我正在尝试使用Python中的OpenCV在图像中查找Hough线。
我的代码如下:
import cv2
import numpy as np
img = cv2.imread('DLMIA.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,100,200,apertureSize = 3)
cv2.imshow('edges',edges)
cv2.waitKey(0)
minLineLength = 30
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imshow('hough',img)
cv2.waitKey(0)
我使用的图片是。
我的结果图片是。
我的代码示例取自这里。
结果图片与之前链接中的图片不同,有什么帮助吗?