【发布时间】:2019-06-19 00:32:05
【问题描述】:
我想要一种自动检测和纠正收据图像歪斜的方法, 我试图找到不同旋转角度的行之间的差异,并选择具有最大差异的角度。 为了计算方差,我做了以下操作:
1.对于每一行,我计算了像素值的总和并将其存储在一个列表中。
2.使用np.var(list)找到列表的方差
src = cv.imread(f_name, cv.IMREAD_GRAYSCALE)
blurred=median = cv.medianBlur(src,9)
ret,thresh2 = cv.threshold(src,127,255,cv.THRESH_BINARY_INV)
height, width = thresh2.shape[:2]
print(height,width)
res=[-1,0]
for angle in range(0,100,10):
rotated_temp=deskew(thresh2,angle)
cv.imshow('rotated_temp',rotated_temp)
cv.waitKey(0)
height,width=rotated_temp.shape[:2]
li=[]
for i in range(height):
sum=0
for j in range(width):
sum+=rotated_temp[i][j]
li.append(sum)
curr_variance=np.var(li)
print(curr_variance,angle)
if(curr_variance>res[0]):
res[0]=curr_variance
res[1]=angle
print(res)
final_rot=deskew(src,res[1])
cv.imshow('final_rot',final_rot)
cv.waitKey(0)
但是,倾斜图像的方差会超过正确对齐的图像,有什么办法可以纠正这个问题
横向文本对齐图像的方差(必需):122449908.009789
垂直文本对齐图像的方差:1840071444.404522
我尝试过使用 HoughLines 但是由于文本之间的间距太少,检测到垂直线,因此这也失败了
感谢任何修改或其他方法
【问题讨论】:
-
尝试扩大图像然后侵蚀它。这应该会生成大斑点,您可以检测到最大长度
标签: python image-processing opencv3.0 variance houghlines