Loading modules/textdetector/detector_ctd.py +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ class ComicTextDetector(TextDetectorBase): 'detect_size': { 'type': 'selector', 'options': [896, 1024, 1152, 1280], 'value': 1024 'value': 1280 }, 'det_rearrange_max_batches': { 'type': 'selector', Loading utils/textblock.py +4 −0 Original line number Diff line number Diff line Loading @@ -625,6 +625,8 @@ def try_merge_textline(blk: TextBlock, blk2: TextBlock, fntsize_tol=1.7, distanc distance_y = max(xyxy1[1], xyxy2[1]) - min(xyxy1[3], xyxy2[3]) w1 = xyxy1[2] - xyxy1[0] w2 = xyxy2[2] - xyxy2[0] h1 = xyxy1[3] - xyxy1[1] h2 = xyxy2[3] - xyxy2[1] l1, l2 = Polygon(blk.lines[-1]), Polygon(blk2.lines[0]) if not l1.intersects(l2): Loading @@ -633,6 +635,8 @@ def try_merge_textline(blk: TextBlock, blk2: TextBlock, fntsize_tol=1.7, distanc return False if distance_x > fntsz_avg * 0.8: return False if abs(distance_y) / min(h1, h2) < 0.4: return False else: if distance_x > 0: return False Loading utils/textlines_merge.py +4 −3 Original line number Diff line number Diff line Loading @@ -302,15 +302,16 @@ def sort_pnts(pts: np.ndarray): assert isinstance(pts, np.ndarray) and pts.shape == (4, 2) pairwise_vec = (pts[:, None] - pts[None]).reshape((16, -1)) pairwise_vec_norm = np.linalg.norm(pairwise_vec, axis=1) long_side_ids = np.argsort(pairwise_vec_norm)[[8, 10]] pairwise_vec_norm_sorted = pairwise_vec_norm[long_side_ids] vec_norm_sort_ids = np.argsort(pairwise_vec_norm) long_side_ids = vec_norm_sort_ids[[8, 10]] pairwise_vec_norm_sorted = pairwise_vec_norm[vec_norm_sort_ids] long_side_vecs = pairwise_vec[long_side_ids] inner_prod = (long_side_vecs[0] * long_side_vecs[1]).sum() if inner_prod < 0: long_side_vecs[0] = -long_side_vecs[0] struc_vec = np.abs(long_side_vecs.mean(axis=0)) is_vertical = struc_vec[0] * 1.2 <= struc_vec[1] if len(set(pairwise_vec_norm_sorted[4: 12])) == 0: # is square if len(set(pairwise_vec_norm_sorted[4: 12])) == 1: # is square is_vertical = False if is_vertical: Loading Loading
modules/textdetector/detector_ctd.py +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ class ComicTextDetector(TextDetectorBase): 'detect_size': { 'type': 'selector', 'options': [896, 1024, 1152, 1280], 'value': 1024 'value': 1280 }, 'det_rearrange_max_batches': { 'type': 'selector', Loading
utils/textblock.py +4 −0 Original line number Diff line number Diff line Loading @@ -625,6 +625,8 @@ def try_merge_textline(blk: TextBlock, blk2: TextBlock, fntsize_tol=1.7, distanc distance_y = max(xyxy1[1], xyxy2[1]) - min(xyxy1[3], xyxy2[3]) w1 = xyxy1[2] - xyxy1[0] w2 = xyxy2[2] - xyxy2[0] h1 = xyxy1[3] - xyxy1[1] h2 = xyxy2[3] - xyxy2[1] l1, l2 = Polygon(blk.lines[-1]), Polygon(blk2.lines[0]) if not l1.intersects(l2): Loading @@ -633,6 +635,8 @@ def try_merge_textline(blk: TextBlock, blk2: TextBlock, fntsize_tol=1.7, distanc return False if distance_x > fntsz_avg * 0.8: return False if abs(distance_y) / min(h1, h2) < 0.4: return False else: if distance_x > 0: return False Loading
utils/textlines_merge.py +4 −3 Original line number Diff line number Diff line Loading @@ -302,15 +302,16 @@ def sort_pnts(pts: np.ndarray): assert isinstance(pts, np.ndarray) and pts.shape == (4, 2) pairwise_vec = (pts[:, None] - pts[None]).reshape((16, -1)) pairwise_vec_norm = np.linalg.norm(pairwise_vec, axis=1) long_side_ids = np.argsort(pairwise_vec_norm)[[8, 10]] pairwise_vec_norm_sorted = pairwise_vec_norm[long_side_ids] vec_norm_sort_ids = np.argsort(pairwise_vec_norm) long_side_ids = vec_norm_sort_ids[[8, 10]] pairwise_vec_norm_sorted = pairwise_vec_norm[vec_norm_sort_ids] long_side_vecs = pairwise_vec[long_side_ids] inner_prod = (long_side_vecs[0] * long_side_vecs[1]).sum() if inner_prod < 0: long_side_vecs[0] = -long_side_vecs[0] struc_vec = np.abs(long_side_vecs.mean(axis=0)) is_vertical = struc_vec[0] * 1.2 <= struc_vec[1] if len(set(pairwise_vec_norm_sorted[4: 12])) == 0: # is square if len(set(pairwise_vec_norm_sorted[4: 12])) == 1: # is square is_vertical = False if is_vertical: Loading