fix: previous refactor issues

This commit is contained in:
283375 2023-08-13 16:01:31 +08:00
parent c640754d87
commit ea2b663e83
2 changed files with 2 additions and 2 deletions

View File

@ -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)))

View File

@ -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)