|
@@ -4,10 +4,11 @@ from ..core.model_loader import get_predictor
|
|
|
from app.utils.defect_inference.CardDefectAggregator import CardDefectAggregator
|
|
from app.utils.defect_inference.CardDefectAggregator import CardDefectAggregator
|
|
|
from app.utils.defect_inference.arean_anylize_draw import DefectProcessor, DrawingParams
|
|
from app.utils.defect_inference.arean_anylize_draw import DefectProcessor, DrawingParams
|
|
|
from app.utils.defect_inference.AnalyzeCenter import (
|
|
from app.utils.defect_inference.AnalyzeCenter import (
|
|
|
- analyze_centering_rotated,analyze_centering_rect ,formate_center_data)
|
|
|
|
|
|
|
+ analyze_centering_rotated, analyze_centering_rect, formate_center_data)
|
|
|
from app.utils.defect_inference.DrawCenterInfo import draw_boxes_and_center_info
|
|
from app.utils.defect_inference.DrawCenterInfo import draw_boxes_and_center_info
|
|
|
from app.utils.defect_inference.ClassifyEdgeCorner import ClassifyEdgeCorner
|
|
from app.utils.defect_inference.ClassifyEdgeCorner import ClassifyEdgeCorner
|
|
|
from app.utils.json_data_formate import formate_face_data, formate_add_edit_type
|
|
from app.utils.json_data_formate import formate_face_data, formate_add_edit_type
|
|
|
|
|
+from app.utils.defect_inference.FilterOutsideDefects import FilterOutsideDefects
|
|
|
from app.utils.simplify_points import SimplifyPoints
|
|
from app.utils.simplify_points import SimplifyPoints
|
|
|
from app.core.config import settings
|
|
from app.core.config import settings
|
|
|
from app.core.logger import get_logger
|
|
from app.core.logger import get_logger
|
|
@@ -30,6 +31,7 @@ class DefectInferenceService:
|
|
|
一个包含推理结果的字典。
|
|
一个包含推理结果的字典。
|
|
|
"""
|
|
"""
|
|
|
simplifyPoints = SimplifyPoints()
|
|
simplifyPoints = SimplifyPoints()
|
|
|
|
|
+ outside_filter = FilterOutsideDefects(expansion_pixel=30)
|
|
|
|
|
|
|
|
# 面
|
|
# 面
|
|
|
if (inference_type == "pokemon_front_face_no_reflect_defect"
|
|
if (inference_type == "pokemon_front_face_no_reflect_defect"
|
|
@@ -62,6 +64,17 @@ class DefectInferenceService:
|
|
|
new_num1 = len(simplify_points)
|
|
new_num1 = len(simplify_points)
|
|
|
logger.info(f"num: {num1}, new_num1: {new_num1}")
|
|
logger.info(f"num: {num1}, new_num1: {new_num1}")
|
|
|
|
|
|
|
|
|
|
+ logger.info("开始执行外框过滤...")
|
|
|
|
|
+ try:
|
|
|
|
|
+ # 1. 因为面原本没有外框推理,这里需要专门加载并推理一次
|
|
|
|
|
+ predictor_outer = get_predictor("outer_box")
|
|
|
|
|
+ outer_result = predictor_outer.predict_from_image(img_bgr)
|
|
|
|
|
+
|
|
|
|
|
+ # 2. 执行过滤
|
|
|
|
|
+ json_data = outside_filter.execute(json_data, outer_result)
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.error(f"面流程外框过滤失败: {e}")
|
|
|
|
|
+
|
|
|
merge_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-merge.json'
|
|
merge_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-merge.json'
|
|
|
with open(merge_json_path, 'w', encoding='utf-8') as f:
|
|
with open(merge_json_path, 'w', encoding='utf-8') as f:
|
|
|
json.dump(json_data, f, ensure_ascii=False, indent=4)
|
|
json.dump(json_data, f, ensure_ascii=False, indent=4)
|
|
@@ -104,6 +117,7 @@ class DefectInferenceService:
|
|
|
mode='edge'
|
|
mode='edge'
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ # 简化点数
|
|
|
for shapes in json_data["shapes"]:
|
|
for shapes in json_data["shapes"]:
|
|
|
points = shapes["points"]
|
|
points = shapes["points"]
|
|
|
num1 = len(points)
|
|
num1 = len(points)
|
|
@@ -117,6 +131,14 @@ class DefectInferenceService:
|
|
|
# json.dump(json_data, f, ensure_ascii=False, indent=4)
|
|
# json.dump(json_data, f, ensure_ascii=False, indent=4)
|
|
|
# logger.info(f"合并结束")
|
|
# logger.info(f"合并结束")
|
|
|
|
|
|
|
|
|
|
+ logger.info("开始执行外框过滤...")
|
|
|
|
|
+ # 外框推理
|
|
|
|
|
+ predictor_outer = get_predictor("outer_box")
|
|
|
|
|
+ outer_result = predictor_outer.predict_from_image(img_bgr)
|
|
|
|
|
+
|
|
|
|
|
+ # 2. 执行过滤
|
|
|
|
|
+ json_data = outside_filter.execute(json_data, outer_result)
|
|
|
|
|
+
|
|
|
processor = DefectProcessor(pixel_resolution=settings.PIXEL_RESOLUTION)
|
|
processor = DefectProcessor(pixel_resolution=settings.PIXEL_RESOLUTION)
|
|
|
area_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-corner_result.json'
|
|
area_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-corner_result.json'
|
|
|
if is_draw_image:
|
|
if is_draw_image:
|
|
@@ -129,10 +151,6 @@ class DefectInferenceService:
|
|
|
area_json: dict = processor.analyze_from_json(json_data)
|
|
area_json: dict = processor.analyze_from_json(json_data)
|
|
|
logger.info("边角缺陷面积计算结束")
|
|
logger.info("边角缺陷面积计算结束")
|
|
|
|
|
|
|
|
- # 推理外框
|
|
|
|
|
- predictor_outer = get_predictor("outer_box")
|
|
|
|
|
- outer_result = predictor_outer.predict_from_image(img_bgr)
|
|
|
|
|
-
|
|
|
|
|
classifier = ClassifyEdgeCorner(settings.PIXEL_RESOLUTION, settings.CORNER_SIZE_MM)
|
|
classifier = ClassifyEdgeCorner(settings.PIXEL_RESOLUTION, settings.CORNER_SIZE_MM)
|
|
|
edge_corner_data = classifier.classify_defects_location(area_json, outer_result)
|
|
edge_corner_data = classifier.classify_defects_location(area_json, outer_result)
|
|
|
|
|
|