|
|
@@ -3,6 +3,8 @@ from mysql.connector.pooling import PooledMySQLConnection
|
|
|
|
|
|
import io
|
|
|
import json
|
|
|
+import cv2
|
|
|
+import numpy as np
|
|
|
from datetime import datetime
|
|
|
from app.core.minio_client import minio_client
|
|
|
from typing import List, Dict, Any, Optional
|
|
|
@@ -12,6 +14,7 @@ from app.core.logger import get_logger
|
|
|
from app.core.config import settings
|
|
|
from app.core.database_loader import get_db_connection
|
|
|
from app.crud import crud_card
|
|
|
+
|
|
|
from app.utils.scheme import ImageType
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
@@ -106,9 +109,14 @@ def _crop_defect_image(original_image_path_str: str, min_rect: List, output_file
|
|
|
# 2. 在内存中用 PIL 切图
|
|
|
with Image.open(io.BytesIO(image_bytes)) as img:
|
|
|
img_w, img_h = img.size
|
|
|
- center_x, center_y = min_rect[0]
|
|
|
- rect_w, rect_h = min_rect[1]
|
|
|
- side_length = max(max(rect_w, rect_h) * 1.5, 100)
|
|
|
+ (center_x, center_y), (rect_w, rect_h), angle = min_rect
|
|
|
+ center_x = int(center_x)
|
|
|
+ center_y = int(center_y)
|
|
|
+ rect_w = int(rect_w)
|
|
|
+ rect_h = int(rect_h)
|
|
|
+
|
|
|
+ resize_scale = 1.5 - abs(abs(angle % 90) - 45) / 90
|
|
|
+ side_length = max(max(rect_w, rect_h) * resize_scale, 100)
|
|
|
half_side = side_length / 2
|
|
|
|
|
|
left, top = max(0, center_x - half_side), max(0, center_y - half_side)
|