Repository navigation
More accurate pinhole camera calibration with imperfect planar target - #12772
Conversation
Add an output parameter to calculate derivatives of image points with respect to 3D coordinates of object points. The output jacobian matrix is a 2Nx3N matrix where N is the number of points. This commit introduces incompatibility to old function signature.
dpdo is a sparse matrix with only non-zero value close to major diagonal. Set it to zero because only elements near major diagonal are computed.
The output jacobian matrix of derivatives with respect to coordinates of 3D object points are added. This might break callers who assume the columns of jacobian matrix.
The test cases for projectPoints() and cvProjectPoints2() are updated to fit new function signatures.
CALIB_RELEASE_OBJECT is used to whether to release 3D coordinates of object points. The method was proposed in: K. H. Strobl and G. Hirzinger. "More Accurate Pinhole Camera Calibration with Imperfect Planar Target". In Proceedings of the IEEE International Conference on Computer Vision (ICCV 2011), 1st IEEE Workshop on Challenges and Opportunities in Robot Perception, Barcelona, Spain, pp. 1068-1075, November 2011.
It's a simple extension of the standard calibration scheme. We choose to fix the first and last object point and a user-selected fixed point.
When releasing object points, only the z coordinates of the objectPoints[0].back is fixed.
If input parameters are not qualified, then fall back to standard calibration method.
The current implementation is equal to or better than https://github.com/xoox/calibrel
CALIB_USE_QR or CALIB_USE_LU could be used for faster calibration with potentially less precise and less stable in some rare cases.
To select the calibration method of releasing object points, a command line parameter `-d=<number>` should be provided.
If the method of releasing object points is merged into OpenCV. It will be expected to be firstly released in 4.1, I think.
Epsilon of 0.1 is a bigger one. Preciser corner positions are required with calibration method of releasing object.
The hypothesis coordinates are used to indicate which distance must be measured between two specified object points.
Similar to camera_calibration tutorial application, a command line argument `-dt=<number>` is used to select the calibration method.
cvCalibrateCamera2() doesn't accept CALIB_RELEASE_OBJECT unless overload interface is added in the future.
Instead of being hard coded into source file, the calibration flags will be read from test data files. opencv_extra/testdata/cv/cameracalibration/calib?.dat must be sync with the test code.
With this new added C interface, the extended calibration method with CALIB_RELEASE_OBJECT can be called by C API.
It has been tested with new added test data in xoox:calib-release-object branch of opencv_extra.
The total number of refined 3D object coordinates is checked.
If iFixedPoint is out of rational range, fall back to standard method.
alalek
left a comment
There was a problem hiding this comment.
Thank you for the contribution!
| */ | ||
| CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera( InputArrayOfArrays objectPoints, | ||
| InputArrayOfArrays imagePoints, Size imageSize, | ||
| InputArrayOfArrays imagePoints, Size imageSize, int iFixedPoint, |
There was a problem hiding this comment.
Lets preserve existing interfaces and add new one (something like calibrateCameraReleaseObject).
iFixedPoint
Looks like, this and other new parameters imply flags += CALIB_RELEASE_OBJECT automatically.
There was a problem hiding this comment.
Lets preserve existing interfaces and add new one (something like
calibrateCameraReleaseObject).
That's my initial thought before starting. With regard to the fact that
they share most of the interface documents, I chose functions overload.
OK, I'll add new interfaces instead of overload old ones. How about the
name calibrateCameraRO? It's shorter and attractive to users, but with
the meaning less obvious. Since most part of the interface document are
shared by calibrateCamera and calibrateCameraRO,
calibrateCameraRO's interface document will be simpler with most
explanations referenced to calibrateCamera.
The standard calibration method and object-releasing calibration method
will be implemented in calibrateCameraRO, and method is chosen based
on whether iFixedPoint is within a rational range. calibrateCamera
is then made a wrapper to calibrateCameraRO.
iFixedPoint
Looks like, this and other new parameters imply
flags += CALIB_RELEASE_OBJECTautomatically.
Only iFixedPoint is input parameter, the other two are optional output
parameters. You are right. The method selection can be controlled with
iFixedPoint. I'll remove CALIB_RELEASE_OBJECT item and make the
method selection based on the value of iFixedPoint.
The method selection is based on the range of the index of fixed point. For minus values, standard calibration method will be chosen. Values in a rational range will make the object-releasing calibration method selected.
Existing interfaces are preserved and new interfaces are added. Since most part of the code base are shared, calibrateCamera() is now a wrapper function of calibrateCameraRO().
The circumstances where this method is mostly helpful are described.
| int nimages = npoints->rows * npoints->cols; | ||
| int npstep = npoints->rows == 1 ? 1 : npoints->step / CV_ELEM_SIZE(npoints->type); | ||
| int i, ni; | ||
| if( iFixedPoint > 0 ) |
There was a problem hiding this comment.
Why iFixedPoint == 0 is out of scope? Is it allowed?
The index of the 3D object point in objectPoints[0] to be fixed. Usually it is
the top-right corner point of the calibration board grid.
Index is zero-based in C++. Zero index should correspond to "top-left" corner.
There was a problem hiding this comment.
Based on the cited paper, three 3D object points are chosen to be fixed. All x, y, z coordinates of point1 and point2 are fixed, and only z of point3 is fixed. In theory, these points could be arbitrarily chosen as long as they are non-collinear. but in practice, it will deliver more accurate results to select points that are far away from each other. In the internal implementation, the first (zero index, "top-left" corner) point is already selected as point1, see line 1651-1653. And the z coordinate of the last point ("bottom-right" corner) is also fixed as point3.z, see line 1657. Users have the freedom to select point2, and "top-right" or "bottom-left" point of the calibration board grid is recommended.
By the convention in the sample C++ code, the first point ("top-left" corner) has the coordinates (0, 0, 0), "top-right" corner has (d, 0, 0) and the last point ("bottom-right" corner) has (x3, y3, 0). The accuracy of intrinsic parameters is free from these fixed points. But for accurate rvecs, tvecs and newObjPoints, the fixed coordinates must be accurate enough. In the above convention, only "d" should be accurately determined. "d" can be easily measured as the distance between the "top-left" and "top-right" corners.
There're samples on how to set the accurate "d". samples/cpp/calibration.cpp line 162 and samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp line 561.
There was a problem hiding this comment.
Thank you for detailed explanation.
Perhaps we should have documentation notes about this (specify valid / expected range of input values):
In the internal implementation, the first (zero index, "top-left" corner) point is already selected as point1
And the z coordinate of the last point ("bottom-right" corner) is also fixed as point3.z
Also add parameters checks into code like this:
CV_Assert(iFixedPoint != 0);
CV_Assert(iFixedPoint != numpoints - 1);
(not sure about second one)
There was a problem hiding this comment.
The current document for iFixedPoint has the following information:
...
According to \cite strobl2011iccv, two other points are also fixed. In
this implementation, objectPoints[0].front and objectPoints[0].back.z
are used. Accurate rvecs and tvecs are only possible if coordinates of
these three fixed points are accurate enough.
...
I'd like to update it with the following text:
@param iFixedPoint The index of the 3D object point in objectPoints[0] to be fixed. Usually
the top-right corner point of the calibration board grid is recommended. For values out of the range
[1, objectPoints[0].size()-2], calibration will fall back to standard method. According to
\cite strobl2011iccv, two other points are also fixed. In this implementation, objectPoints[0].front
and objectPoints[0].back.z are used. Accurate rvecs, tvecs and newObjPoints are only possible if
coordinates of these three fixed points are accurate enough. If standard calibration method to be
used, just set this parameter to a negative value.
Is it acceptable?
I think soft limit is a better experience for users, i.e. just falling back
to standard calibration method if iFixedPoint < 1 or iFixedPoint > numpoints - 2.
If accuracy isn't the most important thing for some users, then fallback
scheme is acceptable for them. It seems assertions are a little bit
harsh for this parameter.
There was a problem hiding this comment.
Before using, users would like to compare accuracy between old and new functions. What parameters are fit for their tasks.
I believe we should not confuse them with the same results (and silently disabled algorithm) if iFixedPoint is out of valid range for this algorithm (error message is a normal way to say that input values is out of expected range - you may use CV_Check() macros to add more accurate error message).
There was a problem hiding this comment.
I also agree that silently falling back to the classical calibrateCamera is not a good thing.
Another example that led users to report issues are the SOLVEPNP_DLS and SOLVEPNP_UPNP flags in SolvePnP function.
There was a problem hiding this comment.
OK, the confusing might arise from the fact that we are using
iFixedPoint as a switch for calibration method selection. It'd be
better to not use "fall back" words. Just tell users to select new
method, pass in the parameter in the specified range. If standard method
is demanded, set it out of the range.
If new method is requested, but the objectPoints data are not qualified,
then CV_Assert() or CV_error() is called.
Thanks for your comments. I'll add more commits for further review.
It is clarified that iFixedPoint is used as a switch to select calibration method. If input data are not qualified, exceptions will be thrown instead of fallback scheme.
iFixedPoint is now used as a switch for calibration method selection. No fallback scheme is utilized anymore. If the input data are not qualified, exceptions will be thrown.
List items of same level should be indented the same way. Otherwise they will be formatted as nested lists by Doxygen.
| - @subpage tutorial_camera_calibration | ||
|
|
||
| *Compatibility:* \> OpenCV 2.0 | ||
| *Compatibility:* \> OpenCV 4.1 |
There was a problem hiding this comment.
If this feature could be released with 4.0, the compatibility would be updated to 4.0.
|
@xoox Well done! Please update tutorial version to 4.0. Squashed commit will look like this: alalek@pr12772_r (if you want another commit message please add comment with updated version). |
alalek
left a comment
There was a problem hiding this comment.
Looks good to me! Thank you for the contribution 👍
This is a fix to the signature of static function collectCalibrationData() and clean-up for opencv#12772. Since fallback scheme in calibration method selection is not used anymore. As an input parameter, iFixedPoint should be passed by value according to the OpenCV coding style guide.
See opencv/opencv#12772 and https://elib.dlr.de/71888/1/strobl_2011iccv.pdf for why this is a good idea. It changes how we should take our calibration images though. See https://www.dlr.de/rm/en/desktopdefault.aspx/tabid-3925/6084_read-9196/ for tips on that
More accurate pinhole camera calibration with imperfect planar target (opencv#12772) 43 commits: * Add derivatives with respect to object points Add an output parameter to calculate derivatives of image points with respect to 3D coordinates of object points. The output jacobian matrix is a 2Nx3N matrix where N is the number of points. This commit introduces incompatibility to old function signature. * Set zero for dpdo matrix before using dpdo is a sparse matrix with only non-zero value close to major diagonal. Set it to zero because only elements near major diagonal are computed. * Add jacobian columns to projectPoints() The output jacobian matrix of derivatives with respect to coordinates of 3D object points are added. This might break callers who assume the columns of jacobian matrix. * Adapt test code to updated project functions The test cases for projectPoints() and cvProjectPoints2() are updated to fit new function signatures. * Add accuracy test code for dpdo * Add badarg test for dpdo * Add new enum item for new calibration method CALIB_RELEASE_OBJECT is used to whether to release 3D coordinates of object points. The method was proposed in: K. H. Strobl and G. Hirzinger. "More Accurate Pinhole Camera Calibration with Imperfect Planar Target". In Proceedings of the IEEE International Conference on Computer Vision (ICCV 2011), 1st IEEE Workshop on Challenges and Opportunities in Robot Perception, Barcelona, Spain, pp. 1068-1075, November 2011. * Add releasing object method into internal function It's a simple extension of the standard calibration scheme. We choose to fix the first and last object point and a user-selected fixed point. * Add interfaces for extended calibration method * Refine document for calibrateCamera() When releasing object points, only the z coordinates of the objectPoints[0].back is fixed. * Add link to strobl2011iccv paper * Improve documentation for calibrateCamera() * Add implementations of wrapping calibrateCamera() * Add checking for params of new calibration method If input parameters are not qualified, then fall back to standard calibration method. * Add camera calibration method of releasing object The current implementation is equal to or better than https://github.com/xoox/calibrel * Update doc for CALIB_RELEASE_OBJECT CALIB_USE_QR or CALIB_USE_LU could be used for faster calibration with potentially less precise and less stable in some rare cases. * Add RELEASE_OBJECT calibration to tutorial code To select the calibration method of releasing object points, a command line parameter `-d=<number>` should be provided. * Update tutorial doc for camera_calibration If the method of releasing object points is merged into OpenCV. It will be expected to be firstly released in 4.1, I think. * Reduce epsilon for cornerSubPix() Epsilon of 0.1 is a bigger one. Preciser corner positions are required with calibration method of releasing object. * Refine camera calibration tutorial The hypothesis coordinates are used to indicate which distance must be measured between two specified object points. * Update sample calibration code method selection Similar to camera_calibration tutorial application, a command line argument `-dt=<number>` is used to select the calibration method. * Add guard to flags of cvCalibrateCamera2() cvCalibrateCamera2() doesn't accept CALIB_RELEASE_OBJECT unless overload interface is added in the future. * Simplify fallback when iFixedPoint is out of range * Refactor projectPoints() to keep compatibilities * Fix arg string "Bad rvecs header" * Read calibration flags from test data files Instead of being hard coded into source file, the calibration flags will be read from test data files. opencv_extra/testdata/cv/cameracalibration/calib?.dat must be sync with the test code. * Add new C interface of cvCalibrateCamera4() With this new added C interface, the extended calibration method with CALIB_RELEASE_OBJECT can be called by C API. * Add regression test of extended calibration method It has been tested with new added test data in xoox:calib-release-object branch of opencv_extra. * Fix assertion in test_cameracalibration.cpp The total number of refined 3D object coordinates is checked. * Add checker for iFixedPoint in cvCalibrateCamera4 If iFixedPoint is out of rational range, fall back to standard method. * Fix documentation for overloaded calibrateCamera() * Remove calibration flag of CALIB_RELEASE_OBJECT The method selection is based on the range of the index of fixed point. For minus values, standard calibration method will be chosen. Values in a rational range will make the object-releasing calibration method selected. * Use new interfaces instead of function overload Existing interfaces are preserved and new interfaces are added. Since most part of the code base are shared, calibrateCamera() is now a wrapper function of calibrateCameraRO(). * Fix exported name of calibrateCameraRO() * Update documentation for calibrateCameraRO() The circumstances where this method is mostly helpful are described. * Add note on the rigidity of the calibration target * Update documentation for calibrateCameraRO() It is clarified that iFixedPoint is used as a switch to select calibration method. If input data are not qualified, exceptions will be thrown instead of fallback scheme. * Clarify iFixedPoint as switch and remove fallback iFixedPoint is now used as a switch for calibration method selection. No fallback scheme is utilized anymore. If the input data are not qualified, exceptions will be thrown. * Add badarg test for object-releasing method * Fix document format of sample list List items of same level should be indented the same way. Otherwise they will be formatted as nested lists by Doxygen. * Add brief intro for objectPoints and imagePoints * Sync tutorial to sample calibration code * Update tutorial compatibility version to 4.0
This is a fix to the signature of static function collectCalibrationData() and clean-up for opencv#12772. Since fallback scheme in calibration method selection is not used anymore. As an input parameter, iFixedPoint should be passed by value according to the OpenCV coding style guide.
More accurate pinhole camera calibration with imperfect planar target (opencv#12772) 43 commits: * Add derivatives with respect to object points Add an output parameter to calculate derivatives of image points with respect to 3D coordinates of object points. The output jacobian matrix is a 2Nx3N matrix where N is the number of points. This commit introduces incompatibility to old function signature. * Set zero for dpdo matrix before using dpdo is a sparse matrix with only non-zero value close to major diagonal. Set it to zero because only elements near major diagonal are computed. * Add jacobian columns to projectPoints() The output jacobian matrix of derivatives with respect to coordinates of 3D object points are added. This might break callers who assume the columns of jacobian matrix. * Adapt test code to updated project functions The test cases for projectPoints() and cvProjectPoints2() are updated to fit new function signatures. * Add accuracy test code for dpdo * Add badarg test for dpdo * Add new enum item for new calibration method CALIB_RELEASE_OBJECT is used to whether to release 3D coordinates of object points. The method was proposed in: K. H. Strobl and G. Hirzinger. "More Accurate Pinhole Camera Calibration with Imperfect Planar Target". In Proceedings of the IEEE International Conference on Computer Vision (ICCV 2011), 1st IEEE Workshop on Challenges and Opportunities in Robot Perception, Barcelona, Spain, pp. 1068-1075, November 2011. * Add releasing object method into internal function It's a simple extension of the standard calibration scheme. We choose to fix the first and last object point and a user-selected fixed point. * Add interfaces for extended calibration method * Refine document for calibrateCamera() When releasing object points, only the z coordinates of the objectPoints[0].back is fixed. * Add link to strobl2011iccv paper * Improve documentation for calibrateCamera() * Add implementations of wrapping calibrateCamera() * Add checking for params of new calibration method If input parameters are not qualified, then fall back to standard calibration method. * Add camera calibration method of releasing object The current implementation is equal to or better than https://github.com/xoox/calibrel * Update doc for CALIB_RELEASE_OBJECT CALIB_USE_QR or CALIB_USE_LU could be used for faster calibration with potentially less precise and less stable in some rare cases. * Add RELEASE_OBJECT calibration to tutorial code To select the calibration method of releasing object points, a command line parameter `-d=<number>` should be provided. * Update tutorial doc for camera_calibration If the method of releasing object points is merged into OpenCV. It will be expected to be firstly released in 4.1, I think. * Reduce epsilon for cornerSubPix() Epsilon of 0.1 is a bigger one. Preciser corner positions are required with calibration method of releasing object. * Refine camera calibration tutorial The hypothesis coordinates are used to indicate which distance must be measured between two specified object points. * Update sample calibration code method selection Similar to camera_calibration tutorial application, a command line argument `-dt=<number>` is used to select the calibration method. * Add guard to flags of cvCalibrateCamera2() cvCalibrateCamera2() doesn't accept CALIB_RELEASE_OBJECT unless overload interface is added in the future. * Simplify fallback when iFixedPoint is out of range * Refactor projectPoints() to keep compatibilities * Fix arg string "Bad rvecs header" * Read calibration flags from test data files Instead of being hard coded into source file, the calibration flags will be read from test data files. opencv_extra/testdata/cv/cameracalibration/calib?.dat must be sync with the test code. * Add new C interface of cvCalibrateCamera4() With this new added C interface, the extended calibration method with CALIB_RELEASE_OBJECT can be called by C API. * Add regression test of extended calibration method It has been tested with new added test data in xoox:calib-release-object branch of opencv_extra. * Fix assertion in test_cameracalibration.cpp The total number of refined 3D object coordinates is checked. * Add checker for iFixedPoint in cvCalibrateCamera4 If iFixedPoint is out of rational range, fall back to standard method. * Fix documentation for overloaded calibrateCamera() * Remove calibration flag of CALIB_RELEASE_OBJECT The method selection is based on the range of the index of fixed point. For minus values, standard calibration method will be chosen. Values in a rational range will make the object-releasing calibration method selected. * Use new interfaces instead of function overload Existing interfaces are preserved and new interfaces are added. Since most part of the code base are shared, calibrateCamera() is now a wrapper function of calibrateCameraRO(). * Fix exported name of calibrateCameraRO() * Update documentation for calibrateCameraRO() The circumstances where this method is mostly helpful are described. * Add note on the rigidity of the calibration target * Update documentation for calibrateCameraRO() It is clarified that iFixedPoint is used as a switch to select calibration method. If input data are not qualified, exceptions will be thrown instead of fallback scheme. * Clarify iFixedPoint as switch and remove fallback iFixedPoint is now used as a switch for calibration method selection. No fallback scheme is utilized anymore. If the input data are not qualified, exceptions will be thrown. * Add badarg test for object-releasing method * Fix document format of sample list List items of same level should be indented the same way. Otherwise they will be formatted as nested lists by Doxygen. * Add brief intro for objectPoints and imagePoints * Sync tutorial to sample calibration code * Update tutorial compatibility version to 4.0
This is a fix to the signature of static function collectCalibrationData() and clean-up for opencv#12772. Since fallback scheme in calibration method selection is not used anymore. As an input parameter, iFixedPoint should be passed by value according to the OpenCV coding style guide.
Merge with extra: opencv/opencv_extra#528
Problem to be solved
Checkerboard patterns on paper using off-the-shelf printers are the most
convenient calibration targets. And these printed patterns stuck on
roughly planar surfaces are the mostly used calibration structure world
wide. But in most cases printed patterns are inaccurate and the sticking
surfaces are not perfectly planar.
For example, the square size of the above chessboard is set to 15mm
in the PDF file. The printed paper was pasted to a glass panel which was
not so perfect planar structure. We measured the distances between
combinations of p1, p2, p3 and p4 with a vernier caliper of 0.02mm
resolution (The uncertainties of the measurements are probably larger
than 0.1mm I think). The result are compared to hypothesis values. The
maximum error is around 1mm (about 3~4 pixels in our application).
The inaccuracy of the checkerboard causes less precise and less stable
estimation of camera intrinsic parameters.
New method integrated
This PR integrates an extension to the standard pinhole camera
calibration method in OpenCV. The method was proposed in the paper:
Klaus H. Strobl and Gerd Hirzinger. More accurate pinhole camera
calibration with imperfect planar target. In 2011 IEEE International
Conference on Computer Vision (ICCV), pages 1068-1075, Barcelona, Spain,
Nov 2011. IEEE. And it was included in the camera calibration toolbox
DLR CalDe and DLR CalLab.
In many common cases with inaccurate calibration plates, this method can
dramatically improve the precision of the estimated camera parameters.
In principle the method releases 3D coordinates of the object structure
when performing non-linear Levenberg-Marquardt optimization. The current
calibration process can be easily reinforced by adding extra
optimization parameters and extending the Jacobian matrix.
Before trying to integrate it into OpenCV, a standalone project
calibrel was created to reimplement
and validate this method. The results were double-checked with CalLab.
In addition to validating with stereo cameras in the paper, we also
evaluated its precision using measured distances.
When preparing to add test code for this new method, the existing data
for regression test is reordered where the object points and image
feature points can be also used by the new calibration method (with
calibration flags changed). The results with releasing object points are
so diverse to standard methods. It may be caused by bad set of images or
inaccuracy of feature points. The comparison is shown in the following
table and further discussions are needed. Could anyone do some
comparisons between these two methods with regard to the same set of
images of an accurate checkerboard? Both cameras with larger and
smaller distortions are needed. Experiments can be conducted with
samples/cpp/calibration.cppandsamples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cppin this PR.
I have no information of the camera, lens and checkerboard used in
calib1.dat. But after drawing its feature points on images, it seems thoseimages are probably not good candidates for camera calibration. Please
check the images on this PR opencv/opencv_extra#528. Also see Dr. Strobl's
comments on good calibration images: xoox/calibrel#1 (comment)
If this PR is going to be squashed, it'd be better full commit messages
are kept instead of commit titles only, for that there are useful
information in the full commit messages.
In the similar fashion, this method can also be included into
stereoCalibrate(). But the speed is expected much slower. If theintrinsic parameters can be estimated with high accuracy for each of the
cameras individually using
calibrateCamera(), it is recommended to doso and then pass CALIB_FIX_INTRINSIC flag to
stereoCalibrate()alongwith the computed intrinsic parameters. However, I'd integrate this
method into
stereoCalibrate()if the necessity is confirmed.This pull request changes
cvCalibrateCamera4()
A new C interface is added which supports both standard calibration
method and the extended new calibration method.
calibrateCameraRO()
New C++ interfaces are added which support both standard calibration
method and the extended new calibration method.
Regression test code
The test code is modified to empower tests of both standard calibration
method and the new added one. The updated test data can be found here:
https://github.com/xoox/opencv_extra/tree/calib-release-object A PR opencv/opencv_extra#528 was
also created for the new test data.
Sample calibration code
Two calibration samples are updated to support both standard
calibration method and the extended new calibration method.
In conclusion, this PR is just a very straightforward extension to
current standard calibration code.