cornerSubPix Exception
I am attempting to calibrate a Logitech c930 camera and keep getting an exception when I follow what I think is the sample calibration code.
I am using OpenCV 2.4.9 with VS2012 c++/cli on a Win 8.1 machine. I have attempted to follow the tutorial code at: C:\opencv\sources\samples\cpp\tutorial_code\calib3d\camera_calibration\camera_calibration.cpp.
My code looks like:
while(successes<CALIBRATE_NUMBER_OF_BOARDS_TO_MATCH && totalframes<CALIBRATE_TOTAL_FRAMES)
{
// check for new image
if(CameraVI->isFrameNew(CameraNumber))
{
vector<Point2f> pointBuf;
TermCriteria criteria = TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 );
totalframes++;
// load the image from the buffer
CameraVI->getPixels(CameraNumber, LdataBuffer, false, true);
// convert it to a mat
cv::Mat tImage(Images->Height, Images->Width, CV_8UC3, LdataBuffer, Mat::AUTO_STEP);
bool found = findChessboardCorners(tImage, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK| CV_CALIB_CB_NORMALIZE_IMAGE);
if(found)
{
successes++;
cvtColor(tImage,grayImage,CV_BGR2GRAY);
cornerSubPix( grayImage, pointBuf, Size(11,11), Size(-1,-1), criteria);
imagePoints.push_back(pointBuf);
}
drawChessboardCorners( tImage, board_sz, Mat(pointBuf), found );
}
Sleep(35);
When I run this, I consistently get an exception on the cornerSubPix call. I know that the image coming in is correct (it is 1920 x 1080) as I can show the image to the screen. Also, the pointBuf seems to be correctly defined and I can access it before the cornerSubPix call. One thing I do notice is that some examples use CV_BGR2GRAY for the color conversion while others use CV_RGB2GRAY. I have tried both but still get the exception. Some examples also use a 5x5 instead of an 11x11 window. I have also tried both but still get the exception.
Any help greatly appreciated.
and the exception is ?
"External component has thrown an exception."