开发者

How to apply `DisparityWLSFilter` to live stereo camera data using precomputed disparity map in OpenCV-Python

I am trying to post-filter my stereo cameras using cv2.ximgproc.createDisparityWLSFilter after block matching and rectification.

I have been following this tutorial and have implemented the suggestions in this answer and this answer in my code (snippet, below). However, I already have an instance of cv2.StereoBM_create, performed rectification, and computed the disparity.

    stereo = cv2.StereoBM_create()
    wls_filter = cv2.ximgproc.createDisparityWLSFilter(stereo)

    disparity = stereo.compute(Left_rect, Right_rect)
    disparity = disparity.astype(np.float32)
       
    # Scaling down the disparity values and normalizing them
    disparity = (disparity / 16.0 - minDisparity) / numDisparities
    
    # Normalize and apply a color map
    disparityImg = cv2.normalize(src=disparity, dst=None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX,
                                 dtype=cv2.CV_8UC1)
    disparityImg = cv2.applyColorMap(disparityImg, cv2.COLORMAP_JET)


    # Applying WLS filter to remove noise
    left_image = Left_rect
    right_image = Right_rect
    left_matcher = stereo
    right_matcher = cv2.ximgproc.createRightMatcher(left_matcher)
    left_disp = left_matcher.compute(left_image, right_image)
    right_disp = right_matcher.compute(right_image, left_image)

    # Now create DisparityWLSFilter
    wls_filter = cv2.ximgproc.createDisparityWLSFilter(left_matcher)
    filtered_disp = wls_filter.filter(left_disp, left_image, disparity_map_right=right_disp)

    # Displaying the disparity map
    cv2.imshow("disparity map", disparityImg)
    cv2.imshow("filtered dispar开发者_Go百科ity map", filtered_disp)

The parameters for the stereoBM and wls filter are set using a GUI (see image below).

How to apply `DisparityWLSFilter` to live stereo camera data using precomputed disparity map in OpenCV-Python

The above tutorial/code is written for two static left and right images. However, I need to apply it stereo webcams, as applied in this project.

When I run the code above, I get a blank disparity map image. Without the WLSFilter code the disparity map image shows is displayed.

How to apply `DisparityWLSFilter` to live stereo camera data using precomputed disparity map in OpenCV-Python

I have tried feeding it my disparity map with left_matcher = disparity, but that obviously doesn't work as I need the left/right disparities separate.

I'm sure this is an easy fix/silly mistake I'm making, I just can't see it! Can anyone spot where I'm going wrong, please?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜