代码看起来像这样
def smooth(y, box_pts):
box = np.ones(box_pts)/box_pts
y_smooth = np.convolve(y, box, mode='same')
return y_smooth
img = cv2.imread(filename)
# RGB-GRAY Conversion
gray = rgb2gray(img)
# Gray to Binary Conversion Ostru Thresholding with Gaussian
blur = cv2.GaussianBlur(gray,(5,5),0)
ret3,thres = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
#_,thres= cv2.threshold(gray,140,255,cv2.THRESH_BINARY)
#Counting black pixels per row
counts = np.sum(thres==0, axis=1)
row_number = [i for i in range(thres.shape[0])]
counts = smooth(counts,19)
plt.plot(row_number, counts, label='fit')
plt.xlabel('Row Number')
plt.ylabel('Number of Black Pixels')
plt.title('Horizontal Projection Profile')
我想找到用于分隔不同行的行号。所需的 row_number 为 [0, 227, 381, 547, 687]。我尝试使用scipy.signal.argrelextrema()找到极值或局部最小值,但我也得到了其他(不需要的)最小值。所以我的问题是 - 是否有任何可能的技术让我可以找到这些行分隔符行号?
PS - 设置阈值似乎不起作用,因为对于新的图像投影配置文件可能会改变,所以阈值是。
任何帮助将不胜感激!!!