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:

Qt Code:
  1. Distortion
  2. 0
  3. 0
  4. 0
  5. 0
  6.  
  7. camera_matrix
  8. 278.619
  9. 0
  10. 319.5
  11. 0
  12. 229.661
  13. 239.5
  14. 0
  15. 0
  16. 1
To copy to clipboard, switch view to plain text mode 

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


Qt Code:
  1. int nv = 7;//(int)sqrt((float)mNumFeatures);
  2. int nh = 7;//(int)sqrt((float)mNumFeatures);
  3. int mHaveFeatures;
  4. CvPoint2D32f* cornersArray = new CvPoint2D32f[nh*nv*1];
  5. vector<CvPoint2D32f> temp;
  6.  
  7. IplImage *buf_image=cvLoadImage("cali.jpg");
  8. cvShowImage("imagenoriginal",buf_image);
  9. CvSize size;
  10. size.width = buf_image->width;
  11. size.height = buf_image->height;
  12. IplImage *mImage = cvCreateImage(size, IPL_DEPTH_8U, 1);
  13. cvConvertImage(buf_image, mImage, 0);
  14. cvShowImage("imagenconvertida",mImage);
  15.  
  16.  
  17. CvPoint2D32f *corners = new CvPoint2D32f [nh*nv];
  18. CvPoint2D32f *nextCornersArray = cornersArray;
  19. int corner_count = 0; // corners found
  20. if (!cvFindChessboardCorners(
  21. mImage,
  22. cvSize(nh, nv), // patern size
  23. nextCornersArray,
  24. &corner_count,
  25. CV_CALIB_CB_ADAPTIVE_THRESH |
  26. CV_CALIB_CB_NORMALIZE_IMAGE))
  27. {
  28. //MESSAGE("(Error) [%d] cvFindChesssboardCorners()\n", mId);
  29. //MESSAGE("(Error) [%d] chessboard corners found: %d\n", mId,
  30. //corner_count);
  31. //mHaveFeatures[mActiveFrame] = 0; // processed, but contains errors
  32. mHaveFeatures = 0; // processed, but contains errors
  33. }
  34. else
  35. {
  36. //MESSAGE("[%d] chessboard corners found: %d\n", mId, corner_count);
  37. //mHaveFeatures[mActiveFrame] = 1; // processed with no error
  38. mHaveFeatures = 1; // processed with no error
  39.  
  40. }
  41.  
  42.  
  43. // Refine the results
  44. cvFindCornerSubPix(
  45. mImage,
  46. nextCornersArray,
  47. corner_count,
  48. cvSize(11,11),
  49. cvSize(-1,-1),
  50. cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1)
  51. );
  52.  
  53. // printf("%s\n", buf);
  54. int count=0;
  55. int result=0;
  56. IplImage* cimg = cvCreateImage( cvGetSize(mImage), 8, 3 );
  57. cvCvtColor( mImage, cimg, CV_GRAY2BGR );
  58. cvDrawChessboardCorners( cimg, cvSize(nh, nv), nextCornersArray,
  59. corner_count, result );
  60. cvShowImage( "corners", cimg );
  61.  
  62.  
  63. CvPoint3D32f* corners3d = new CvPoint3D32f[nh*nv*1];
  64.  
  65. float *distortion = new float[4];
  66. float *camera_matrix = new float[9];
  67. float *translation_vectors = new float[3*1];
  68. float *rotation_matrices = new float[9*1];
  69. int* cant=new int(nh*nv);
  70.  
  71. cvCalibrateCamera(1,cant,cvGetSize(mImage),nextCornersArray,
  72. corners3d, distortion, camera_matrix,
  73. translation_vectors,
  74. rotation_matrices, 0);
  75.  
  76.  
  77.  
  78.  
  79. for (int iImg = 0; iImg < 1; iImg++)
  80. {
  81. IplImage *inicio = cvLoadImage("cali.jpg");
  82. IplImage *undistort = cvCreateImage(cvGetSize(inicio), IPL_DEPTH_8U,3);
  83. // ERROR !!!!!!!!!!!!!
  84. cvUnDistortOnce(inicio, undistort, camera_matrix, distortion, 1);
  85.  
  86. }
To copy to clipboard, switch view to plain text mode 

Can any body help me plz???