Ask Your Question

Segmentation fault in StereoBeliefPropagation

asked 2014-06-25 11:28:57 -0500

hunse gravatar image

I'm trying to get a basic example of StereoBeliefPropagation working. Here is my code:

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/cuda.hpp"
#include "opencv2/cudastereo.hpp"

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
        Mat img1_h = imread("tsukuba1.pgm", 0);
        Mat img2_h = imread("tsukuba2.pgm", 0);

        cuda::GpuMat img1, img2, disp;
        disp.upload(img1_h);  // initialize this buffer, will be overwritten

        cuda::StereoBeliefPropagation *bp =

        bp->compute(img1, img2, disp, cuda::Stream::Null());

        Mat disp_h;;
        imshow("Result", disp_h);

    catch(const cv::Exception& ex)
        cout << "Error: " << ex.what() << endl;
        return 1;
    return 0;

When I run this, I get a segmentation fault at bp->compute. Does anyone know why? I'm very new to OpenCV on the GPU, so any advice is welcome. Also, links to examples of successfully running any stereo algorithm on the GPU would be great.

I'm using OpenCV version 3.0.0dev from the beginning of April. From what I can tell, it's set up correctly with the GPU (it detects it, and I can copy images on and off). Also, if anyone wants to run this example, the tsukuba images can be found along with the source code on this page.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-03 13:40:12 -0500

hunse gravatar image

updated 2014-07-03 13:41:39 -0500

I found the problem. The line

cuda::StereoBeliefPropagation *bp =

should instead be

Ptr<cuda::StereoBeliefPropagation> bp =

As a note, the OpenCV GPU examples were very useful in solving this problem.

edit flag offensive delete link more

Question Tools


Asked: 2014-06-25 11:28:57 -0500

Seen: 558 times

Last updated: Jul 03 '14