mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-10-27 07:44:12 +01:00
contours_in_same_horizon: simplify
- array instead of list operations - return array of index pairs instead of list objects
This commit is contained in:
parent
acee4c1bfe
commit
5d15941b35
2 changed files with 44 additions and 54 deletions
|
|
@ -1315,18 +1315,16 @@ def combine_hor_lines_and_delete_cross_points_and_get_lines_features_back_new(
|
||||||
float(num_col_classifier))
|
float(num_col_classifier))
|
||||||
if len_lines_bigger_than_x_width_smaller_than_acolumn_width_per_column < 10:
|
if len_lines_bigger_than_x_width_smaller_than_acolumn_width_per_column < 10:
|
||||||
args_hor=np.arange(len(slope_lines_hor))
|
args_hor=np.arange(len(slope_lines_hor))
|
||||||
all_args_uniq=contours_in_same_horizon(cy_main_hor)
|
sep_pairs=contours_in_same_horizon(cy_main_hor)
|
||||||
#print(all_args_uniq,'all_args_uniq')
|
if len(sep_pairs):
|
||||||
if len(all_args_uniq)>0:
|
|
||||||
if type(all_args_uniq[0]) is list:
|
|
||||||
special_separators=[]
|
special_separators=[]
|
||||||
contours_new=[]
|
contours_new=[]
|
||||||
for dd in range(len(all_args_uniq)):
|
for pair in sep_pairs:
|
||||||
merged_all=None
|
merged_all=None
|
||||||
some_args=args_hor[all_args_uniq[dd]]
|
some_args=args_hor[pair]
|
||||||
some_cy=cy_main_hor[all_args_uniq[dd]]
|
some_cy=cy_main_hor[pair]
|
||||||
some_x_min=x_min_main_hor[all_args_uniq[dd]]
|
some_x_min=x_min_main_hor[pair]
|
||||||
some_x_max=x_max_main_hor[all_args_uniq[dd]]
|
some_x_max=x_max_main_hor[pair]
|
||||||
|
|
||||||
#img_in=np.zeros(separators_closeup_n[:,:,2].shape)
|
#img_in=np.zeros(separators_closeup_n[:,:,2].shape)
|
||||||
#print(img_p_in_ver.shape[1],some_x_max-some_x_min,'xdiff')
|
#print(img_p_in_ver.shape[1],some_x_max-some_x_min,'xdiff')
|
||||||
|
|
@ -1356,9 +1354,6 @@ def combine_hor_lines_and_delete_cross_points_and_get_lines_features_back_new(
|
||||||
else:
|
else:
|
||||||
img_p_in=img_in_hor
|
img_p_in=img_in_hor
|
||||||
special_separators=[]
|
special_separators=[]
|
||||||
else:
|
|
||||||
img_p_in=img_in_hor
|
|
||||||
special_separators=[]
|
|
||||||
|
|
||||||
img_p_in_ver[img_p_in_ver == 255] = 1
|
img_p_in_ver[img_p_in_ver == 255] = 1
|
||||||
sep_ver_hor = img_p_in + img_p_in_ver
|
sep_ver_hor = img_p_in + img_p_in_ver
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,16 @@ from shapely.ops import unary_union, nearest_points
|
||||||
from .rotate import rotate_image, rotation_image_new
|
from .rotate import rotate_image, rotation_image_new
|
||||||
|
|
||||||
def contours_in_same_horizon(cy_main_hor):
|
def contours_in_same_horizon(cy_main_hor):
|
||||||
X1 = np.zeros((len(cy_main_hor), len(cy_main_hor)))
|
"""
|
||||||
X2 = np.zeros((len(cy_main_hor), len(cy_main_hor)))
|
Takes an array of y coords, identifies all pairs among them
|
||||||
|
which are close to each other, and returns all such pairs
|
||||||
X1[0::1, :] = cy_main_hor[:]
|
by index into the array.
|
||||||
X2 = X1.T
|
"""
|
||||||
|
sort = np.argsort(cy_main_hor)
|
||||||
X_dif = np.abs(X2 - X1)
|
same = np.diff(cy_main_hor[sort] <= 20)
|
||||||
args_help = np.array(range(len(cy_main_hor)))
|
# groups = np.split(sort, np.arange(len(cy_main_hor) - 1)[~same] + 1)
|
||||||
all_args = []
|
same = np.flatnonzero(same)
|
||||||
for i in range(len(cy_main_hor)):
|
return np.stack((sort[:-1][same], sort[1:][same])).T
|
||||||
list_h = list(args_help[X_dif[i, :] <= 20])
|
|
||||||
list_h.append(i)
|
|
||||||
if len(list_h) > 1:
|
|
||||||
all_args.append(list(set(list_h)))
|
|
||||||
return np.unique(np.array(all_args, dtype=object))
|
|
||||||
|
|
||||||
def find_contours_mean_y_diff(contours_main):
|
def find_contours_mean_y_diff(contours_main):
|
||||||
M_main = [cv2.moments(contours_main[j]) for j in range(len(contours_main))]
|
M_main = [cv2.moments(contours_main[j]) for j in range(len(contours_main))]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue