I wrote a code to find disparity map from two images "left" and "right"; and saving the map in "stereo". The code seems okay to me but somehow I'm getting exception:
On the terminal window:
OpenCV Error: Bad argument (Unknown array type) in unknown function, file ......\src\opencv\modules\core\src\matrix.cpp, line 698
The code is
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);
I'm using VS ultimate 2012, Windows 8, OpenCV 2.4.4. Please guide me how to fix this exception.
I think
cvFindStereoCorrespondenceBM
requiresIplImage
orcvMat
. Since you are usingMat
, you should use C++ API of OpenCV.Since you are using Mat, you should try this and check if it works or not.
I don't know if this will work or not, but the C++ API StereoBM will surely work.
Try this and see if it works.
You can define some size.