-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Use input rotation and translation in camera calibration #20219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.x
Are you sure you want to change the base?
Use input rotation and translation in camera calibration #20219
Conversation
c87d30f
to
abe2206
Compare
32cbf34
to
4b1eaa1
Compare
4b1eaa1
to
4c57506
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution!
space. Due to its duality, this tuple is equivalent to the position of the calibration pattern with | ||
respect to the camera coordinate space. If @ref CALIB_FIX_EXTRINSIC is specified, rotation | ||
matrices and translation vectors equal in size to the number of images must be initialized and will | ||
be used for calibration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be used for calibration
This contradicts with OutputArrayOfArrays rvecs
parameter declaration which is critical for bindings generators (Python/Java/etc code).
Perhaps we should make dedicated overload (at least in public headers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alalek . I see 4 api versions of calibrate camera in calib3d.hpp:
- calibrateCameraExtended
- calibrateCamera
- calibrateCameraROExtended
- calibrateCameraRO
Here's an initial proposal for the overload:
- calibrateCameraFEExtended: Based on calibrateCameraROExtended but with rvecs and tvecs as InputOutputArrayOfArrays
- calibrateCameraFE: Based on calibrateCameraRO but with rvecs and tvecs as InputOutputArrayOfArrays
The "FE" stands for "FixedExtrinsics". This is similar to how calibrateCameraROExtended and calibrateCameraRO are declared and how "RO" stands for "ReleasingObject". I selected InputOutputArrayOfArrays instead of InputArrayOfArrays in case one day we want the user to be able to pass in an initial guess for extrinsics that will be optimized by the LM solver.
Basing the extension on calibrateCameraRO also allows the method of releasing object to be combined with fixed extrinsics.
What's your opinion?
Hi @alalek what about this? |
Thanks for the reminder. I'll propose a new api soon. |
14f3a00
to
32942b2
Compare
cbf30bf
to
c452d97
Compare
c7adc4c
to
180fb9c
Compare
180fb9c
to
eb913c5
Compare
InputOutputArray cameraMatrix, InputOutputArray distCoeffs, | ||
InputOutputArrayOfArrays rvecs, InputOutputArrayOfArrays tvecs, | ||
int flags = 0, TermCriteria criteria = TermCriteria( | ||
TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alalek @asmorkalov I propose a dedicated api to support passing in extrinsics. Can you see if you're agreeable with the api?
The extrinsics type is InputOutputArrayOfArrays
, which allows OpenCV to modify it in case we want to support an initial guess for the extrinsics in the future.
Hi, any news about this? |
Hi everyone is there anything I can do about this pull request? |
@@ -517,6 +517,7 @@ enum { CALIB_NINTRINSIC = 18, | |||
CALIB_FIX_TAUX_TAUY = 0x80000, | |||
CALIB_USE_QR = 0x100000, //!< use QR instead of SVD decomposition for solving. Faster but potentially less precise | |||
CALIB_FIX_TANGENT_DIST = 0x200000, | |||
CALIB_FIX_EXTRINSIC = (1 << 23), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is CALIB_RECOMPUTE_EXTRINSIC
for fisheye. Also need to align with new flags in 5.x.
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.
Description
Add a flag
CALIB_FIX_EXTRINSIC
tocalibrateCamera
that allows users to fix input rotation and translation parameters during calibration. Unit tests are added to verify calibration results and format of extrinsic arguments . This PR is a response to #15781.FAQ
The requester in #15781 asked for separate flags to fix rotation and translation. Why does this PR only allow fixing rotation and translation together?
When testing calibration results with
calib1.data
andcalib2.data
, I noticed the LM solver struggles to arrive at a good calibration result when only rotation is fixed but not when rotation and translation are fixed.The reason is opencv performs calibration with Zhang's method, which estimates camera matrix first and translation matrices from camera matrix after. This forces the LM solver to optimize both the camera and translation matrices, which it's unable to do as the initial guess for the camera and translation matrices are a poor fit for the input rotation matrix. Likewise when only translation is fixed.
In contrast, when fixing both rotation and translation, the LM solver only has to optimize the camera matrix and is able to arrive at a good calibration result.