gpt4 book ai didi

python - opencv在实时/静态图像中检测走廊边缘和直线

转载 作者:行者123 更新时间:2023-12-02 17:24:08 25 4
gpt4 key购买 nike

我有一张看起来像这样的图片。

我知道在 simplecv 中,您可以使用:

img = Image('hallway.jpg')
img.show()
img.edges.show()
lines = img.findLines()
lines = lines.filter(lines.length() > 50)
lines.show()

我想知道是否有人知道任何库/文档或可以指向我任何方向,以便能够使用OpenCV 实时检测拐角,门等的边缘或静态图像

enter image description here

最佳答案

Opencv python的Hough行的实现可能会有所帮助。虽然算法很繁琐,但它的一个概率版本可以实时运行。您甚至可以调整参数以使其更快而以准确性为代价。

import cv2
import numpy as np

img = cv2.imread('hallway.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imshow("preview", img)
cv2.waitkey(0)

请注意,您可能必须根据需要调整canny和其他参数的阈值。

另一种方法是使用轮廓。这可能对 https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.html有帮助

关于python - opencv在实时/静态图像中检测走廊边缘和直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60386959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com