Search code examples
c++opencvvirtualstereo-3ddisparity-mapping

The Type cv::StereoBM must implement the inherited pure virtual method


I've been working towards using the StereoBM class to generate a disparity map based on two camera input feeds.

I can create a pointed variable StereoBM *sbm; but whenever I call a function, I'm presented with a segmentation fault with a Release build. The Debug build will not run as it aborts due to malloc(): memory corruption.

Disparity_Map::Disparity_Map(int rows, int cols, int type) : inputLeft(), inputRight(), greyLeft(), greyRight(), Disparity() {
    inputLeft.create(rows, cols, type);
    inputRight.create(rows, cols, type);

    greyLeft.create(rows, cols, type);
    greyRight.create(rows, cols, type);
}
void Disparity_Map::computeDisparity(){

    cvtColor(inputLeft, greyLeft, CV_BGR2GRAY);
    cvtColor(inputRight, greyRight, CV_BGR2GRAY);

    StereoBM *sbm;

    // This is where the segfault/memory corruption occurs
    sbm->setNumDisparities(112);
    sbm->setBlockSize(9);
    sbm->setPreFilterCap(61);
    sbm->setPreFilterSize(5);
    sbm->setTextureThreshold(500);
    sbm->setSpeckleWindowSize(0);
    sbm->setSpeckleRange(8);
    sbm->setMinDisparity(0);
    sbm->setUniquenessRatio(0);
    sbm->setDisp12MaxDiff(1);

    sbm->compute(greyLeft, greyRight, Disparity);
    normalize(Disparity, Disparity, 0, 255, CV_MINMAX, CV_8U);
}

I'm not entirely sure what I'm doing wrong with the above. When creating a non-pointer variable, I have this warning for all of the class's methods :

The type 'cv::StereoBM' must implement the inherited pure virtual method 'cv::StereoMatcher::setSpeckleRange'

I've included the header <opencv2/calib3d/calib3d.hpp>, I've ensured the library is linked, and I'm running opencv 3.1.0.

Would anyone be able to shed light on all of the above? As I'm still learning OpenCV and pushing myself through C++.


Solution

  • StereoBM *sbm;
    

    You declare pointer without allocation of object.

    cv::Ptr<cv::StereoBM> sbm = cv::StereoBM::create() - it's correct way to create StereoBM object.