diff --git a/src/arcaea_offline_ocr/mask.py b/src/arcaea_offline_ocr/mask.py index 08de893..6466d2d 100644 --- a/src/arcaea_offline_ocr/mask.py +++ b/src/arcaea_offline_ocr/mask.py @@ -49,7 +49,7 @@ BYD_MAX_HSV = np.array([179, 210, 198], np.uint8) def mask_gray(__img_bgr: Mat): # bgr_value_equal_mask = all(__img_bgr[:, 1:] == __img_bgr[:, :-1], axis=1) - bgr_value_equal_mask = max(__img_bgr, axis=2) - min(__img_bgr, axis=2) <= 5 + bgr_value_equal_mask = np.max(__img_bgr, axis=2) - np.min(__img_bgr, axis=2) <= 5 img_bgr = __img_bgr.copy() img_bgr[~bgr_value_equal_mask] = np.array([0, 0, 0], __img_bgr.dtype) img_bgr = cv2.erode(img_bgr, cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))) diff --git a/src/arcaea_offline_ocr/ocr.py b/src/arcaea_offline_ocr/ocr.py index 54d3ede..cb03c99 100644 --- a/src/arcaea_offline_ocr/ocr.py +++ b/src/arcaea_offline_ocr/ocr.py @@ -44,7 +44,7 @@ def preprocess_hog(digit_rois): def ocr_digits_by_contour_samples(__roi_gray: Mat, size: Tuple[int, int]): roi = __roi_gray.copy() - contours = cv2.findContours(roi, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) + contours, _ = cv2.findContours(roi, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) rects = sorted([cv2.boundingRect(c) for c in contours], key=lambda r: r[0]) digit_rois = [cv2.resize(crop_xywh(roi, rect), size) for rect in rects] return preprocess_hog(digit_rois)