【问题标题】:opencv detecting hallway edges and straight lines in realtime/still imagesopencv在实时/静止图像中检测走廊边缘和直线
【发布时间】:2020-06-08 17:38:19
【问题描述】:

我有一张像这样的图片。

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

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

我想知道是否有人知道任何库/文档或可以向我指出任何方向,即能够实时检测角落、门等的边缘,或者 使用 OpenCV 在静止图像中检测?

【问题讨论】:

    标签: python image opencv object-detection


    【解决方案1】:

    Opencv python 有可以提供帮助的霍夫线的实现。虽然算法很繁重,但它有一个实时工作的概率版本。您甚至可以以准确性为代价调整参数以使其更快。

    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

    【讨论】:

    • 你好!哇,这看起来比 simplecv 重得多。我试过谷歌搜索,但我真的找不到很多。感谢您的贡献!我真的很感激。
    • 其实并不重。它只是没有隐藏许多实现细节并让您对事物有更多的控制权。这是来自 OpenCV 的文档,其中包含有关其工作原理的一些说明。 opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 2023-03-20
    • 1970-01-01
    • 2015-08-29
    • 2010-12-01
    相关资源
    最近更新 更多