1
votes

I am calibrating my camera, to perform the undistortion of the images. To achive this goal i am using the calibrate camera function of OpenCV libraries. So i used a chessboard to get the points in the real reference system to extract points. Then i converted these points to the real reference system with mm. So at the end i get two vectors of points: vector of chessboard cross points, and vector of points in mm.

Finally i tried to calibrate the camera with calibrateCamera function, to get my calibration parameters. The calibrate camera function is defined as following:

calibrateCamera(pointsmm,points,Size(640,480),cameraMatrix,distCoeffs,rvec,tvec );  

where points and poinstmm are defined as following:

vector<vector<Point2f>> points;
vector<vector<Point3f>> pointsmm;

and cameraMatrix, distCoeff, rvec, tvec as

vector <float>

.

The vector points are obtained as following:

    vector <Point2f> temp;
    bool found = findChessboardCorners(md1,Size(nx,ny),temp);
    if (found){
        //cornerSubPix( md1_g, temp, Size(11,11), Size(-1,-1), TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 )); //(peggiora)
        points.push_back(temp); 
        vector<Point3f> temp2;
        for( int i = 0; i < ny; i++ )
            for( int j = 0; j < nx; j++ )
                temp2.push_back(Point3f(float((2*j + i % 2)*squaresize), float(i*squaresize), 220));
        pointsmm.push_back(temp2);
    }
    //nx and ny are the size of the image
    cv::drawChessboardCorners(md1, Size(nx,ny), Mat(temp), found);

This operation is repeated for all acquisition that i have so the size of points and pointsmm, corresponds with number of acquisition. While the size of each elements of the vectors corresponds with the expected size of the chessboard.

The chessboard that i draw is ok, and points corresponds. In addition i checked that pointsmm and points have the same size.

When i call the calibrate function in execution i get the following error: Exception not managed in 'System.Runtime.InteropServices.SEHException' in BridgeLibrary.dll External component has thrown an exception. Debugging the software the excepetion is thrown when i call the calibrateCamera function.

I'm using CLI/C++ to bridge wpf with c++. I think that the problem depends on how i call calibrateCamera function. I tried also to define the vectors rvec and tvec as vector, but it doesn't work. I am using OpenCV version 2.19 .

1
can you try to run the code without any cli/wpf clutter ? it seems, that opencv threw an exception, and that got stuck somewhere in your managed code. also, if there ever was a opencv2.1.9 version, that's far too old to be used.berak
Thank you for your suggestion berak. Actually i can't run my code without cli. It will make me loose too time. But i don't think that it depends on the kind of the project that i am using for.dinoiama

1 Answers

1
votes

You have used the correct trick..

I used the same method to calibrate the camera for the fixed pattern in my project.

Use this link for more help:

http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration_square_chess/camera_calibration_square_chess.html