Ask Your Question
0

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:

    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.

edit retag flag offensive close merge delete

Comments

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
1

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

Stats

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

Seen: 958 times

Last updated: Apr 21 '15