@ -2357,7 +2357,6 @@ class Eynollah:
arg_text_con = [ ]
for ii in range ( len ( cx_text_only ) ) :
for jj in range ( len ( boxes ) ) :
print ( cx_text_only [ ii ] , cy_text_only [ ii ] , ' markaz ' )
if cx_text_only [ ii ] > = boxes [ jj ] [ 0 ] and cx_text_only [ ii ] < boxes [ jj ] [ 1 ] and cy_text_only [ ii ] > = boxes [ jj ] [ 2 ] and cy_text_only [ ii ] < boxes [ jj ] [ 3 ] : # this is valid if the center of region identify in which box it is located
arg_text_con . append ( jj )
break
@ -3624,6 +3623,9 @@ class Eynollah:
textline_contour [ : , 0 ] = textline_contour [ : , 0 ] + box_ind [ 2 ]
textline_contour [ : , 1 ] = textline_contour [ : , 1 ] + box_ind [ 0 ]
return textline_contour
def return_list_of_contours_with_desired_order ( self , ls_cons , sorted_indexes ) :
return [ ls_cons [ sorted_indexes [ index ] ] for index in range ( len ( sorted_indexes ) ) ]
def run ( self ) :
"""
@ -3735,11 +3737,15 @@ class Eynollah:
contours_only_text_parent = [ c for jz , c in enumerate ( contours_only_text_parent ) if areas_cnt_text [ jz ] > MIN_AREA_REGION ]
areas_cnt_text_parent = [ area for area in areas_cnt_text if area > MIN_AREA_REGION ]
index_con_parents = np . argsort ( areas_cnt_text_parent )
try :
contours_only_text_parent = list ( np . array ( contours_only_text_parent , dtype = object ) [ index_con_parents ] )
except :
contours_only_text_parent = list ( np . array ( contours_only_text_parent , dtype = np . int32 ) [ index_con_parents ] )
areas_cnt_text_parent = list ( np . array ( areas_cnt_text_parent ) [ index_con_parents ] )
contours_only_text_parent = self . return_list_of_contours_with_desired_order ( contours_only_text_parent , index_con_parents )
##try:
##contours_only_text_parent = list(np.array(contours_only_text_parent,dtype=object)[index_con_parents])
##except:
##contours_only_text_parent = list(np.array(contours_only_text_parent,dtype=np.int32)[index_con_parents])
##areas_cnt_text_parent = list(np.array(areas_cnt_text_parent)[index_con_parents])
areas_cnt_text_parent = self . return_list_of_contours_with_desired_order ( areas_cnt_text_parent , index_con_parents )
cx_bigest_big , cy_biggest_big , _ , _ , _ , _ , _ = find_new_features_of_contours ( [ contours_biggest ] )
cx_bigest , cy_biggest , _ , _ , _ , _ , _ = find_new_features_of_contours ( contours_only_text_parent )
@ -3753,12 +3759,14 @@ class Eynollah:
if len ( areas_cnt_text_d ) > 0 :
contours_biggest_d = contours_only_text_parent_d [ np . argmax ( areas_cnt_text_d ) ]
index_con_parents_d = np . argsort ( areas_cnt_text_d )
try :
contours_only_text_parent_d = list ( np . array ( contours_only_text_parent_d , dtype = object ) [ index_con_parents_d ] )
except :
contours_only_text_parent_d = list ( np . array ( contours_only_text_parent_d , dtype = np . int32 ) [ index_con_parents_d ] )
contours_only_text_parent_d = self . return_list_of_contours_with_desired_order ( contours_only_text_parent_d , index_con_parents_d )
#try:
#contours_only_text_parent_d = list(np.array(contours_only_text_parent_d,dtype=object)[index_con_parents_d])
#except:
#contours_only_text_parent_d = list(np.array(contours_only_text_parent_d,dtype=np.int32)[index_con_parents_d])
areas_cnt_text_d = list ( np . array ( areas_cnt_text_d ) [ index_con_parents_d ] )
#areas_cnt_text_d = list(np.array(areas_cnt_text_d)[index_con_parents_d])
areas_cnt_text_d = self . return_list_of_contours_with_desired_order ( areas_cnt_text_d , index_con_parents_d )
cx_bigest_d_big , cy_biggest_d_big , _ , _ , _ , _ , _ = find_new_features_of_contours ( [ contours_biggest_d ] )
cx_bigest_d , cy_biggest_d , _ , _ , _ , _ , _ = find_new_features_of_contours ( contours_only_text_parent_d )
@ -3820,11 +3828,14 @@ class Eynollah:
areas_cnt_text_parent = [ area for area in areas_cnt_text if area > MIN_AREA_REGION ]
index_con_parents = np . argsort ( areas_cnt_text_parent )
try :
contours_only_text_parent = list ( np . array ( contours_only_text_parent , dtype = object ) [ index_con_parents ] )
except :
contours_only_text_parent = list ( np . array ( contours_only_text_parent , dtype = np . int32 ) [ index_con_parents ] )
areas_cnt_text_parent = list ( np . array ( areas_cnt_text_parent ) [ index_con_parents ] )
contours_only_text_parent = self . return_list_of_contours_with_desired_order ( contours_only_text_parent , index_con_parents )
#try:
#contours_only_text_parent = list(np.array(contours_only_text_parent,dtype=object)[index_con_parents])
#except:
#contours_only_text_parent = list(np.array(contours_only_text_parent,dtype=np.int32)[index_con_parents])
#areas_cnt_text_parent = list(np.array(areas_cnt_text_parent)[index_con_parents])
areas_cnt_text_parent = self . return_list_of_contours_with_desired_order ( areas_cnt_text_parent , index_con_parents )
cx_bigest_big , cy_biggest_big , _ , _ , _ , _ , _ = find_new_features_of_contours ( [ contours_biggest ] )
cx_bigest , cy_biggest , _ , _ , _ , _ , _ = find_new_features_of_contours ( contours_only_text_parent )
@ -3865,10 +3876,11 @@ class Eynollah:
#print("text region early 6 in %.1fs", time.time() - t0)
if self . full_layout :
if np . abs ( slope_deskew ) > = SLOPE_THRESHOLD :
try :
contours_only_text_parent_d_ordered = list ( np . array ( contours_only_text_parent_d_ordered , dtype = np . int32 ) [ index_by_text_par_con ] )
except :
contours_only_text_parent_d_ordered = list ( np . array ( contours_only_text_parent_d_ordered , dtype = object ) [ index_by_text_par_con ] )
contours_only_text_parent_d_ordered = self . return_list_of_contours_with_desired_order ( contours_only_text_parent_d_ordered , index_by_text_par_con )
#try:
#contours_only_text_parent_d_ordered = list(np.array(contours_only_text_parent_d_ordered, dtype=np.int32)[index_by_text_par_con])
#except:
#contours_only_text_parent_d_ordered = list(np.array(contours_only_text_parent_d_ordered, dtype=object)[index_by_text_par_con])
if self . light_version :
text_regions_p , contours_only_text_parent , contours_only_text_parent_h , all_box_coord , all_box_coord_h , all_found_textline_polygons , all_found_textline_polygons_h , slopes , slopes_h , contours_only_text_parent_d_ordered , contours_only_text_parent_h_d_ordered = check_any_text_region_in_model_one_is_main_or_header_light ( text_regions_p , regions_fully , contours_only_text_parent , all_box_coord , all_found_textline_polygons , slopes , contours_only_text_parent_d_ordered )
else :
@ -3958,10 +3970,11 @@ class Eynollah:
if np . abs ( slope_deskew ) < SLOPE_THRESHOLD :
order_text_new , id_of_texts_tot = self . do_order_of_regions ( contours_only_text_parent , contours_only_text_parent_h , boxes , textline_mask_tot )
else :
try :
contours_only_text_parent_d_ordered = list ( np . array ( contours_only_text_parent_d_ordered , dtype = object ) [ index_by_text_par_con ] )
except :
contours_only_text_parent_d_ordered = list ( np . array ( contours_only_text_parent_d_ordered , dtype = np . int32 ) [ index_by_text_par_con ] )
contours_only_text_parent_d_ordered = self . return_list_of_contours_with_desired_order ( contours_only_text_parent_d_ordered , index_by_text_par_con )
#try:
#contours_only_text_parent_d_ordered = list(np.array(contours_only_text_parent_d_ordered, dtype=object)[index_by_text_par_con])
#except:
#contours_only_text_parent_d_ordered = list(np.array(contours_only_text_parent_d_ordered, dtype=np.int32)[index_by_text_par_con])
order_text_new , id_of_texts_tot = self . do_order_of_regions ( contours_only_text_parent_d_ordered , contours_only_text_parent_h , boxes_d , textline_mask_tot_d )