[3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe#22443
Conversation
Add flags to set the camera intrinsic parameters as an initial guess (can allow converging to the correct camera intrinsic parameters). Add -imshow-scale flag to resize the image when displaying the results. Add -enable-k3 flag to enable or disable the estimation of the K3 distortion coefficient.
| " [-V] # use a video file, and not an image list, uses\n" | ||
| " # [input_data] string for the video file name\n" | ||
| " [-su] # show undistorted images after calibration\n" | ||
| " [-ws=<number_of_pixel>] # half of search window for cornerSubPix (11 by default)\n" |
There was a problem hiding this comment.
Parameter backported from 4.x.
| double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, | ||
| distCoeffs, rvecs, tvecs, flags|CALIB_FIX_K4|CALIB_FIX_K5); | ||
| ///*|CALIB_FIX_K3*/|CALIB_FIX_K4|CALIB_FIX_K5); | ||
| distCoeffs, rvecs, tvecs, flags | CALIB_USE_LU); |
There was a problem hiding this comment.
CALIB_USE_LU is used in OpenCV 4.x:
opencv/samples/cpp/calibration.cpp
Line 173 in 1fd45a1
Normally no need to pass CALIB_FIX_K4|CALIB_FIX_K5 (CALIB_RATIONAL_MODEL should be explicitly passed), moreover CALIB_FIX_K6 should be missing.
| aspectRatio, flags, cameraMatrix, distCoeffs, | ||
| rvecs, tvecs, reprojErrs, totalAvgErr); | ||
| printf("%s. avg reprojection error = %.2f\n", | ||
| printf("%s. avg reprojection error = %.7f\n", |
There was a problem hiding this comment.
Backport from 4.x:
opencv/samples/cpp/calibration.cpp
Line 332 in 1fd45a1
| { | ||
| Size boardSize, imageSize; | ||
| float squareSize, aspectRatio; | ||
| float squareSize, aspectRatio = 1; |
There was a problem hiding this comment.
Backport from 4.x:
opencv/samples/cpp/calibration.cpp
Line 353 in 1fd45a1
| writePoints = parser.has("op"); | ||
| writeExtrinsics = parser.has("oe"); | ||
| if (parser.has("a")) | ||
| if (parser.has("a")) { |
There was a problem hiding this comment.
Backport from 4.x:
opencv/samples/cpp/calibration.cpp
Lines 404 to 407 in 1fd45a1
| cameraId = parser.get<int>("@input_data"); | ||
| else | ||
| inputFilename = parser.get<string>("@input_data"); | ||
| int winSize = parser.get<int>("ws"); |
There was a problem hiding this comment.
Backport from 4.x:
opencv/samples/cpp/calibration.cpp
Line 421 in 1fd45a1
| if( pattern == CHESSBOARD && found) cornerSubPix( viewGray, pointbuf, Size(11,11), | ||
| Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.1 )); | ||
| if( pattern == CHESSBOARD && found) cornerSubPix( viewGray, pointbuf, Size(winSize,winSize), | ||
| Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.0001 )); |
There was a problem hiding this comment.
Backport from 4.x:
opencv/samples/cpp/calibration.cpp
Line 519 in 1fd45a1
| "{op||}{oe||}{zt||}{a||}{p||}{v||}{V||}{su||}" | ||
| "{ws|11|}" | ||
| "{fx||}{fy||}{cx||}{cy||}" | ||
| "{imshow-scale|1|}{enable-k3|1|}" |
There was a problem hiding this comment.
In 3.4, by default enable-k3=1 to keep the same behavior than before with: flags|CALIB_FIX_K4|CALIB_FIX_K5
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.
Allow passing some rough camera intrinsic parameters as an initial guess allow converging to the correct intrinsic parameters with my data.
With some
2048x2048calibration images:CALIB_FIX_K3=1, reprojection error is1.2656CALIB_FIX_K3=0, reprojection error is5.1693CALIB_FIX_K3=0and by usingfx=1400, fy=1400, cx=1024, cy=1024, reprojection error is0.39724The same images but resized to
1024x1024:CALIB_FIX_K3=1, reprojection error is0.65225CALIB_FIX_K3=0, reprojection error is2.31561CALIB_FIX_K3=0and by usingfx=700, fy=700, cx=512, cy=512, reprojection error is0.20709