def processing(org, binary, clf, main=True): if main: # *** Step 2 *** object detection: get connected areas -> get boundary -> get corners boundary_rec, boundary_non_rec = det.boundary_detection(binary, write_boundary=True) corners_rec = det.get_corner(boundary_rec) corners_non_rec = det.get_corner(boundary_non_rec) # *** Step 3 *** data processing: identify blocks and compos from rectangles -> identify irregular compos corners_block, corners_img, corners_compo = det.block_or_compo(org, binary, corners_rec) det.compo_irregular(org, corners_non_rec, corners_img, corners_compo) # *** Step 4 *** classification: clip and classify the components candidates -> ignore noises -> refine img compos = seg.clipping(org, corners_compo) compos_class = clf.predict(compos) corners_compo, compos_class = det.strip_img(corners_compo, compos_class, corners_img) # *** Step 5 *** result refinement if is_shrink_img: corners_img = det.img_shrink(org, binary, corners_img) # *** Step 6 *** recursive inspection: search components nested in components corners_block, corners_img, corners_compo, compos_class = det.compo_in_img(processing, org, binary, clf, corners_img, corners_block, corners_compo, compos_class) # *** Step 7 *** ocr check and text detection from cleaned image if is_ocr: corners_block, _ = det.rm_text(org, corners_block, ['block' for i in range(len(corners_block))]) corners_img, _ = det.rm_text(org, corners_img, ['img' for i in range(len(corners_img))]) corners_compo, compos_class = det.rm_text(org, corners_compo, compos_class) # *** Step 8 *** merge overlapped components # corners_img = det.rm_img_in_compo(corners_img, corners_compo) corners_img, _ = det.merge_corner(org, corners_img, ['img' for i in range(len(corners_img))], is_merge_nested_same=True) corners_compo, compos_class = det.merge_corner(org, corners_compo, compos_class, is_merge_nested_same=True) return corners_block, corners_img, corners_compo, compos_class # *** used for img inspection *** # only consider rectangular components else: boundary_rec, boundary_non_rec = det.boundary_detection(binary) corners_rec = det.get_corner(boundary_rec) corners_block, corners_img, corners_compo = det.block_or_compo(org, binary, corners_rec) compos = seg.clipping(org, corners_compo) compos_class = clf.predict(compos) corners_compo, compos_class = det.strip_img(corners_compo, compos_class, corners_img) return corners_block, corners_compo, compos_class
def processing(org, binary, main=True): if main: # *** Step 2 *** object detection: get connected areas -> get boundary -> get corners boundary_rec, boundary_non_rec = det.boundary_detection(binary, show=False) corners_rec = det.get_corner(boundary_rec) corners_non_rec = det.get_corner(boundary_non_rec) # *** Step 3 *** data processing: identify blocks and compos from rectangles -> identify irregular compos corners_block, corners_img, corners_compo = det.block_or_compo( org, binary, corners_rec) det.compo_irregular(org, corners_non_rec, corners_img, corners_compo) corners_img, _ = det.rm_text(org, corners_img, ['img' for i in range(len(corners_img))]) # *** Step 4 *** classification: clip and classify the components candidates -> ignore noises -> refine img compos = seg.clipping(org, corners_compo) compos_class = CNN.predict(compos) # corners_compo, compos_class = det.compo_filter(org, corners_compo, compos_class, is_icon) corners_compo, compos_class = det.strip_img(corners_compo, compos_class, corners_img) # *** Step 5 *** result refinement if is_merge: corners_img, _ = det.merge_corner( corners_img, ['img' for i in range(len(corners_img))]) corners_block, _ = det.rm_text( org, corners_block, ['block' for i in range(len(corners_block))]) corners_img, _ = det.rm_text(org, corners_img, ['img' for i in range(len(corners_img))]) corners_compo, compos_class = det.rm_text(org, corners_compo, compos_class) if is_shrink_img: corners_img = det.img_shrink(org, binary, corners_img) # *** Step 6 *** text detection from cleaned image img_clean = draw.draw_bounding_box(org, corners_img, color=(255, 255, 255), line=-1) corners_word = ocr.text_detection(org, img_clean) corners_text = ocr.text_merge_word_into_line(org, corners_word) # *** Step 7 *** img inspection: search components in img element if is_img_inspect: corners_block, corners_img, corners_compo, compos_class = det.compo_in_img( processing, org, binary, corners_img, corners_block, corners_compo, compos_class) return corners_block, corners_img, corners_compo, compos_class, corners_text # *** used for img inspection *** # only consider rectangular components else: boundary_rec, boundary_non_rec = det.boundary_detection(binary) corners_rec = det.get_corner(boundary_rec) corners_block, corners_img, corners_compo = det.block_or_compo( org, binary, corners_rec) compos = seg.clipping(org, corners_compo) compos_class = CNN.predict(compos) corners_compo, compos_class = det.compo_filter(org, corners_compo, compos_class, is_icon) corners_compo, compos_class = det.strip_img(corners_compo, compos_class, corners_img) corners_block, _ = det.rm_text( org, corners_block, ['block' for i in range(len(corners_block))]) corners_compo, compos_class = det.rm_text(org, corners_compo, compos_class) return corners_block, corners_compo, compos_class
binary = pre.preprocess(gray, 1) # *** Step 2 *** object detection: get connected areas -> get boundary -> get corners boundary_all, boundary_rec, boundary_nonrec = det.boundary_detection(binary) # get corner of boundaries corners_rec = det.get_corner(boundary_rec) corners_nonrec = det.get_corner(boundary_nonrec) # *** Step 3 *** process data: identify blocks and imgs from rectangles -> identify compos -> identify irregular imgs # identify rectangular block and rectangular img from rectangular shapes corners_block, corners_img = det.img_or_block(org, binary, corners_rec) # identify potential buttons and input bars corners_block, corners_compo = det.uicomponent_or_block(org, corners_block) # shrink images with extra borders if is_shrink_img: corners_img = det.img_shrink(org, binary, corners_img) # identify irregular-shape img from irregular shapes corners_img += det.img_irregular(org, corners_nonrec) # ignore too large and highly likely text areas corners_img = det.img_refine(org, corners_img) # merge overlapped corners, and remove nested corners if is_merge_img: corners_img = det.merge_corners(corners_img) # detect components on img corners_compo += det.uicomponent_in_img(org, binary, corners_img) # remove text misrecognition corners_block = det.rm_text(org, corners_block) corners_img = det.rm_text(org, corners_img) corners_compo = det.rm_text(org, corners_compo) # *** Step 5 *** text detection from cleaned image
corners_rec = det.get_corner(boundary_rec) corners_nonrec = det.get_corner(boundary_nonrec) # *** Step 4 *** process data: identify blocks and imgs from rectangles -> identify compos -> identify irregular imgs # identify rectangular block and rectangular img from rectangular shapes corners_block, corners_img = det.img_or_block( org, binary, corners_rec, C.THRESHOLD_BLOCK_MAX_BORDER_THICKNESS, C.THRESHOLD_BLOCK_MAX_CROSS_POINT) # block check # identify potential buttons and input bars corners_block, corners_compo = det.uicomponent_or_block( org, corners_block, C.THRESHOLD_UICOMPO_MAX_HEIGHT, C.THRESHOLD_UICOMPO_MIN_EDGE_RATION, C.THRESHOLD_BLOCK_MIN_EDGE_LENGTH) # shrink images with extra borders if is_shrink_img: corners_img = det.img_shrink(org, binary, corners_img, C.THRESHOLD_LINE_MIN_LENGTH_H, C.THRESHOLD_LINE_MIN_LENGTH_V, C.THRESHOLD_LINE_THICKNESS) # identify irregular-shape img from irregular shapes corners_img += det.img_irregular(org, corners_nonrec, C.THRESHOLD_IMG_MUST_HEIGHT, C.THRESHOLD_IMG_MUST_WIDTH) # img assertion # *** Step 5 *** refine results: refine img according to size -> OCR text area filter # ignore too large and highly likely text areas corners_img = det.img_refine( org, corners_img, C.THRESHOLD_IMG_MAX_HEIGHT_RATIO, # ignore too large imgs C.THRESHOLD_TEXT_EDGE_RATIO, C.THRESHOLD_TEXT_HEIGHT) # ignore text areas # merge overlapped corners, and remove nested corners