diff --git a/qurator/sbb_textline_detector/main.py b/qurator/sbb_textline_detector/main.py index e182ed2..1e58586 100644 --- a/qurator/sbb_textline_detector/main.py +++ b/qurator/sbb_textline_detector/main.py @@ -1155,6 +1155,7 @@ class textlineerkenner: elif slope_for_all == 999: slope_for_all = slope_biggest self.slopes.append(slope_for_all) + def order_of_regions(self, textline_mask,contours_main): mada_n=textline_mask.sum(axis=1) y=mada_n[:] @@ -1168,6 +1169,7 @@ class textlineerkenner: sigma_gaus=8 + z= gaussian_filter1d(y_help, sigma_gaus) zneg_rev=-y_help+np.max(y_help) @@ -1182,6 +1184,8 @@ class textlineerkenner: peaks_neg=peaks_neg-20-20 peaks=peaks-20 + + if contours_main!=None: areas_main=np.array([cv2.contourArea(contours_main[j]) for j in range(len(contours_main))]) M_main=[cv2.moments(contours_main[j]) for j in range(len(contours_main))] @@ -1192,38 +1196,66 @@ class textlineerkenner: y_min_main=np.array([np.min(contours_main[j][:,0,1]) for j in range(len(contours_main))]) y_max_main=np.array([np.max(contours_main[j][:,0,1]) for j in range(len(contours_main))]) + #print(contours_main[0],np.shape(contours_main[0]),contours_main[0][:,0,0]) + + if contours_main!=None: indexer_main=np.array(range(len(contours_main))) + if contours_main!=None: len_main=len(contours_main) else: len_main=0 + matrix_of_orders=np.zeros((len_main,5)) + matrix_of_orders[:,0]=np.array( range( len_main ) ) + matrix_of_orders[:len_main,1]=1 matrix_of_orders[len_main:,1]=2 + matrix_of_orders[:len_main,2]=cx_main + + matrix_of_orders[:len_main,3]=cy_main + + + matrix_of_orders[:len_main,4]=np.array( range( len_main ) ) + #matrix_of_orders[len_main:,4]=np.array( range( len_head ) ) + + #print(matrix_of_orders) + + peaks_neg_new=[] + + peaks_neg_new.append(0) + for iii in range(len(peaks_neg)): + peaks_neg_new.append(peaks_neg[iii]) + + peaks_neg_new.append(textline_mask.shape[0]) + final_indexers_sorted=[] - for i in range(len(peaks_neg)-1): - top=peaks_neg[i] - down=peaks_neg[i+1] + for i in range(len(peaks_neg_new)-1): + top=peaks_neg_new[i] + down=peaks_neg_new[i+1] indexes_in=matrix_of_orders[:,0][(matrix_of_orders[:,3]>=top) & ((matrix_of_orders[:,3]=top) & ((matrix_of_orders[:,3]