segmentation.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:deep_ocr 作者: JinpengLI 项目源码 文件源码
def check_if_good_boundary(self, boundary, norm_height, norm_width, color_img):
        preprocess_bg_mask = PreprocessBackgroundMask(boundary)
        char_w = norm_width / 20
        remove_noise = PreprocessRemoveNonCharNoise(char_w)

        id_card_img_mask = preprocess_bg_mask.do(color_img)
        id_card_img_mask[0:int(norm_height*0.05),:] = 0
        id_card_img_mask[int(norm_height*0.95): ,:] = 0
        id_card_img_mask[:, 0:int(norm_width*0.05)] = 0
        id_card_img_mask[:, int(norm_width*0.95):] = 0

        remove_noise.do(id_card_img_mask)

#        se1 = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5))
#        se2 = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2))
#        mask = cv2.morphologyEx(id_card_img_mask, cv2.MORPH_CLOSE, se1)
#        id_card_img_mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, se2)
#  
        ## remove right head profile
        left_half_id_card_img_mask = np.copy(id_card_img_mask)
        left_half_id_card_img_mask[:, norm_width/2:] = 0

        ## Try to find text lines and chars
        horizontal_sum = np.sum(left_half_id_card_img_mask, axis=1)
        line_ranges = extract_peek_ranges_from_array(horizontal_sum)

        return len(line_ranges) >= 5 and len(line_ranges) <= 7
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号