Python opencv很长的Hough线

2024-07-04 14:03:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我想得到五边形,三角形和正方形的霍夫线。 这是从cv2.cannyenter image description here获得的边缘图像

环境:Python2.7、Opencv 2.4.11

img = cv2.imread("shapes.png")
grayimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cannygrayimgBlur = cv2.Canny(grayimg, 50, 150)  
minLineLength = 100
maxLineGap = 10
lines =cv2.HoughLinesP(cannygrayimgBlur,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('img',img)
cv2.waitKey(0)

但结果是非常奇怪的。只绘制正方形的完整边。 enter image description here


Tags: imgcv2linesx1x2三角形y1正方形

热门问题