PDA

View Full Version : how to cvCalibrateCamera



cae
13th February 2010, 12:08
Hi , i'm trying to calibrate a camera with opencv, but i`m not able to do it!

I can create, modify images, i'm able to search for the chess corners, draw them.... but when calibration arrives... it fails.

I thik there is a problem with the parameters:
cvCalibrateCamera(1,cant,cvGetSize(mImage),nextCor nersArray,
corners3d, distortion, camera_matrix,
translation_vectors,
rotation_matrices, 0);
1= number of images
cant= number of corners per image i think, but im trying with 1 only
cvGetSize(mImage)= image size
nextCornersArray= array with the cordx and cordy of every cornerchess
corners3d= empty, maybe it is for the output <--- i think i've to do something with this...
distortion...
.
.
. i supposed all are outputs

any idea?






int nv = 7;
int nh = 7;
int mHaveFeatures;
CvPoint2D32f* cornersArray = new CvPoint2D32f[nh*nv*1];
vector<CvPoint2D32f> temp;

IplImage *buf_image=cvLoadImage("cali.jpg");
cvShowImage("original",buf_image);
CvSize size;
size.width = buf_image->width;
size.height = buf_image->height;
IplImage *mImage = cvCreateImage(size, IPL_DEPTH_8U, 1);
cvConvertImage(buf_image, mImage, 0);
cvShowImage("converted",mImage);



CvPoint2D32f *corners = new CvPoint2D32f [nh*nv];
CvPoint2D32f *nextCornersArray = cornersArray;
int corner_count = 0; // corners found
if (!cvFindChessboardCorners(
mImage,
cvSize(nh, nv), // patern size
nextCornersArray,
&corner_count,
CV_CALIB_CB_ADAPTIVE_THRESH |
CV_CALIB_CB_NORMALIZE_IMAGE))
{
//MESSAGE("(Error) [%d] cvFindChesssboardCorners()\n", mId);
//MESSAGE("(Error) [%d] chessboard corners found: %d\n", mId,
//corner_count);
//mHaveFeatures[mActiveFrame] = 0; // processed, but contains errors
mHaveFeatures = 0; // processed, but contains errors
}
else
{
//MESSAGE("[%d] chessboard corners found: %d\n", mId, corner_count);
//mHaveFeatures[mActiveFrame] = 1; // processed with no error
mHaveFeatures = 1; // processed with no error

}


// Refine the results
cvFindCornerSubPix(
mImage,
nextCornersArray,
corner_count,
cvSize(11,11),
cvSize(-1,-1),
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1)
);

int count=0;
int result=0;
IplImage* cimg = cvCreateImage( cvGetSize(mImage), 8, 3 );
cvCvtColor( mImage, cimg, CV_GRAY2BGR );
cvDrawChessboardCorners( cimg, cvSize(nh, nv), nextCornersArray,
corner_count, result );
cvShowImage( "corners", cimg );
//cvReleaseImage( &cimg );
CvPoint3D32f* corners3d = new CvPoint3D32f[nh*nv*1];

float *distortion = new float[4];
float *camera_matrix = new float[9];
float *translation_vectors = new float[3*1];
float *rotation_matrices = new float[9*1];
int* cant=new int(nh*nv);
msgBox.setText(QString("cant %1 mImage.width %2 cord x %3 cord y %4")
.arg(*cant).arg(mImage->width)
.arg(nextCornersArray[0].x).arg(nextCornersArray[0].y));
msgBox.exec();

//here is the problem
cvCalibrateCamera(1,cant,cvGetSize(mImage),nextCor nersArray,
corners3d, distortion, camera_matrix,
translation_vectors,
rotation_matrices, 0);



Here the header of the function:

/* Calibrates camera using multiple views of calibration pattern */
CV_INLINE void cvCalibrateCamera( int image_count, int* _point_counts,
CvSize image_size, CvPoint2D32f* _image_points, CvPoint3D32f* _object_points,
float* _distortion_coeffs, float* _camera_matrix, float* _translation_vectors,
float* _rotation_matrices, int flags )

cae
13th February 2010, 13:06
found!


it was that array, it must have the "original" coords of the points

for(y = 0; y < nv; y++ )
{
for( x = 0; x < nv; x++, i++ )
{
corners3d[i].x = quadsize * x;
corners3d[i].y = quadsize * y;
corners3d[i].z = 0;
}
}


dont know yet if the results are good, but at least it doesnt crush!