【问题标题】:Live camera to shape distance calculation based on computer vision基于计算机视觉的实时摄像头形状距离计算
【发布时间】:2020-01-01 14:02:45
【问题描述】:

目标是实时检测墙壁并将距离导出到墙壁。有一个设置,一个封闭的 4 面墙,每面墙上有一组独特且理想的形状(三角形,正方形......)一个机器人带摄像头的将在墙壁内漫游并具有计算机视觉。机器人应检测形状并导出相机与墙壁(或该形状)之间的距离。

我已经通过 Opencv 和形状检测 (cv2.approxPolyDP) 和距离计算(周长计算和边缘计数,然后将像素长度转换为实际距离)实现了这个目标。

它在 90 度角时完美工作,但在其他角度时无效。

任何更好的方法。

谢谢

for cnt in contours[1:]:
# considering countours from 1 because from practical experience whole frame is often considered as a contour
        area = cv2.contourArea(cnt)
        # area of detected contour
        approx = cv2.approxPolyDP(cnt, 0.02*cv2.arcLength(cnt, True), True)
        #It predicts and makes pixel connected contour to a shape
        x = approx.ravel()[0]
        y = approx.ravel()[1]
        # detected shape type label text placement 
        perimeter = cv2.arcLength(cnt,True)
        # find perimeter

【问题讨论】:

    标签: python-3.x opencv


    【解决方案1】:

    在其他角度,您可以看到形状的透视图。

    您必须使用Geometric Transformations 来中和透视效果(使用已知形状的对象或相机角度)。

    还考虑到强烈建议使用校正图像Camera Calibration


    编辑:

    假设您的墙上有一个正方形。当相机从物体的非 90 度直视视角捕捉图像时。正方形不对齐,看起来变形,这会导致测量误差。

    但你可以使用cv2.getPerspectiveTransform()。该函数计算透视变换M的3x3矩阵。

    之后使用warped = cv2.warpPerspective(img, M, (w,h)) 并对图像应用透视变换。现在正方形(在warped 图像中)看起来像 90 度直视图,并且您当前的代码在输出图像(warped 图像)上运行良好。

    请原谅我的错误解释。也许这篇博文可以帮助你:

    4 Point OpenCV getPerspective Transform Example

    Find distance from camera to object/marker using Python and OpenCV

    【讨论】:

    • 嗨。你能解释一下函数或算法的前景吗?
    • @saran ,我编辑我的答案。我希望这会对你有所帮助。
    猜你喜欢
    • 2017-02-05
    • 2013-05-23
    • 1970-01-01
    • 2018-03-19
    • 2011-11-26
    • 2018-11-07
    • 1970-01-01
    • 2018-05-13
    • 2015-02-28
    相关资源
    最近更新 更多