|
@@ -4,7 +4,8 @@ from ..core.model_loader import get_predictor
|
|
|
from app.utils.CardDefectAggregator import CardDefectAggregator
|
|
from app.utils.CardDefectAggregator import CardDefectAggregator
|
|
|
from app.utils.arean_anylize_draw import DefectProcessor, DrawingParams
|
|
from app.utils.arean_anylize_draw import DefectProcessor, DrawingParams
|
|
|
from app.utils.AnalyzeCenter import analyze_centering_rotated
|
|
from app.utils.AnalyzeCenter import analyze_centering_rotated
|
|
|
-from app.utils.json_data_formate import formate_center_data
|
|
|
|
|
|
|
+from app.utils.ClassifyEdgeCorner import ClassifyEdgeCorner
|
|
|
|
|
+from app.utils.json_data_formate import formate_center_data, formate_face_data
|
|
|
from app.core.config import settings
|
|
from app.core.config import settings
|
|
|
from app.core.logger import logger
|
|
from app.core.logger import logger
|
|
|
import json
|
|
import json
|
|
@@ -59,22 +60,24 @@ 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"合并结束")
|
|
|
|
|
|
|
|
- processor = DefectProcessor(pixel_resolution=settings.pixel_resolution)
|
|
|
|
|
- area_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-area_result.json'
|
|
|
|
|
|
|
+ processor = DefectProcessor(pixel_resolution=settings.PIXEL_RESOLUTION)
|
|
|
|
|
+ area_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-face_result.json'
|
|
|
if is_draw_image:
|
|
if is_draw_image:
|
|
|
drawing_params_with_rect = DrawingParams(draw_min_rect=True)
|
|
drawing_params_with_rect = DrawingParams(draw_min_rect=True)
|
|
|
drawn_image, area_json = processor.analyze_and_draw(img_bgr, json_data,
|
|
drawn_image, area_json = processor.analyze_and_draw(img_bgr, json_data,
|
|
|
drawing_params_with_rect)
|
|
drawing_params_with_rect)
|
|
|
- temp_img_path = settings.TEMP_WORK_DIR / f'{inference_type}-area_result.jpg'
|
|
|
|
|
|
|
+ temp_img_path = settings.TEMP_WORK_DIR / f'{inference_type}-face_result.jpg'
|
|
|
cv2.imwrite(temp_img_path, drawn_image)
|
|
cv2.imwrite(temp_img_path, drawn_image)
|
|
|
else:
|
|
else:
|
|
|
area_json = processor.analyze_from_json(json_data)
|
|
area_json = processor.analyze_from_json(json_data)
|
|
|
|
|
|
|
|
|
|
+ face_json_result = formate_face_data(area_json)
|
|
|
|
|
+
|
|
|
with open(area_json_path, 'w', encoding='utf-8') as f:
|
|
with open(area_json_path, 'w', encoding='utf-8') as f:
|
|
|
- json.dump(area_json, f, ensure_ascii=False, indent=4)
|
|
|
|
|
- logger.info("面积计算结束")
|
|
|
|
|
|
|
+ json.dump(face_json_result, f, ensure_ascii=False, indent=2)
|
|
|
|
|
+ logger.info("面的面积计算结束")
|
|
|
|
|
|
|
|
- return area_json
|
|
|
|
|
|
|
+ return face_json_result
|
|
|
|
|
|
|
|
# 边角
|
|
# 边角
|
|
|
elif (inference_type == "pokemon_front_corner_no_reflect_defect"
|
|
elif (inference_type == "pokemon_front_corner_no_reflect_defect"
|
|
@@ -98,22 +101,29 @@ 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"合并结束")
|
|
|
|
|
|
|
|
- processor = DefectProcessor(pixel_resolution=settings.pixel_resolution)
|
|
|
|
|
- area_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-area_result.json'
|
|
|
|
|
|
|
+ processor = DefectProcessor(pixel_resolution=settings.PIXEL_RESOLUTION)
|
|
|
|
|
+ area_json_path = settings.TEMP_WORK_DIR / f'{inference_type}-corner_result.json'
|
|
|
if is_draw_image:
|
|
if is_draw_image:
|
|
|
drawing_params_with_rect = DrawingParams(draw_min_rect=True)
|
|
drawing_params_with_rect = DrawingParams(draw_min_rect=True)
|
|
|
drawn_image, area_json = processor.analyze_and_draw(img_bgr, json_data,
|
|
drawn_image, area_json = processor.analyze_and_draw(img_bgr, json_data,
|
|
|
drawing_params_with_rect)
|
|
drawing_params_with_rect)
|
|
|
- temp_img_path = settings.TEMP_WORK_DIR / f'{inference_type}-area_result.jpg'
|
|
|
|
|
|
|
+ temp_img_path = settings.TEMP_WORK_DIR / f'{inference_type}-corner_result.jpg'
|
|
|
cv2.imwrite(temp_img_path, drawn_image)
|
|
cv2.imwrite(temp_img_path, drawn_image)
|
|
|
else:
|
|
else:
|
|
|
area_json = processor.analyze_from_json(json_data)
|
|
area_json = processor.analyze_from_json(json_data)
|
|
|
|
|
|
|
|
|
|
+ # 推理外框
|
|
|
|
|
+ predictor_outer = get_predictor("pokemon_outer_box")
|
|
|
|
|
+ outer_result = predictor_outer.predict_from_image(img_bgr)
|
|
|
|
|
+
|
|
|
|
|
+ classifier = ClassifyEdgeCorner(settings.PIXEL_RESOLUTION, settings.CORNER_SIZE_MM)
|
|
|
|
|
+ edge_corner_data = classifier.classify_defects_location(area_json, outer_result)
|
|
|
|
|
+
|
|
|
with open(area_json_path, 'w', encoding='utf-8') as f:
|
|
with open(area_json_path, 'w', encoding='utf-8') as f:
|
|
|
- json.dump(area_json, f, ensure_ascii=False, indent=4)
|
|
|
|
|
- logger.info("面积计算结束")
|
|
|
|
|
|
|
+ json.dump(edge_corner_data, f, ensure_ascii=False, indent=2)
|
|
|
|
|
+ logger.info("边角面积计算结束")
|
|
|
|
|
|
|
|
- return area_json
|
|
|
|
|
|
|
+ return edge_corner_data
|
|
|
|
|
|
|
|
elif inference_type == "pokemon_card_center":
|
|
elif inference_type == "pokemon_card_center":
|
|
|
predictor_inner = get_predictor(settings.DEFECT_TYPE[inference_type]['inner_box'])
|
|
predictor_inner = get_predictor(settings.DEFECT_TYPE[inference_type]['inner_box'])
|