python - Opencv - python - 从线段检测器(LSD)连接线段以形成一条线
问题描述
我正在研究寻找板球场的爆裂折痕的问题,我已经在一定程度上实现了我想要做的事情,即我可以使用来自 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)
解决方案
推荐阅读
- r - 有没有办法“扩大”R中向量的真实值?
- react-native - React Native 样式 textDecorationLine:“下划线”在 iOS 13 中不起作用
- php - Gaufrette(使用 AWS)和 Symfony 4 - 阅读图片
- css - 如何在我的 Word 新闻网站上对齐页脚链接?
- java - 如何强制侦探不发送单个 b3 标头
- ocaml - 在 OCaml 中打开模块的问题
- apostrophe-cms - 移至回收站的项目仍显示在站点导航中
- ios - 如何提取在 Moya 中失败的请求的 url
- awk - 数组数组的排序与 awk 中的多维数组有何不同?
- spring-boot - 在 docker 中启动 ApplicationContext 时出错