2

I get a ximgproc_DisparityWLSFilter from cv2.ximgproc.createDisparityWLSFilter(left_matcher), but I cannot get ximgproc_DisparityWLSFilter.filter() to work.

The error I get is

OpenCV Error: Assertion failed (!disparity_map_right.empty() && (disparity_map_right.depth() == CV_16S) && (disparity_map_right.channels() == 1)) in cv::ximgproc::DisparityWLSFilterImpl::filter, file ......\opencv_contrib\modules\ximgproc\src\disparity_filters.cpp, line 262

In general, how do I figure out how to use this, when there isn't a single google result for "ximgproc_DisparityWLSFilter"?

powersupply
  • 121
  • 1
  • 3

2 Answers2

4

I had this issue too, what you need to do is create the filter first. Then you can filter... hopefully that makes sense. Here is a code snippet of what I used tested on Python 3.6 opencv3.4.2

wls = cv2.ximgproc.createDisparityWLSFilter(left_Matcher)
filteredDisp = wls.filter(leftStereoComputeOutput, leftOriginalImage, disparity_map_right=rightStereoComputeOutput)

In order to figure out how this bit worked, I had to look at the documentation and at what other people had implemented on Github, then connect the pieces. Lots of Trial and Error.

Arguments for the filter are:

Python:
filtered_disparity_map  =   cv.ximgproc_DisparityFilter.filter( disparity_map_left, left_view[, filtered_disparity_map[, disparity_map_right[, ROI[, right_view]]]] )

Parameters:

disparity_map_left disparity map of the left view, 1 channel, CV_16S type. Implicitly assumes that disparity values are scaled by 16 (one-pixel disparity corresponds to the value of 16 in the disparity map). Disparity map can have any resolution, it will be automatically resized to fit left_view resolution.

left_view left view of the original stereo-pair to guide the filtering process, 8-bit single-channel or three-channel image.

filtered_disparity_map output disparity map.

disparity_map_right optional argument, some implementations might also use the disparity map of the right view to compute confidence maps, for instance.

ROI region of the disparity map to filter. Optional, usually it should be set automatically.

right_view optional argument, some implementations might also use the right view of the original stereo-pair.

The above Parameters were found at https://docs.opencv.org/3.4/db/d72/classcv_1_1ximgproc_1_1DisparityFilter.html

Jacob W. Dallas
  • 383
  • 3
  • 12
  • Where do I get `rightStereoComputeOutput`? SGBM and SBM return only the left disparity. – jiggy Sep 30 '19 at 08:41
  • What is `left_matcher`? I have been looking through the docs and can't quite figure that part out. – Salvatore Jun 28 '20 at 17:28
  • Hey Matt and jiggy, I'm going to update my answer with some code so that you have some context – Jacob W. Dallas Jul 01 '20 at 15:32
  • Well I was going to, but it seems like I'm having a heck of a time finding this specific piece. To each of your questions (from the best of my knowledge): jiggy - the rightStereoComputeOutput was just a variable I named for the disparity_map_right optional argument. It is calculated similarly to the how you got the disparity_map_left except that you flip the photos. Matt - I wish I had the codebase in front of me, but I can't remember for the life of me what that was apologies – Jacob W. Dallas Jul 01 '20 at 23:22
0

Unlike c++, Python doesn't work well with pointers. So the arguments are

Filtered_disp = ximgproc_DisparityWLSFilter.filter(left_disp,left, None,right_disp)

Note that it's no longer a void function in Python!

I figured this out through trial and error though.

guest
  • 711
  • 1
  • 6
  • 11