Ask Your Question
0

Segmentation fault in StereoBeliefPropagation

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

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[])
{
    try
    {
        Mat img1_h = imread("tsukuba1.pgm", 0);
        Mat img2_h = imread("tsukuba2.pgm", 0);

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

        cuda::StereoBeliefPropagation *bp =
            cuda::createStereoBeliefPropagation();

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

        Mat disp_h;
        disp.download(disp_h);
        imshow("Result", disp_h);
        waitKey();

    }
    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
1

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

hunse gravatar image

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

I found the problem. The line

cuda::StereoBeliefPropagation *bp =
    cuda::createStereoBeliefPropagation();

should instead be

Ptr<cuda::StereoBeliefPropagation> bp =
    cuda::createStereoBeliefPropagation();

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

edit flag offensive delete link more

Question Tools

Stats

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

Seen: 659 times

Last updated: Jul 03 '14