def roi_(origin): img = common.binary_(origin, thresh=config.binary_threshold) img = common.erode_(img) img = common.morph_(img) img = common.canny_(img) contours = common.findContours_(img, origin) # FFT 矫正 roi = common.minAreaRect_(origin, contours) return roi
def chosen(origin): # randon hough img = common.binary_(origin, thresh=config.binary_threshold) img = common.erode_(img) img = common.morph_(img) img = common.canny_(img) origin = common.hough_lines_p_(img, origin) contours = common.findContours_(img, origin) roi = common.boundingRect_(origin, contours) return roi
def main_(file_path="data/img/11.jpg"): img = read_(file_path, shrink=1) img = cut_(img) cv2.imwrite("data/result/1_cut.jpg", img) img = roi_(img) cv2.imwrite("data/result/2_roi.jpg", img) if img.shape[0] * img.shape[1] > 400 * 400: img = chosen(img) cv2.imwrite("data/result/3_chosen.jpg", img) img = common.canny_(img) temp = hand_write.get_img("872") cv2.imshow("temp", temp) temp = common.canny_(temp) cv2.imwrite("data/result/4_temp.jpg", temp) img = common.template(img, temp) cv2.imwrite("data/result/5_match.jpg", img) # 图像分段(分水岭算法) cv2.waitKey(0) cv2.destroyAllWindows()
def main_(file_path="../data/img/1.jpg"): img = read_(file_path, shrink=1) img = cut_(img) img = roi_(img) if img.shape[0] * img.shape[1] > 400 * 400: img = chosen(img) img = common.canny_(img) # img = common.Remove_holes(img) cv2.imshow("chosen", img) genFontImage(ImageFont.truetype('../data/font/msyhbd.ttf', 22), '2', (14, 20)) temp = cv2.imread("temp.jpg") # temp = common.Remove_holes(temp) cv2.imshow("temp", temp) img = common.template(img, temp) cv2.imshow("match", img) cv2.waitKey(0) cv2.destroyAllWindows()