问题描述
我正在尝试清理包含直线作为噪声的验证码图像。
我对 OpenCV 非常陌生,但据我所知,最好的方法是将图像变成黑白,然后使用霍夫线变换来检测线条,然后将它们屏蔽。
我是在这里做的:
im_gray = cv2.imread('download.png',cv2.IMREAD_GRAYSCALE)
im_bw = cv2.threshold(im_gray,120,255,cv2.THRESH_BINARY)[1]
im_bw_inverted = cv2.bitwise_not(im_bw)
im_bw_inverted
:
然后我使用霍夫线检测到这些线:
rho = 1
theta = np.pi / 180
min_line_length = 1
max_line_gap = 20
threshold = 50
line_image = np.copy(im_bw) * 0
lines = cv2.houghlinesp(im_bw_inverted,rho,theta,threshold,np.array([]),min_line_length,max_line_gap)
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(line_image,(x1,y1),(x2,y2),(255,0),1)
line_image
:
使用 inpaint
对其进行屏蔽:
line_image_dilate = cv2.dilate(line_image,cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(4,4)))
dst = cv2.inpaint(im_bw_inverted,line_image_dilate,1,cv2.INPAINT_NS)
dst
结果:
有没有更好的方法来清理图像?结果图像看起来不太好有没有办法改善结果?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)