Type cv::StereoBM 必须实现继承的纯虚方法

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

我一直致力于使用 StereoBM class 根据两个摄像头输入源生成视差图。

我可以创建一个指向变量 StereoBM *sbm; 但是每当我调用一个函数时,我都会遇到发布版本的分段错误。调试构建不会 运行 因为它由于 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);
}

我不完全确定我在上面做错了什么。创建 non-pointer 变量时,我对所有 class 的方法都有此警告:

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

我已经包含了 header <opencv2/calib3d/calib3d.hpp>,我已经确保链接了库,并且我正在 运行ning opencv 3.1.0.

谁能阐明以上所有内容?因为我还在学习 OpenCV 并通过 C++ 推动自己。

StereoBM *sbm;

你在没有分配对象的情况下声明了指针。

cv::Ptr<cv::StereoBM> sbm = cv::StereoBM::create() - 这是创建 StereoBM 对象的正确方法。