我正在解决这个问题,即找到板球球场的爆裂折痕,我已经在某种程度上实现了我想做的事情,即我可以使用 opencv 中的 LSD 检测垂直线段,但我似乎不明白如何连接不同的线段在同一行上做一个完整的行。
寻找线段的代码:
import cv2
import math
import numpy as np
#Read gray image
img = cv2.imread("2.jpg",0)
#Create default parametrization LSD
lsd = cv2.createLineSegmentDetector(0)
#Detect lines in the image
lines = lsd.detect(img)[0] #Position 0 of the returned tuple are the detected lines
print(lines[0][0][0])
ver_lines = []
for line in lines:
angletan = math.degrees(math.atan2((round(line[0][3],2) - round(line[0][1],2)), (round(line[0][2],2) - round(line[0][0],2))))
if(angletan > 85 and angletan < 95):
ver_lines.append(line)
#Draw detected lines in the image
drawn_img = lsd.drawSegments(img,np.array(ver_lines))
#Show image
cv2.imshow("LSD",drawn_img )
cv2.waitKey(0)
输入图片:
检测到的行:
我想要什么:
最佳答案
查看霍夫投票。我已经将它用于类似的事情。
https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
关于python - Opencv - python - 将线段检测器(LSD)中的线段连接起来形成一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53921061/