def pre_processing(input_path): # *** Step 1 *** pre-processing: gray, gradient, binary org, gray = pre.read_img(input_path, (0, 3000)) # cut out partial img binary = pre.preprocess(gray) return org, binary
if int(index) > end_index: break start = time.clock() # set paths print(input_path) print(time.ctime()) out_img_draw = pyjoin(C.ROOT_IMG_DRAWN, index + '.png') out_img_clean = pyjoin(C.ROOT_IMG_CLEAN, index + '.png') out_img_gradient = pyjoin(C.ROOT_IMG_GRADIENT, index + '.png') out_img_segment = pyjoin(C.ROOT_IMG_SEGMENT, index) out_label = pyjoin(C.ROOT_LABEL, index) # *** Step 1 *** pre-processing: gray, gradient, binary org, gray = pre.read_img(input_path, (0, 2600)) # cut out partial img if org is None or gray is None: continue binary = pre.preprocess(gray, 1) # *** Step 2 *** processing: get connected areas -> get boundary -> rectangle check boundary_rec, boundary_all = det.boundary_detection( binary, C.THRESHOLD_MIN_OBJ_AREA, C.THRESHOLD_MIN_REC_PARAMETER, C.THRESHOLD_MIN_REC_EVENNESS, C.THRESHOLD_MAX_LINE_THICKNESS, C.THRESHOLD_MIN_LIN_LENGTH, C.THRESHOLD_MAX_IMG_DENT_RATIO) # get corner of boundaries -> img or block check corners_rec = det.get_corner(boundary_rec) corners_block, corners_img = det.block_or_img( binary, corners_rec, C.THRESHOLD_MAX_BLOCK_BORDER_THICKNESS, C.THRESHOLD_MAX_BLOCK_CROSS_POINT) # refine img component corners_img = det.img_refine2(corners_img, C.THRESHOLD_MAX_IMG_EDGE_RATIO,
from code_generation import DIV import line import line_to_block as l2b import code_generation as code from config import CONFIG as cfg import ip_preprocessing as pre C = cfg() org, gray = pre.read_img('input/4.png', (0, 3000)) # cut out partial img lines_v = line.read_lines('output/lines_v.csv') lines_h = line.read_lines('output/lines_h.csv') blocks_h = l2b.divide_blocks_by_lines(lines_h, org.shape[0], C.BLOCK_MIN_HEIGHT) hierarchies_h = l2b.hierarchy_blocks(blocks_h) print(hierarchies_h) # html = code.gen_html2(blocks_h) # open('output/y.html', 'w').write(html) # code.gen_css(blocks_h)
y + t >= column - 1 or (np.sum(binary[head:end, y + t]) / 255) / (end - head) < max_cross_point): clear_right = True if clear_left and clear_right: lines_v.append(((y, head), (y, end))) break if x < row - 1: x += 1 if y < column - 1: y += 1 return lines_h, lines_v org, gray = pre.read_img('input/6.png', (2000, 2600)) # cut out partial img binary = pre.preprocess(gray, 1) lines_h, lines_v = search_line(binary) draw_line(org, lines_h, (0, 255, 0)) draw_line(org, lines_v, (0, 0, 255)) broad = np.zeros(org.shape, dtype=np.uint8) draw_line(broad, lines_h, (0, 255, 0)) draw_line(broad, lines_v, (0, 0, 255)) new_bin = rm_line(binary, [lines_h, lines_v]) cv2.imwrite('output/labeled.png', org) cv2.imwrite('output/lines.png', broad) cv2.imwrite('output/grad.png', binary) cv2.imwrite('output/rm_line.png', new_bin)