0

我写了一个代码来从“左”和“右”两个图像中找到视差图;并将地图保存为“立体”。代码对我来说似乎没问题,但不知何故我遇到了异常:

在终端窗口上:

OpenCV 错误:未知函数中的错误参数(未知数组类型),文件......\src\opencv\modules\core\src\matrix.cpp,第 698 行

代码是

Mat left = imread( "files\\left.jpg" );
Mat right = imread( "files\\right.jpg" );
Size size = left.size();
namedWindow( "left", CV_WINDOW_AUTOSIZE );
imshow("left", left);
cvNamedWindow( "right", CV_WINDOW_AUTOSIZE );
imshow("right", right);

Mat left_C1;
cvtColor(left, left_C1, CV_RGB2GRAY);
Mat right_C1;
cvtColor(right, right_C1, CV_RGB2GRAY);

Mat stereo = Mat(size, CV_16SC1);
CvStereoBMState* state = cvCreateStereoBMState();

state->preFilterSize=5;
state->preFilterCap=1;
state->SADWindowSize=5;
state->minDisparity=0;
state->numberOfDisparities=64;
state->textureThreshold=0;
state->uniquenessRatio=0;

cvFindStereoCorrespondenceBM(&left_C1, &right_C1, &stereo, state);

namedWindow( "stereo", CV_WINDOW_AUTOSIZE );
imshow("stereo",stereo);
waitKey(0);

我正在使用 VS Ultimate 2012、Windows 8、OpenCV 2.4.4。请指导我如何解决此异常。

4

1 回答 1

3

我认为 cvFindStereoCorrespondenceBM需要IplImagecvMat。由于您使用的是Mat,您应该使用 OpenCV 的 C++ API。

StereoBM sbm;
sbm.state->SADWindowSize = 23;
sbm.state->numberOfDisparities = 96;
sbm.state->preFilterSize = 25;
sbm.state->preFilterCap = 63;
sbm.state->minDisparity = 0;
sbm.state->textureThreshold = 20;
sbm.state->uniquenessRatio = 10;
sbm.state->speckleWindowSize = 25;
sbm.state->speckleRange = 8;
sbm.state->disp12MaxDiff = 1;
// change the parameters

sbm(left_c1, right_c1, stereo);

由于您使用的是 Mat,您应该尝试一下并检查它是否有效。

cvFindStereoCorrespondenceBM(left_C1, right_C1, stereo, state);

我不知道这是否有效,但 C++ API StereoBM 肯定会有效。

试试这个,看看它是否有效。

#define WIDTH 426
#define HEIGHT 320

您可以定义一些大小。

CvSize imageSize = {WIDTH,HEIGHT};
CvMat* frame1r = cvCreateMat( imageSize.height,imageSize.width, CV_8U );
CvMat* frame2r = cvCreateMat( imageSize.height,imageSize.width, CV_8U );
CvMat* disp = cvCreateMat( imageSize.height, imageSize.width, CV_16S );
CvMat* vdisp = cvCreateMat( imageSize.height,imageSize.width, CV_8U );

// Load image in frame1r and frame2r

cvFindStereoCorrespondenceBM( frame1r, frame2r, disp, state);
cvNormalize( disp, vdisp, 0, 256, CV_MINMAX );                   
cvShowImage( "disparity", vdisp );
于 2013-03-19T13:28:36.320 回答