Skip to content

[3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe#22443

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
catree:feat_calibrate_camera_exe_initial_guess
Aug 31, 2022
Merged

[3.4] Add flag to pass initial guess for camera intrinsics into the calibration exe#22443
opencv-pushbot merged 1 commit intoopencv:3.4from
catree:feat_calibrate_camera_exe_initial_guess

Conversation

@catree
Copy link
Copy Markdown
Contributor

@catree catree commented Aug 29, 2022

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Allow passing some rough camera intrinsic parameters as an initial guess allow converging to the correct intrinsic parameters with my data.

With some 2048x2048 calibration images:

  • with CALIB_FIX_K3=1, reprojection error is 1.2656
  • with CALIB_FIX_K3=0, reprojection error is 5.1693
  • with CALIB_FIX_K3=0 and by using fx=1400, fy=1400, cx=1024, cy=1024, reprojection error is 0.39724

The same images but resized to 1024x1024:

  • with CALIB_FIX_K3=1, reprojection error is 0.65225
  • with CALIB_FIX_K3=0, reprojection error is 2.31561
  • with CALIB_FIX_K3=0 and by using fx=700, fy=700, cx=512, cy=512, reprojection error is 0.20709

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"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CALIB_USE_LU is used in OpenCV 4.x:

flags | CALIB_FIX_K3 | CALIB_USE_LU);

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",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport from 4.x:

printf("%s. avg reprojection error = %.7f\n",

{
Size boardSize, imageSize;
float squareSize, aspectRatio;
float squareSize, aspectRatio = 1;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport from 4.x:

float squareSize, aspectRatio = 1;

writePoints = parser.has("op");
writeExtrinsics = parser.has("oe");
if (parser.has("a"))
if (parser.has("a")) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport from 4.x:

if (parser.has("a")) {
flags |= CALIB_FIX_ASPECT_RATIO;
aspectRatio = parser.get<float>("a");
}

cameraId = parser.get<int>("@input_data");
else
inputFilename = parser.get<string>("@input_data");
int winSize = parser.get<int>("ws");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport from 4.x:

int winSize = parser.get<int>("ws");

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 ));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport from 4.x:

Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.0001 ));

"{op||}{oe||}{zt||}{a||}{p||}{v||}{V||}{su||}"
"{ws|11|}"
"{fx||}{fy||}{cx||}{cy||}"
"{imshow-scale|1|}{enable-k3|1|}"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 3.4, by default enable-k3=1 to keep the same behavior than before with: flags|CALIB_FIX_K4|CALIB_FIX_K5

Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@opencv-pushbot opencv-pushbot merged commit 7834a46 into opencv:3.4 Aug 31, 2022
@alalek alalek mentioned this pull request Oct 15, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants