Ask Your Question
0

How to use cv::StereoMatcher in c++

asked 2016-03-26 12:00:22 -0600

215 gravatar image

updated 2016-03-26 12:40:13 -0600

I struggling a bit understanding how i should apply StereoMatcher to create a simple disparity map?..

From the Api it seems simple but, but this simple piece of code does result in bad_memory access error.

What is going wrong?

#include <iostream>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/core/affine.hpp>

int main(int argc, const    char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    std::cout << CV_VERSION << std::endl;


    cv::Mat left = cv::imread("../left.png");
    cv::Mat right = cv::imread("../right.png");
    cv::Mat disparity_out;
    cv::StereoMatcher* map;
    map->compute(left, right, disparity_out);
    imshow("test",disparity_out);

    return 0;
}
edit retag flag offensive close merge delete

Comments

cv::StereoMatcher* map; -- this does not ever create a valid instance

berak gravatar imageberak ( 2016-03-26 12:05:00 -0600 )edit

How would you do so? cv::StereoMatcher map won't run as stereoMatcher is an abstract class.

215 gravatar image215 ( 2016-03-26 12:05:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-03-26 12:44:23 -0600

berak gravatar image

updated 2016-03-26 12:49:53 -0600

StereoMatcher is the (abstract) base class to StereoBM or StereoSGBM. please use one of the latter, not the former

also, you have to use cv::Ptr<>not a 'raw' pointer, like :

 Ptr< StereoBM > match = StereoBM::create();
 match->compute(...);

(then, please never call anything mapusing c++, since there's already a container class with the same name in namespace std)

edit flag offensive delete link more

Comments

for the record, -- 3rd iteration ;)

berak gravatar imageberak ( 2016-03-26 13:07:30 -0600 )edit

I tried this code but the result is a black image? do you have any suggestion ?

Laurentiu gravatar imageLaurentiu ( 2017-05-19 06:58:18 -0600 )edit

the disparity is a 16U image, and your values might be fairly small. try something like:

imshow("test",disparity_out * 1000);

also, just print it out:

cout<< disparity_out;
berak gravatar imageberak ( 2017-05-19 07:04:11 -0600 )edit

the result is negative. Range between -8000 and -320000 value for my pixels

Laurentiu gravatar imageLaurentiu ( 2017-05-19 07:15:47 -0600 )edit

ah, sorry, 16S, then. maybe convertTo() 8U, using appropriate scale and offset ?

berak gravatar imageberak ( 2017-05-19 07:21:18 -0600 )edit

Now it's ok, but not very good. And I want to write as binary file, and if I read binary file the images is bad, very bad

Laurentiu gravatar imageLaurentiu ( 2017-05-19 07:25:58 -0600 )edit

After conversion the result is good. Thank you for your help :D

Laurentiu gravatar imageLaurentiu ( 2017-05-19 07:31:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-26 12:00:22 -0600

Seen: 1,728 times

Last updated: Mar 26 '16