From 419beed83685027f37bc0292400ac933a0b141dd Mon Sep 17 00:00:00 2001 From: "Rezanezhad, Vahid" Date: Tue, 15 Oct 2019 13:24:27 +0200 Subject: [PATCH] Update main.py --- qurator/sbb_textline_detector/main.py | 259 +++++++++++++++++++++++++- 1 file changed, 256 insertions(+), 3 deletions(-) diff --git a/qurator/sbb_textline_detector/main.py b/qurator/sbb_textline_detector/main.py index fdd5308..ba1855a 100644 --- a/qurator/sbb_textline_detector/main.py +++ b/qurator/sbb_textline_detector/main.py @@ -1155,7 +1155,93 @@ 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[:] + y_help=np.zeros(len(y)+40) + y_help[20:len(y)+20]=y + x=np.array( range(len(y)) ) + + + peaks_real, _ = find_peaks(gaussian_filter1d(y, 3), height=0) + + + sigma_gaus=8 + z= gaussian_filter1d(y_help, sigma_gaus) + zneg_rev=-y_help+np.max(y_help) + + zneg=np.zeros(len(zneg_rev)+40) + zneg[20:len(zneg_rev)+20]=zneg_rev + zneg= gaussian_filter1d(zneg, sigma_gaus) + + + peaks, _ = find_peaks(z, height=0) + peaks_neg, _ = find_peaks(zneg, height=0) + + 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))] + cx_main=[(M_main[j]['m10']/(M_main[j]['m00']+1e-32)) for j in range(len(M_main))] + cy_main=[(M_main[j]['m01']/(M_main[j]['m00']+1e-32)) for j in range(len(M_main))] + x_min_main=np.array([np.min(contours_main[j][:,0,0]) for j in range(len(contours_main))]) + x_max_main=np.array([np.max(contours_main[j][:,0,0]) for j in range(len(contours_main))]) + + 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))]) + + + 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 ) ) + + final_indexers_sorted=[] + for i in range(len(peaks_neg)-1): + top=peaks_neg[i] + down=peaks_neg[i+1] + + indexes_in=matrix_of_orders[:,0][(matrix_of_orders[:,3]>=top) & ((matrix_of_orders[:,3]=top) & ((matrix_of_orders[:,3]