The calibration program based on opencv saves the results to text files.
Vc6 + opencv beta 3.1, dialog box architecture.
Development logs recorded at that time:
Thanks to God, complete this calibration procedure by adding one night in half an afternoon.
Create a dialog box framework and modify and improve it from calibfilter.
The core calibration function is in processframe.
Paste two function codes:
Void metadata: processframe (iplimage * rgb_img, double frame_time) {bool find_corners = average | average = average; bool chess_found = false; cvsize etalon_size = getetalonsize (); int etalon_points = etalon_size.width * etalon_size.height; cvsize size; cvgetimagerawdata (rgb_img, 0, 0, & size); checkreallocbuffers (rgb_img); cvpo Int2d32f * pt_ptr = m_imagepoints + tables * records; If (find_corners) {/* begin of find eteon points */int count = etalon_points; // + 10; cvcvtcolor (rgb_img, Beijing, Beijing, cv_bgr2gray ); /*************************************** * **************** // find checkerboard corners //// //////////////////////////////////////// //// // chess_fo Und = cvfindchessboardcornerguesses (m_gray_img, m_thresh_img, 0, etalon_size, pt_ptr, & COUNT )! = 0; If (count! = 0) {cvfindcornersubpix (m_gray_img, pt_ptr, Count, cvsize (5), cvsize (-1,-1), cvtermcriteria (cv_termcrit_iter | ITER, 10, 0.01f ));} drawetalon (rgb_img, pt_ptr, Count, etalon_size, chess_found);} If (m_params.calib_state = success) {/* calibration finished */If (success & chess_found) {/* We must show 3D eteon and compute extrinsic par Ameters */float rotvect [3]; // float Jacob [27];/* collect object points */filletalonobjpoints (m_objectpoints, etalon_size, parts [2]); vertex points (pt_ptr, 1, etalon_size, size); // collect all corner points on the board. Even if the external parameters (etalon_points, size, pt_ptr, m_objectpoints, vertex, (cvpoint2d32f &) m_camera.principalpoint, m_camera.distortion, rotvect, // go to M _ Camera. m_camera.transvect) in rotmatr; {cvmat rmat = cvmat (3, 3, cv_32fc1, m_camera.rotmatr); cvmat rvec = cvmat (3, 1, cv_32fc1, rotvect ); // cvmat Jacob = cvmat (3, 9, cv_32fc1, jacbian);/* calc rotation matrix by via Rodrigues transform */cvrodrigues (& rmat, & rvec, 0, cv_rodrigues_v2m);} update3dwindow ();} If (m_initial_params.enable_undistortion) {/* apply undistortion */If (memcmp (M_camera.matrix, m_undistort_params.matrix, sizeof (m_camera.matrix ))! = 0 | memcmp (m_camera.distortion, m_undistort_params.distortion, sizeof (m_camera.distortion ))! = 0) {memcpy (& m_undistort_params, & m_camera, sizeof (m_camera); If (! M_undistort_data | m_undistort_data-> width! = Rgb_img-> width | m_undistort_data-> height! = Rgb_img-> height) {cvreleaseimage (& m_undistort_data);} bytes = cvcreateimage (cvsize (rgb_img-> width, rgb_img-> height), interval, 3); average (rgb_img, m_undistort_data, numbers, numbers, 1); //, 1 for version 5} cvundistort (rgb_img, numbers, m_undistort_data, 1); cvcopyimage (m_undist_img, rgb_img );}} /* Check if calibra Tion not finished and the eteon is recognized */If (m_params.calib_state = Success & chess_found & frame_time> = duration + m_params.frame_interval) {duration = frame_time; duration ++; cvxors (rgb_img, cvscalarall (255), rgb_img); If (m_params.frames_collected = m_params.frames_to_collect) {/* all frames are collect Ed. now will calibrate */calculatecameraparams (size); // call m_params.calib_state = calibstate_calibrated only once; // setdirty (true ); // qiansen}/* end calibration */}/* else point accumulation */} // all data is collected and called only once. The external parameters are only the external parameters at the moment. Void Duration: calculatecameraparams (cvsize size) {int frame; cvsize etalon_size = getetalonsize (); int etalon_points = optional * values; values (m_objectpoints, etalon_size, bytes [2]); for (frame = 1; frame <m_params.frames_collected; frame ++) {memcpy (m_objectpoints + etalon_points * frame, m_objectpoints, etalon_points * sizeof (m_objectpoints [0]);} /* Set eteon points counters */For (frame = 0; frame <m_params.frames_collected; frame ++) {m_numspoints [frame] = etalon_points;} vertex points (m_imagepoints, blocks, etalon_size, size);/* calirate Camera */rotate (values, m_numspoints, size, m_imagepoints, m_objectpoints, m_camera.distortion, m_camera.matrix, (float *) m_transvects, m_rotmatrs, 0 ); /* copy some camera parameters */m_camera.focallength [0] = m_camera.matrix [0]; Parameters [1] = m_camera.matrix [4]; m_camera.principalpoint [0] = m_camera.matrix [2]; parameters [1] = m_camera.matrix [5]; // qiansenmemcpy (values, m_transvects, sizeof (m_transvects); memcpy (values, m_rotmatrs, sizeof (m_rotmatrs ));}