Results 1 to 2 of 2

Thread: how to cvCalibrateCamera

  1. #1
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default how to cvCalibrateCamera

    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?



    Qt Code:
    1. int nv = 7;
    2. int nh = 7;
    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("original",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("converted",mImage);
    15.  
    16.  
    17.  
    18. CvPoint2D32f *corners = new CvPoint2D32f [nh*nv];
    19. CvPoint2D32f *nextCornersArray = cornersArray;
    20. int corner_count = 0; // corners found
    21. if (!cvFindChessboardCorners(
    22. mImage,
    23. cvSize(nh, nv), // patern size
    24. nextCornersArray,
    25. &corner_count,
    26. CV_CALIB_CB_ADAPTIVE_THRESH |
    27. CV_CALIB_CB_NORMALIZE_IMAGE))
    28. {
    29. //MESSAGE("(Error) [%d] cvFindChesssboardCorners()\n", mId);
    30. //MESSAGE("(Error) [%d] chessboard corners found: %d\n", mId,
    31. //corner_count);
    32. //mHaveFeatures[mActiveFrame] = 0; // processed, but contains errors
    33. mHaveFeatures = 0; // processed, but contains errors
    34. }
    35. else
    36. {
    37. //MESSAGE("[%d] chessboard corners found: %d\n", mId, corner_count);
    38. //mHaveFeatures[mActiveFrame] = 1; // processed with no error
    39. mHaveFeatures = 1; // processed with no error
    40.  
    41. }
    42.  
    43.  
    44. // Refine the results
    45. cvFindCornerSubPix(
    46. mImage,
    47. nextCornersArray,
    48. corner_count,
    49. cvSize(11,11),
    50. cvSize(-1,-1),
    51. cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1)
    52. );
    53.  
    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. //cvReleaseImage( &cimg );
    62. CvPoint3D32f* corners3d = new CvPoint3D32f[nh*nv*1];
    63.  
    64. float *distortion = new float[4];
    65. float *camera_matrix = new float[9];
    66. float *translation_vectors = new float[3*1];
    67. float *rotation_matrices = new float[9*1];
    68. int* cant=new int(nh*nv);
    69. msgBox.setText(QString("cant %1 mImage.width %2 cord x %3 cord y %4")
    70. .arg(*cant).arg(mImage->width)
    71. .arg(nextCornersArray[0].x).arg(nextCornersArray[0].y));
    72. msgBox.exec();
    73.  
    74. //here is the problem
    75. cvCalibrateCamera(1,cant,cvGetSize(mImage),nextCornersArray,
    76. corners3d, distortion, camera_matrix,
    77. translation_vectors,
    78. rotation_matrices, 0);
    To copy to clipboard, switch view to plain text mode 

    Here the header of the function:
    Qt Code:
    1. /* Calibrates camera using multiple views of calibration pattern */
    2. CV_INLINE void cvCalibrateCamera( int image_count, int* _point_counts,
    3. CvSize image_size, CvPoint2D32f* _image_points, CvPoint3D32f* _object_points,
    4. float* _distortion_coeffs, float* _camera_matrix, float* _translation_vectors,
    5. float* _rotation_matrices, int flags )
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to cvCalibrateCamera

    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.