| 12345678910111213141516171819202122232425262728293031323334353637 |
- import cv2
- import numpy as np
- from ..core.model_loader import get_predictor
- from app.utils.defect_inference.img_rectify_and_center import (
- FryCardProcessParams, FryCardProcessor, CenterMode, FillMode)
- from app.core.config import settings
- from app.core.logger import get_logger
- import json
- logger = get_logger(__name__)
- class CardRectifyAndCenter:
- def __init__(self):
- self.inference_type = "outer_box"
- self.outer_box_model = get_predictor(self.inference_type)
- def rectify_and_center(self, img_bgr: np.ndarray) -> np.ndarray:
- # 1. 设置处理参数
- params = FryCardProcessParams(
- debug_level="detail",
- label_name="outer_box",
- center_mode=CenterMode.BOUNDING_RECT,
- fill_mode=FillMode.BLACK
- )
- # 2. 初始化处理器
- processor = FryCardProcessor()
- seg_json = self.outer_box_model.predict_from_image(img_bgr)
- # 4. 执行处理
- final_image = processor.process_image_with_json(img_bgr, seg_json, params)
- temp_img_path = settings.TEMP_WORK_DIR / "rectify_center_img.jpg"
- cv2.imwrite(temp_img_path, final_image)
- return final_image
|