【发布时间】:2016-06-18 04:50:46
【问题描述】:
我一直在努力使用 StereoBM 类根据两个相机输入源生成视差图。
我可以创建一个指向变量StereoBM *sbm;,但是每当我调用一个函数时,我都会在发布版本中遇到分段错误。由于malloc(): memory corruption,Debug 构建将不会运行,因为它中止。
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);
}
我不完全确定我在上面做错了什么。创建非指针变量时,我对所有类的方法都有这个警告:
The type 'cv::StereoBM' must implement the inherited pure virtual method 'cv::StereoMatcher::setSpeckleRange'
我已包含标题 <opencv2/calib3d/calib3d.hpp>,我已确保已链接库,并且我正在运行 opencv 3.1.0。
任何人都能够阐明以上所有内容吗?因为我仍在学习 OpenCV 并推动自己学习 C++。
【问题讨论】:
-
你能提供一个重现错误的小sn-p吗?看看如何做一个minimal reproducible example
-
在将 sbm 设置为指针时,我已经使用我尝试与 opencv 3.1.0 一起使用的代码更新了原始帖子,另一个错误是当我定义
StereoBM sbm时没有别的代码编译,但不运行。 -
您定义了一个指向 SMB 的指针,但实际上并没有创建一个
-
能否详细说明您的评论
-
改变 StereoBM *sbm;到 StereoBM sbm; ...以及 sbm-> 到 sbm 的所有实例。这样,您将在堆栈上分配一个 StereoBM 对象,您可以使用它,而不是一个指向未定义的无处的指针,当您尝试取消引用它时会崩溃。
标签: c++ opencv virtual stereo-3d disparity-mapping