我正在解决这个问题,寻找板球间距的爆裂折痕,我已经在某种程度上实现了我想要做的是,我可以使用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)
输入图像:
检测到的线路:
我想要的是:
发布于 2018-12-25 17:56:00
看看hough voting吧。我用它做过类似的事情。
https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
https://stackoverflow.com/questions/53921061
复制相似问题