python - Opencv - python - 将线段检测器(LSD)中的线段连接起来形成一条线

标签 python opencv image-processing straight-line-detection

我正在解决这个问题,即找到板球球场的爆裂折痕,我已经在某种程度上实现了我想做的事情,即我可以使用 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)

输入图片:enter image description here

检测到的行:enter image description here

我想要什么:enter image description here

最佳答案

查看霍夫投票。我已经将它用于类似的事情。

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/

相关文章:

algorithm - Google 如何通过安全搜索识别成人内容?

matlab - MATLAB 中的高斯滤波器

python - 打印带有重复键的多维字典

python - 配置 nginx 和 uwsgi 时出现 'No such file or directory' 错误

javascript - jquery.post() 后端响应,但回调函数参数为空

python - 如何使用 requirements.txt 在 Heroku python 网络应用程序中安装 Dlib?

python - 如何在按属性分组时查询对象集合

java - Opencv 打开视频文件但捕获 isOpened 始终为 false

c++ - 我可以提供对 OpenCV 矩阵的只读访问吗?

image-processing - 图像识别算法的学习步骤