PDA

View Full Version : cvUnDistortOnce problem



cae
15th February 2010, 14:44
Hi, im trying to calibrate a camera, but i have some problems... im able to calibrate the camera with a chess table picture, the values i obtain are the following:


Distortion
0
0
0
0

camera_matrix
278.619
0
319.5
0
229.661
239.5
0
0
1

and here i show the code, it crushes when i call cvUnDistortOnce .... why???




int nv = 7;//(int)sqrt((float)mNumFeatures);
int nh = 7;//(int)sqrt((float)mNumFeatures);
int mHaveFeatures;
CvPoint2D32f* cornersArray = new CvPoint2D32f[nh*nv*1];
vector<CvPoint2D32f> temp;

IplImage *buf_image=cvLoadImage("cali.jpg");
cvShowImage("imagenoriginal",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("imagenconvertida",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)
);

// printf("%s\n", buf);
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 );


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

cvCalibrateCamera(1,cant,cvGetSize(mImage),nextCor nersArray,
corners3d, distortion, camera_matrix,
translation_vectors,
rotation_matrices, 0);




for (int iImg = 0; iImg < 1; iImg++)
{
IplImage *inicio = cvLoadImage("cali.jpg");
IplImage *undistort = cvCreateImage(cvGetSize(inicio), IPL_DEPTH_8U,3);
// ERROR !!!!!!!!!!!!!
cvUnDistortOnce(inicio, undistort, camera_matrix, distortion, 1);

}



Can any body help me plz???

wysota
19th February 2010, 11:15
How is that related to Qt Programming?