我的任务是找到线(startX,startY,endX,endY)和矩形(4条线)的坐标。这是输入文件:
我使用下一个代码:
img = cv2.imread(image_src)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh1 = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
edges = cv2.Canny(thresh1,50,150,apertureSize = 3)
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,10,minLineLength,maxLineGap)
print(len(lines))
for line in lines:
cv2.line(img,(line[0][0],line[0][1]),(line[0][2],line[0][3]),(0,0,255),6)
Run Code Online (Sandbox Code Playgroud)
从上一张图像中,您可以看到大量的小红线。
问题: