【问题标题】:module 'cv2.ximgproc' has no attribute 'getDisparityVis'模块“cv2.ximgproc”没有属性“getDisparityVis”
【发布时间】:2021-03-22 06:29:54
【问题描述】:

我正在尝试在 Opencv 中对视差图进行后处理。在代码中使用 '''getDisparityVis''' 时会引发以下错误。 非常感谢任何帮助。

filtered_disp_vis= cv2.ximgproc.getDisparityVis(disparity,filtered_disp_vis,1.0);

错误


AttributeError                            Traceback (most recent call last)
<ipython-input-4-1594f6523e20> in <module>

 27         dispr = np.int16(right_disp)

 28         disparity = wls_filter.filter(left_disp, fixedLeft, None, right_disp)
---> 29         ximgproc.getDisparityVis(disparity,filtered_disp_vis,1.0);

 30 
 31         cv2.imshow('leftImage',displ/1.0)

AttributeError: module 'cv2.ximgproc' has no attribute 'getDisparityVis'

【问题讨论】:

  • 你试图调查什么问题?
  • 请提供您使用的OpenCV版本
  • @Christoph Rackwitz 抱歉回复晚了。目前正在使用 OpenCV 版本 4.4.0.46 和 Python 3.9
  • @Christoph Rackwitz 为了调试,我尝试使用不同版本的 OpenCV 4.3.0.36,然后再次运行程序,但错误仍然存​​在
  • @Christoph Rackwitz 能否请您指导我使用“getDisparityVis”的任何示例代码

标签: python opencv camera opencv-python stereo-3d


【解决方案1】:

好的,这个函数是非常 simple,你在Python中需要做的就是创建一个类似的函数。这是我的解决方案:

def get_disparity_vis(src: np.ndarray, scale: float = 1.0) -> np.ndarray:
    '''Replicated OpenCV C++ function

    Found here: https://github.com/opencv/opencv_contrib/blob/b91a781cbc1285d441aa682926d93d8c23678b0b/modules/ximgproc/src/disparity_filters.cpp#L559
    
    Arguments:
        src (np.ndarray): input numpy array
        scale (float): scale factor

    Returns:
        dst (np.ndarray): scaled input array
    '''
    dst = (src * scale/16.0).astype(np.uint8)
    return dst

【讨论】:

    猜你喜欢
    • 2019-12-17
    • 2020-08-30
    • 2020-06-04
    • 2021-02-22
    • 2019-09-14
    • 2019-06-07
    • 1970-01-01
    • 2022-06-15
    • 2017-11-22
    相关资源
    最近更新 更多