Ask Your Question

cornerSubPix Exception

asked 2015-04-12 10:20:15 -0600

pistorinoj gravatar image

updated 2015-04-12 16:58:35 -0600

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:

        // check for new image
            vector<Point2f> pointBuf;
            TermCriteria criteria = TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 );


            // 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);

                cornerSubPix( grayImage, pointBuf, Size(11,11), Size(-1,-1), criteria);

            drawChessboardCorners( tImage, board_sz, Mat(pointBuf), found );

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.

edit retag flag offensive close merge delete


and the exception is ?

berak gravatar imageberak ( 2015-04-12 10:29:23 -0600 )edit

"External component has thrown an exception."

pistorinoj gravatar imagepistorinoj ( 2015-04-12 10:40:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-04-21 08:03:35 -0600

pistorinoj gravatar image

I figured this out and it was stupid. I was storing the point found by findChessboardCorners in one vector (corners) but using a different vector (pointBuf) for the cornerSubPix call. cornerSubPix apparently does not like an empty vector. Not sure why my try/catch call did not report this.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-04-12 10:20:15 -0600

Seen: 717 times

Last updated: Apr 21 '15