|
@@ -7,6 +7,7 @@ from app.utils.defect_inference.AnalyzeCenter import analyze_centering_rotated,
|
|
|
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.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
|
|
|
import json
|
|
import json
|
|
@@ -27,6 +28,7 @@ class DefectInferenceService:
|
|
|
Returns:
|
|
Returns:
|
|
|
一个包含推理结果的字典。
|
|
一个包含推理结果的字典。
|
|
|
"""
|
|
"""
|
|
|
|
|
+ simplifyPoints = SimplifyPoints()
|
|
|
|
|
|
|
|
# 面
|
|
# 面
|
|
|
if (inference_type == "pokemon_front_face_no_reflect_defect"
|
|
if (inference_type == "pokemon_front_face_no_reflect_defect"
|
|
@@ -49,10 +51,20 @@ class DefectInferenceService:
|
|
|
image=img_bgr,
|
|
image=img_bgr,
|
|
|
mode='face'
|
|
mode='face'
|
|
|
)
|
|
)
|
|
|
- # merge_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-merge.json'
|
|
|
|
|
- # with open(merge_json_path, 'w', encoding='utf-8') as f:
|
|
|
|
|
- # json.dump(json_data, f, ensure_ascii=False, indent=4)
|
|
|
|
|
- # logger.info(f"合并结束")
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # 简化点数
|
|
|
|
|
+ for shapes in json_data["shapes"]:
|
|
|
|
|
+ points = shapes["points"]
|
|
|
|
|
+ num1 = len(points)
|
|
|
|
|
+ simplify_points = simplifyPoints.simplify_points(points)
|
|
|
|
|
+ shapes["points"] = simplify_points
|
|
|
|
|
+ new_num1 = len(simplify_points)
|
|
|
|
|
+ logger.info(f"num: {num1}, new_num1: {new_num1}")
|
|
|
|
|
+
|
|
|
|
|
+ merge_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-merge.json'
|
|
|
|
|
+ with open(merge_json_path, 'w', encoding='utf-8') as f:
|
|
|
|
|
+ json.dump(json_data, f, ensure_ascii=False, indent=4)
|
|
|
|
|
+ logger.info(f"合并结束")
|
|
|
|
|
|
|
|
processor = DefectProcessor(pixel_resolution=settings.PIXEL_RESOLUTION)
|
|
processor = DefectProcessor(pixel_resolution=settings.PIXEL_RESOLUTION)
|
|
|
area_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-face_result.json'
|
|
area_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-face_result.json'
|
|
@@ -91,6 +103,14 @@ class DefectInferenceService:
|
|
|
mode='edge'
|
|
mode='edge'
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ for shapes in json_data["shapes"]:
|
|
|
|
|
+ points = shapes["points"]
|
|
|
|
|
+ num1 = len(points)
|
|
|
|
|
+ simplify_points = simplifyPoints.simplify_points(points)
|
|
|
|
|
+ shapes["points"] = simplify_points
|
|
|
|
|
+ new_num1 = len(simplify_points)
|
|
|
|
|
+ logger.info(f"num: {num1}, new_num1: {new_num1}")
|
|
|
|
|
+
|
|
|
# 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)
|