2013-03-15 00:10:54 +08:00
|
|
|
#include "opencv2/core.hpp"
|
|
|
|
#include <opencv2/core/utility.hpp>
|
|
|
|
#include "opencv2/imgproc.hpp"
|
|
|
|
#include "opencv2/calib3d.hpp"
|
2014-07-04 22:48:15 +08:00
|
|
|
#include "opencv2/imgcodecs.hpp"
|
2014-07-10 22:27:32 +08:00
|
|
|
#include "opencv2/videoio.hpp"
|
2013-03-15 00:10:54 +08:00
|
|
|
#include "opencv2/highgui.hpp"
|
2012-12-21 23:58:51 +08:00
|
|
|
|
|
|
|
#include <cctype>
|
2010-06-13 11:50:29 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
#include <iostream>
|
2010-06-13 11:50:29 +08:00
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
|
2011-06-09 20:01:47 +08:00
|
|
|
const char * usage =
|
|
|
|
" \nexample command line for calibration from a live feed.\n"
|
2015-08-01 23:24:23 +08:00
|
|
|
" calibration -w=4 -h=5 -s=0.025 -o=camera.yml -op -oe\n"
|
2011-06-09 20:01:47 +08:00
|
|
|
" \n"
|
|
|
|
" example command line for calibration from a list of stored images:\n"
|
|
|
|
" imagelist_creator image_list.xml *.png\n"
|
2015-08-01 23:24:23 +08:00
|
|
|
" calibration -w=4 -h=5 -s=0.025 -o=camera.yml -op -oe image_list.xml\n"
|
2011-06-09 20:01:47 +08:00
|
|
|
" where image_list.xml is the standard OpenCV XML/YAML\n"
|
|
|
|
" use imagelist_creator to create the xml or yaml list\n"
|
|
|
|
" file consisting of the list of strings, e.g.:\n"
|
|
|
|
" \n"
|
|
|
|
"<?xml version=\"1.0\"?>\n"
|
|
|
|
"<opencv_storage>\n"
|
|
|
|
"<images>\n"
|
|
|
|
"view000.png\n"
|
|
|
|
"view001.png\n"
|
|
|
|
"<!-- view002.png -->\n"
|
|
|
|
"view003.png\n"
|
|
|
|
"view010.png\n"
|
|
|
|
"one_extra_view.jpg\n"
|
|
|
|
"</images>\n"
|
|
|
|
"</opencv_storage>\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* liveCaptureHelp =
|
|
|
|
"When the live video from camera is used as input, the following hot-keys may be used:\n"
|
|
|
|
" <ESC>, 'q' - quit the program\n"
|
|
|
|
" 'g' - start capturing images\n"
|
|
|
|
" 'u' - switch undistortion on/off\n";
|
|
|
|
|
2020-02-23 21:38:04 +08:00
|
|
|
static void help(char** argv)
|
2010-11-24 09:44:36 +08:00
|
|
|
{
|
|
|
|
printf( "This is a camera calibration sample.\n"
|
2020-02-23 21:38:04 +08:00
|
|
|
"Usage: %s\n"
|
2015-08-01 23:24:23 +08:00
|
|
|
" -w=<board_width> # the number of inner corners per one of board dimension\n"
|
|
|
|
" -h=<board_height> # the number of inner corners per another board dimension\n"
|
|
|
|
" [-pt=<pattern>] # the type of pattern: chessboard or circles' grid\n"
|
|
|
|
" [-n=<number_of_frames>] # the number of frames to use for calibration\n"
|
2010-11-24 09:44:36 +08:00
|
|
|
" # (if not specified, it will be set to the number\n"
|
|
|
|
" # of board views actually available)\n"
|
2015-08-01 23:24:23 +08:00
|
|
|
" [-d=<delay>] # a minimum delay in ms between subsequent attempts to capture a next view\n"
|
2010-11-24 09:44:36 +08:00
|
|
|
" # (used only for video capturing)\n"
|
2015-08-01 23:24:23 +08:00
|
|
|
" [-s=<squareSize>] # square size in some user-defined units (1 by default)\n"
|
|
|
|
" [-o=<out_camera_params>] # the output filename for intrinsic [and extrinsic] parameters\n"
|
2010-11-24 09:44:36 +08:00
|
|
|
" [-op] # write detected feature points\n"
|
|
|
|
" [-oe] # write extrinsic parameters\n"
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
" [-oo] # write refined 3D object points\n"
|
2010-11-24 09:44:36 +08:00
|
|
|
" [-zt] # assume zero tangential distortion\n"
|
2015-08-01 23:24:23 +08:00
|
|
|
" [-a=<aspectRatio>] # fix aspect ratio (fx/fy)\n"
|
2010-11-24 09:44:36 +08:00
|
|
|
" [-p] # fix the principal point at the center\n"
|
|
|
|
" [-v] # flip the captured images around the horizontal axis\n"
|
2010-11-30 07:16:41 +08:00
|
|
|
" [-V] # use a video file, and not an image list, uses\n"
|
|
|
|
" # [input_data] string for the video file name\n"
|
2010-11-24 09:44:36 +08:00
|
|
|
" [-su] # show undistorted images after calibration\n"
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
" [-ws=<number_of_pixel>] # Half of search window for cornerSubPix (11 by default)\n"
|
|
|
|
" [-dt=<distance>] # actual distance between top-left and top-right corners of\n"
|
|
|
|
" # the calibration grid. If this parameter is specified, a more\n"
|
|
|
|
" # accurate calibration method will be used which may be better\n"
|
|
|
|
" # with inaccurate, roughly planar target.\n"
|
2011-06-09 20:01:47 +08:00
|
|
|
" [input_data] # input data, one of the following:\n"
|
2010-11-24 09:44:36 +08:00
|
|
|
" # - text file with a list of the images of the board\n"
|
|
|
|
" # the text file can be generated with imagelist_creator\n"
|
|
|
|
" # - name of video file with a video of the board\n"
|
2011-06-09 20:01:47 +08:00
|
|
|
" # if input_data not specified, a live view from the camera is used\n"
|
2020-02-23 21:38:04 +08:00
|
|
|
"\n", argv[0] );
|
2011-06-09 20:01:47 +08:00
|
|
|
printf("\n%s",usage);
|
|
|
|
printf( "\n%s", liveCaptureHelp );
|
2010-11-24 09:44:36 +08:00
|
|
|
}
|
2010-06-13 11:50:29 +08:00
|
|
|
|
|
|
|
enum { DETECTION = 0, CAPTURING = 1, CALIBRATED = 2 };
|
2011-02-07 15:59:01 +08:00
|
|
|
enum Pattern { CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };
|
2010-06-13 11:50:29 +08:00
|
|
|
|
|
|
|
static double computeReprojectionErrors(
|
|
|
|
const vector<vector<Point3f> >& objectPoints,
|
|
|
|
const vector<vector<Point2f> >& imagePoints,
|
|
|
|
const vector<Mat>& rvecs, const vector<Mat>& tvecs,
|
|
|
|
const Mat& cameraMatrix, const Mat& distCoeffs,
|
|
|
|
vector<float>& perViewErrors )
|
|
|
|
{
|
|
|
|
vector<Point2f> imagePoints2;
|
|
|
|
int i, totalPoints = 0;
|
|
|
|
double totalErr = 0, err;
|
|
|
|
perViewErrors.resize(objectPoints.size());
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
for( i = 0; i < (int)objectPoints.size(); i++ )
|
|
|
|
{
|
|
|
|
projectPoints(Mat(objectPoints[i]), rvecs[i], tvecs[i],
|
|
|
|
cameraMatrix, distCoeffs, imagePoints2);
|
2013-04-11 23:27:54 +08:00
|
|
|
err = norm(Mat(imagePoints[i]), Mat(imagePoints2), NORM_L2);
|
2010-06-13 11:50:29 +08:00
|
|
|
int n = (int)objectPoints[i].size();
|
2010-11-30 18:27:34 +08:00
|
|
|
perViewErrors[i] = (float)std::sqrt(err*err/n);
|
|
|
|
totalErr += err*err;
|
2010-06-13 11:50:29 +08:00
|
|
|
totalPoints += n;
|
|
|
|
}
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-11-30 18:27:34 +08:00
|
|
|
return std::sqrt(totalErr/totalPoints);
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
|
|
|
|
2011-02-07 15:59:01 +08:00
|
|
|
static void calcChessboardCorners(Size boardSize, float squareSize, vector<Point3f>& corners, Pattern patternType = CHESSBOARD)
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
|
|
|
corners.resize(0);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2011-02-07 15:59:01 +08:00
|
|
|
switch(patternType)
|
|
|
|
{
|
|
|
|
case CHESSBOARD:
|
|
|
|
case CIRCLES_GRID:
|
|
|
|
for( int i = 0; i < boardSize.height; i++ )
|
|
|
|
for( int j = 0; j < boardSize.width; j++ )
|
|
|
|
corners.push_back(Point3f(float(j*squareSize),
|
|
|
|
float(i*squareSize), 0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASYMMETRIC_CIRCLES_GRID:
|
|
|
|
for( int i = 0; i < boardSize.height; i++ )
|
|
|
|
for( int j = 0; j < boardSize.width; j++ )
|
|
|
|
corners.push_back(Point3f(float((2*j + i % 2)*squareSize),
|
|
|
|
float(i*squareSize), 0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-04-11 23:27:54 +08:00
|
|
|
CV_Error(Error::StsBadArg, "Unknown pattern type\n");
|
2011-02-07 15:59:01 +08:00
|
|
|
}
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool runCalibration( vector<vector<Point2f> > imagePoints,
|
2011-02-07 15:59:01 +08:00
|
|
|
Size imageSize, Size boardSize, Pattern patternType,
|
2010-06-13 11:50:29 +08:00
|
|
|
float squareSize, float aspectRatio,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
float grid_width, bool release_object,
|
2010-06-13 11:50:29 +08:00
|
|
|
int flags, Mat& cameraMatrix, Mat& distCoeffs,
|
|
|
|
vector<Mat>& rvecs, vector<Mat>& tvecs,
|
|
|
|
vector<float>& reprojErrs,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
vector<Point3f>& newObjPoints,
|
2010-06-13 11:50:29 +08:00
|
|
|
double& totalAvgErr)
|
|
|
|
{
|
|
|
|
cameraMatrix = Mat::eye(3, 3, CV_64F);
|
2013-04-11 23:27:54 +08:00
|
|
|
if( flags & CALIB_FIX_ASPECT_RATIO )
|
2010-06-13 11:50:29 +08:00
|
|
|
cameraMatrix.at<double>(0,0) = aspectRatio;
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-09-07 23:38:48 +08:00
|
|
|
distCoeffs = Mat::zeros(8, 1, CV_64F);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
vector<vector<Point3f> > objectPoints(1);
|
2011-02-07 15:59:01 +08:00
|
|
|
calcChessboardCorners(boardSize, squareSize, objectPoints[0], patternType);
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
objectPoints[0][boardSize.width - 1].x = objectPoints[0][0].x + grid_width;
|
|
|
|
newObjPoints = objectPoints[0];
|
2010-08-18 23:35:56 +08:00
|
|
|
|
2010-11-30 07:16:41 +08:00
|
|
|
objectPoints.resize(imagePoints.size(),objectPoints[0]);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
double rms;
|
|
|
|
int iFixedPoint = -1;
|
|
|
|
if (release_object)
|
|
|
|
iFixedPoint = boardSize.width - 1;
|
|
|
|
rms = calibrateCameraRO(objectPoints, imagePoints, imageSize, iFixedPoint,
|
|
|
|
cameraMatrix, distCoeffs, rvecs, tvecs, newObjPoints,
|
|
|
|
flags | CALIB_FIX_K3 | CALIB_USE_LU);
|
2010-11-30 18:27:34 +08:00
|
|
|
printf("RMS error reported by calibrateCamera: %g\n", rms);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-07-17 18:35:17 +08:00
|
|
|
bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
if (release_object) {
|
|
|
|
cout << "New board corners: " << endl;
|
|
|
|
cout << newObjPoints[0] << endl;
|
|
|
|
cout << newObjPoints[boardSize.width - 1] << endl;
|
|
|
|
cout << newObjPoints[boardSize.width * (boardSize.height - 1)] << endl;
|
|
|
|
cout << newObjPoints.back() << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
objectPoints.clear();
|
|
|
|
objectPoints.resize(imagePoints.size(), newObjPoints);
|
2010-06-13 11:50:29 +08:00
|
|
|
totalAvgErr = computeReprojectionErrors(objectPoints, imagePoints,
|
|
|
|
rvecs, tvecs, cameraMatrix, distCoeffs, reprojErrs);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-15 21:04:17 +08:00
|
|
|
static void saveCameraParams( const string& filename,
|
2010-06-13 11:50:29 +08:00
|
|
|
Size imageSize, Size boardSize,
|
|
|
|
float squareSize, float aspectRatio, int flags,
|
|
|
|
const Mat& cameraMatrix, const Mat& distCoeffs,
|
|
|
|
const vector<Mat>& rvecs, const vector<Mat>& tvecs,
|
|
|
|
const vector<float>& reprojErrs,
|
|
|
|
const vector<vector<Point2f> >& imagePoints,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
const vector<Point3f>& newObjPoints,
|
2010-06-13 11:50:29 +08:00
|
|
|
double totalAvgErr )
|
|
|
|
{
|
|
|
|
FileStorage fs( filename, FileStorage::WRITE );
|
2012-06-15 21:04:17 +08:00
|
|
|
|
|
|
|
time_t tt;
|
|
|
|
time( &tt );
|
|
|
|
struct tm *t2 = localtime( &tt );
|
2010-06-13 11:50:29 +08:00
|
|
|
char buf[1024];
|
|
|
|
strftime( buf, sizeof(buf)-1, "%c", t2 );
|
|
|
|
|
|
|
|
fs << "calibration_time" << buf;
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
if( !rvecs.empty() || !reprojErrs.empty() )
|
|
|
|
fs << "nframes" << (int)std::max(rvecs.size(), reprojErrs.size());
|
|
|
|
fs << "image_width" << imageSize.width;
|
|
|
|
fs << "image_height" << imageSize.height;
|
|
|
|
fs << "board_width" << boardSize.width;
|
|
|
|
fs << "board_height" << boardSize.height;
|
2010-06-24 15:56:57 +08:00
|
|
|
fs << "square_size" << squareSize;
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2013-04-11 23:27:54 +08:00
|
|
|
if( flags & CALIB_FIX_ASPECT_RATIO )
|
2010-06-13 11:50:29 +08:00
|
|
|
fs << "aspectRatio" << aspectRatio;
|
|
|
|
|
|
|
|
if( flags != 0 )
|
|
|
|
{
|
|
|
|
sprintf( buf, "flags: %s%s%s%s",
|
2013-04-11 23:27:54 +08:00
|
|
|
flags & CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" : "",
|
|
|
|
flags & CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "",
|
|
|
|
flags & CALIB_FIX_PRINCIPAL_POINT ? "+fix_principal_point" : "",
|
|
|
|
flags & CALIB_ZERO_TANGENT_DIST ? "+zero_tangent_dist" : "" );
|
|
|
|
//cvWriteComment( *fs, buf, 0 );
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
fs << "flags" << flags;
|
|
|
|
|
|
|
|
fs << "camera_matrix" << cameraMatrix;
|
|
|
|
fs << "distortion_coefficients" << distCoeffs;
|
|
|
|
|
|
|
|
fs << "avg_reprojection_error" << totalAvgErr;
|
|
|
|
if( !reprojErrs.empty() )
|
|
|
|
fs << "per_view_reprojection_errors" << Mat(reprojErrs);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
if( !rvecs.empty() && !tvecs.empty() )
|
|
|
|
{
|
2011-05-30 16:01:09 +08:00
|
|
|
CV_Assert(rvecs[0].type() == tvecs[0].type());
|
|
|
|
Mat bigmat((int)rvecs.size(), 6, rvecs[0].type());
|
2010-11-26 00:55:46 +08:00
|
|
|
for( int i = 0; i < (int)rvecs.size(); i++ )
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
|
|
|
Mat r = bigmat(Range(i, i+1), Range(0,3));
|
|
|
|
Mat t = bigmat(Range(i, i+1), Range(3,6));
|
2011-05-30 16:01:09 +08:00
|
|
|
|
|
|
|
CV_Assert(rvecs[i].rows == 3 && rvecs[i].cols == 1);
|
|
|
|
CV_Assert(tvecs[i].rows == 3 && tvecs[i].cols == 1);
|
|
|
|
//*.t() is MatExpr (not Mat) so we can use assignment operator
|
|
|
|
r = rvecs[i].t();
|
|
|
|
t = tvecs[i].t();
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
2013-04-11 23:27:54 +08:00
|
|
|
//cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0 );
|
2010-06-13 11:50:29 +08:00
|
|
|
fs << "extrinsic_parameters" << bigmat;
|
|
|
|
}
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
if( !imagePoints.empty() )
|
|
|
|
{
|
2012-03-17 05:21:04 +08:00
|
|
|
Mat imagePtMat((int)imagePoints.size(), (int)imagePoints[0].size(), CV_32FC2);
|
2010-11-26 00:55:46 +08:00
|
|
|
for( int i = 0; i < (int)imagePoints.size(); i++ )
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
|
|
|
Mat r = imagePtMat.row(i).reshape(2, imagePtMat.cols);
|
2010-07-09 17:09:20 +08:00
|
|
|
Mat imgpti(imagePoints[i]);
|
|
|
|
imgpti.copyTo(r);
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
|
|
|
fs << "image_points" << imagePtMat;
|
|
|
|
}
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
|
|
|
|
if( !newObjPoints.empty() )
|
|
|
|
{
|
|
|
|
fs << "grid_points" << newObjPoints;
|
|
|
|
}
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
|
|
|
|
2010-06-14 03:08:24 +08:00
|
|
|
static bool readStringList( const string& filename, vector<string>& l )
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
|
|
|
l.resize(0);
|
2010-06-14 03:08:24 +08:00
|
|
|
FileStorage fs(filename, FileStorage::READ);
|
|
|
|
if( !fs.isOpened() )
|
2010-06-13 11:50:29 +08:00
|
|
|
return false;
|
2018-10-31 20:48:56 +08:00
|
|
|
size_t dir_pos = filename.rfind('/');
|
|
|
|
if (dir_pos == string::npos)
|
|
|
|
dir_pos = filename.rfind('\\');
|
2010-06-14 03:08:24 +08:00
|
|
|
FileNode n = fs.getFirstTopLevelNode();
|
|
|
|
if( n.type() != FileNode::SEQ )
|
|
|
|
return false;
|
|
|
|
FileNodeIterator it = n.begin(), it_end = n.end();
|
|
|
|
for( ; it != it_end; ++it )
|
2018-10-31 20:48:56 +08:00
|
|
|
{
|
|
|
|
string fname = (string)*it;
|
|
|
|
if (dir_pos != string::npos)
|
|
|
|
{
|
|
|
|
string fpath = samples::findFile(filename.substr(0, dir_pos + 1) + fname, false);
|
|
|
|
if (fpath.empty())
|
|
|
|
{
|
|
|
|
fpath = samples::findFile(fname);
|
|
|
|
}
|
|
|
|
fname = fpath;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fname = samples::findFile(fname);
|
|
|
|
}
|
|
|
|
l.push_back(fname);
|
|
|
|
}
|
2010-06-13 11:50:29 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-15 21:04:17 +08:00
|
|
|
static bool runAndSave(const string& outputFilename,
|
2010-06-13 11:50:29 +08:00
|
|
|
const vector<vector<Point2f> >& imagePoints,
|
2011-02-07 15:59:01 +08:00
|
|
|
Size imageSize, Size boardSize, Pattern patternType, float squareSize,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
float grid_width, bool release_object,
|
2010-06-13 11:50:29 +08:00
|
|
|
float aspectRatio, int flags, Mat& cameraMatrix,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
Mat& distCoeffs, bool writeExtrinsics, bool writePoints, bool writeGrid )
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
|
|
|
vector<Mat> rvecs, tvecs;
|
|
|
|
vector<float> reprojErrs;
|
|
|
|
double totalAvgErr = 0;
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
vector<Point3f> newObjPoints;
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2011-02-07 15:59:01 +08:00
|
|
|
bool ok = runCalibration(imagePoints, imageSize, boardSize, patternType, squareSize,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
aspectRatio, grid_width, release_object, flags, cameraMatrix, distCoeffs,
|
|
|
|
rvecs, tvecs, reprojErrs, newObjPoints, totalAvgErr);
|
|
|
|
printf("%s. avg reprojection error = %.7f\n",
|
2010-06-13 11:50:29 +08:00
|
|
|
ok ? "Calibration succeeded" : "Calibration failed",
|
|
|
|
totalAvgErr);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
if( ok )
|
|
|
|
saveCameraParams( outputFilename, imageSize,
|
|
|
|
boardSize, squareSize, aspectRatio,
|
|
|
|
flags, cameraMatrix, distCoeffs,
|
|
|
|
writeExtrinsics ? rvecs : vector<Mat>(),
|
|
|
|
writeExtrinsics ? tvecs : vector<Mat>(),
|
|
|
|
writeExtrinsics ? reprojErrs : vector<float>(),
|
|
|
|
writePoints ? imagePoints : vector<vector<Point2f> >(),
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
writeGrid ? newObjPoints : vector<Point3f>(),
|
2010-06-13 11:50:29 +08:00
|
|
|
totalAvgErr );
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-09 20:01:47 +08:00
|
|
|
int main( int argc, char** argv )
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
|
|
|
Size boardSize, imageSize;
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
float squareSize, aspectRatio = 1;
|
2010-06-13 11:50:29 +08:00
|
|
|
Mat cameraMatrix, distCoeffs;
|
2015-08-01 23:24:23 +08:00
|
|
|
string outputFilename;
|
|
|
|
string inputFilename = "";
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2015-08-01 23:24:23 +08:00
|
|
|
int i, nframes;
|
|
|
|
bool writeExtrinsics, writePoints;
|
2010-06-13 11:50:29 +08:00
|
|
|
bool undistortImage = false;
|
|
|
|
int flags = 0;
|
|
|
|
VideoCapture capture;
|
2015-08-01 23:24:23 +08:00
|
|
|
bool flipVertical;
|
|
|
|
bool showUndistorted;
|
|
|
|
bool videofile;
|
|
|
|
int delay;
|
2010-06-13 11:50:29 +08:00
|
|
|
clock_t prevTimestamp = 0;
|
|
|
|
int mode = DETECTION;
|
2011-06-09 20:01:47 +08:00
|
|
|
int cameraId = 0;
|
2010-06-13 11:50:29 +08:00
|
|
|
vector<vector<Point2f> > imagePoints;
|
|
|
|
vector<string> imageList;
|
2010-12-21 17:32:14 +08:00
|
|
|
Pattern pattern = CHESSBOARD;
|
2010-06-13 11:50:29 +08:00
|
|
|
|
2015-08-01 23:24:23 +08:00
|
|
|
cv::CommandLineParser parser(argc, argv,
|
|
|
|
"{help ||}{w||}{h||}{pt|chessboard|}{n|10|}{d|1000|}{s|1|}{o|out_camera_data.yml|}"
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
"{op||}{oe||}{zt||}{a||}{p||}{v||}{V||}{su||}"
|
|
|
|
"{oo||}{ws|11|}{dt||}"
|
2015-08-01 23:24:23 +08:00
|
|
|
"{@input_data|0|}");
|
|
|
|
if (parser.has("help"))
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
2020-02-23 21:38:04 +08:00
|
|
|
help(argv);
|
2011-06-09 20:01:47 +08:00
|
|
|
return 0;
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
2015-08-01 23:24:23 +08:00
|
|
|
boardSize.width = parser.get<int>( "w" );
|
|
|
|
boardSize.height = parser.get<int>( "h" );
|
|
|
|
if ( parser.has("pt") )
|
2011-06-09 16:04:33 +08:00
|
|
|
{
|
2015-08-01 23:24:23 +08:00
|
|
|
string val = parser.get<string>("pt");
|
|
|
|
if( val == "circles" )
|
|
|
|
pattern = CIRCLES_GRID;
|
|
|
|
else if( val == "acircles" )
|
|
|
|
pattern = ASYMMETRIC_CIRCLES_GRID;
|
|
|
|
else if( val == "chessboard" )
|
|
|
|
pattern = CHESSBOARD;
|
2010-06-13 11:50:29 +08:00
|
|
|
else
|
2015-08-01 23:24:23 +08:00
|
|
|
return fprintf( stderr, "Invalid pattern type: must be chessboard or circles\n" ), -1;
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
2015-08-01 23:24:23 +08:00
|
|
|
squareSize = parser.get<float>("s");
|
|
|
|
nframes = parser.get<int>("n");
|
|
|
|
delay = parser.get<int>("d");
|
|
|
|
writePoints = parser.has("op");
|
|
|
|
writeExtrinsics = parser.has("oe");
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
bool writeGrid = parser.has("oo");
|
|
|
|
if (parser.has("a")) {
|
2015-08-01 23:24:23 +08:00
|
|
|
flags |= CALIB_FIX_ASPECT_RATIO;
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
aspectRatio = parser.get<float>("a");
|
|
|
|
}
|
2015-08-01 23:24:23 +08:00
|
|
|
if ( parser.has("zt") )
|
|
|
|
flags |= CALIB_ZERO_TANGENT_DIST;
|
|
|
|
if ( parser.has("p") )
|
|
|
|
flags |= CALIB_FIX_PRINCIPAL_POINT;
|
|
|
|
flipVertical = parser.has("v");
|
|
|
|
videofile = parser.has("V");
|
|
|
|
if ( parser.has("o") )
|
|
|
|
outputFilename = parser.get<string>("o");
|
|
|
|
showUndistorted = parser.has("su");
|
|
|
|
if ( isdigit(parser.get<string>("@input_data")[0]) )
|
|
|
|
cameraId = parser.get<int>("@input_data");
|
|
|
|
else
|
|
|
|
inputFilename = parser.get<string>("@input_data");
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
int winSize = parser.get<int>("ws");
|
|
|
|
float grid_width = squareSize * (boardSize.width - 1);
|
|
|
|
bool release_object = false;
|
|
|
|
if (parser.has("dt")) {
|
|
|
|
grid_width = parser.get<float>("dt");
|
|
|
|
release_object = true;
|
|
|
|
}
|
2015-08-01 23:24:23 +08:00
|
|
|
if (!parser.check())
|
|
|
|
{
|
2020-02-23 21:38:04 +08:00
|
|
|
help(argv);
|
2015-08-01 23:24:23 +08:00
|
|
|
parser.printErrors();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ( squareSize <= 0 )
|
|
|
|
return fprintf( stderr, "Invalid board square width\n" ), -1;
|
|
|
|
if ( nframes <= 3 )
|
|
|
|
return printf("Invalid number of images\n" ), -1;
|
|
|
|
if ( aspectRatio <= 0 )
|
|
|
|
return printf( "Invalid aspect ratio\n" ), -1;
|
|
|
|
if ( delay <= 0 )
|
|
|
|
return printf( "Invalid delay\n" ), -1;
|
|
|
|
if ( boardSize.width <= 0 )
|
|
|
|
return fprintf( stderr, "Invalid board width\n" ), -1;
|
|
|
|
if ( boardSize.height <= 0 )
|
|
|
|
return fprintf( stderr, "Invalid board height\n" ), -1;
|
|
|
|
|
|
|
|
if( !inputFilename.empty() )
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
2018-10-31 20:48:56 +08:00
|
|
|
if( !videofile && readStringList(samples::findFile(inputFilename), imageList) )
|
2010-06-14 03:08:24 +08:00
|
|
|
mode = CAPTURING;
|
2012-06-15 21:04:17 +08:00
|
|
|
else
|
2018-10-31 20:48:56 +08:00
|
|
|
capture.open(samples::findFileOrKeep(inputFilename));
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
capture.open(cameraId);
|
|
|
|
|
|
|
|
if( !capture.isOpened() && imageList.empty() )
|
2011-02-13 12:09:58 +08:00
|
|
|
return fprintf( stderr, "Could not initialize video (%d) capture\n",cameraId ), -2;
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
if( !imageList.empty() )
|
|
|
|
nframes = (int)imageList.size();
|
|
|
|
|
2011-06-09 20:01:47 +08:00
|
|
|
if( capture.isOpened() )
|
|
|
|
printf( "%s", liveCaptureHelp );
|
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
namedWindow( "Image View", 1 );
|
|
|
|
|
|
|
|
for(i = 0;;i++)
|
|
|
|
{
|
|
|
|
Mat view, viewGray;
|
|
|
|
bool blink = false;
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
if( capture.isOpened() )
|
|
|
|
{
|
|
|
|
Mat view0;
|
|
|
|
capture >> view0;
|
|
|
|
view0.copyTo(view);
|
|
|
|
}
|
|
|
|
else if( i < (int)imageList.size() )
|
|
|
|
view = imread(imageList[i], 1);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2014-08-13 19:08:27 +08:00
|
|
|
if(view.empty())
|
2010-06-13 11:50:29 +08:00
|
|
|
{
|
|
|
|
if( imagePoints.size() > 0 )
|
|
|
|
runAndSave(outputFilename, imagePoints, imageSize,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
boardSize, pattern, squareSize, grid_width, release_object, aspectRatio,
|
2010-06-13 11:50:29 +08:00
|
|
|
flags, cameraMatrix, distCoeffs,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
writeExtrinsics, writePoints, writeGrid);
|
2010-06-13 11:50:29 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
imageSize = view.size();
|
|
|
|
|
|
|
|
if( flipVertical )
|
|
|
|
flip( view, view, 0 );
|
|
|
|
|
|
|
|
vector<Point2f> pointbuf;
|
2013-04-06 22:16:51 +08:00
|
|
|
cvtColor(view, viewGray, COLOR_BGR2GRAY);
|
2010-11-30 07:16:41 +08:00
|
|
|
|
2010-12-21 17:32:14 +08:00
|
|
|
bool found;
|
|
|
|
switch( pattern )
|
|
|
|
{
|
|
|
|
case CHESSBOARD:
|
|
|
|
found = findChessboardCorners( view, boardSize, pointbuf,
|
2013-04-11 23:27:54 +08:00
|
|
|
CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK | CALIB_CB_NORMALIZE_IMAGE);
|
2010-12-21 17:32:14 +08:00
|
|
|
break;
|
2011-02-07 15:59:01 +08:00
|
|
|
case CIRCLES_GRID:
|
2010-12-21 17:32:14 +08:00
|
|
|
found = findCirclesGrid( view, boardSize, pointbuf );
|
|
|
|
break;
|
2011-02-07 15:59:01 +08:00
|
|
|
case ASYMMETRIC_CIRCLES_GRID:
|
|
|
|
found = findCirclesGrid( view, boardSize, pointbuf, CALIB_CB_ASYMMETRIC_GRID );
|
|
|
|
break;
|
2010-12-21 17:32:14 +08:00
|
|
|
default:
|
|
|
|
return fprintf( stderr, "Unknown pattern type\n" ), -1;
|
|
|
|
}
|
2010-11-30 07:16:41 +08:00
|
|
|
|
|
|
|
// improve the found corners' coordinate accuracy
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
if( pattern == CHESSBOARD && found) cornerSubPix( viewGray, pointbuf, Size(winSize,winSize),
|
|
|
|
Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.0001 ));
|
2010-11-30 07:16:41 +08:00
|
|
|
|
|
|
|
if( mode == CAPTURING && found &&
|
|
|
|
(!capture.isOpened() || clock() - prevTimestamp > delay*1e-3*CLOCKS_PER_SEC) )
|
|
|
|
{
|
|
|
|
imagePoints.push_back(pointbuf);
|
|
|
|
prevTimestamp = clock();
|
|
|
|
blink = capture.isOpened();
|
|
|
|
}
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-11-30 07:16:41 +08:00
|
|
|
if(found)
|
|
|
|
drawChessboardCorners( view, boardSize, Mat(pointbuf), found );
|
2010-06-13 11:50:29 +08:00
|
|
|
|
|
|
|
string msg = mode == CAPTURING ? "100/100" :
|
|
|
|
mode == CALIBRATED ? "Calibrated" : "Press 'g' to start";
|
|
|
|
int baseLine = 0;
|
2012-06-15 21:04:17 +08:00
|
|
|
Size textSize = getTextSize(msg, 1, 1, 1, &baseLine);
|
2010-07-14 08:32:35 +08:00
|
|
|
Point textOrigin(view.cols - 2*textSize.width - 10, view.rows - 2*baseLine - 10);
|
2010-06-13 11:50:29 +08:00
|
|
|
|
|
|
|
if( mode == CAPTURING )
|
2010-07-14 08:32:35 +08:00
|
|
|
{
|
2010-11-30 07:16:41 +08:00
|
|
|
if(undistortImage)
|
|
|
|
msg = format( "%d/%d Undist", (int)imagePoints.size(), nframes );
|
2010-07-14 08:32:35 +08:00
|
|
|
else
|
2010-11-30 07:16:41 +08:00
|
|
|
msg = format( "%d/%d", (int)imagePoints.size(), nframes );
|
|
|
|
}
|
2010-06-13 11:50:29 +08:00
|
|
|
|
|
|
|
putText( view, msg, textOrigin, 1, 1,
|
|
|
|
mode != CALIBRATED ? Scalar(0,0,255) : Scalar(0,255,0));
|
|
|
|
|
|
|
|
if( blink )
|
|
|
|
bitwise_not(view, view);
|
|
|
|
|
|
|
|
if( mode == CALIBRATED && undistortImage )
|
|
|
|
{
|
|
|
|
Mat temp = view.clone();
|
|
|
|
undistort(temp, view, cameraMatrix, distCoeffs);
|
|
|
|
}
|
|
|
|
|
|
|
|
imshow("Image View", view);
|
2016-08-12 21:11:30 +08:00
|
|
|
char key = (char)waitKey(capture.isOpened() ? 50 : 500);
|
2010-06-13 11:50:29 +08:00
|
|
|
|
2016-08-12 21:11:30 +08:00
|
|
|
if( key == 27 )
|
2010-06-13 11:50:29 +08:00
|
|
|
break;
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
if( key == 'u' && mode == CALIBRATED )
|
|
|
|
undistortImage = !undistortImage;
|
|
|
|
|
|
|
|
if( capture.isOpened() && key == 'g' )
|
|
|
|
{
|
|
|
|
mode = CAPTURING;
|
|
|
|
imagePoints.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mode == CAPTURING && imagePoints.size() >= (unsigned)nframes )
|
|
|
|
{
|
|
|
|
if( runAndSave(outputFilename, imagePoints, imageSize,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
boardSize, pattern, squareSize, grid_width, release_object, aspectRatio,
|
2010-06-13 11:50:29 +08:00
|
|
|
flags, cameraMatrix, distCoeffs,
|
Merge pull request #12772 from xoox:calib-release-object
More accurate pinhole camera calibration with imperfect planar target (#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
2018-10-26 00:38:55 +08:00
|
|
|
writeExtrinsics, writePoints, writeGrid))
|
2010-06-13 11:50:29 +08:00
|
|
|
mode = CALIBRATED;
|
|
|
|
else
|
|
|
|
mode = DETECTION;
|
2010-06-14 03:08:24 +08:00
|
|
|
if( !capture.isOpened() )
|
|
|
|
break;
|
2010-06-13 11:50:29 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-09-07 23:38:48 +08:00
|
|
|
if( !capture.isOpened() && showUndistorted )
|
|
|
|
{
|
|
|
|
Mat view, rview, map1, map2;
|
|
|
|
initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(),
|
|
|
|
getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize, 0),
|
|
|
|
imageSize, CV_16SC2, map1, map2);
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-09-07 23:38:48 +08:00
|
|
|
for( i = 0; i < (int)imageList.size(); i++ )
|
|
|
|
{
|
|
|
|
view = imread(imageList[i], 1);
|
2014-08-13 19:08:27 +08:00
|
|
|
if(view.empty())
|
2010-09-07 23:38:48 +08:00
|
|
|
continue;
|
|
|
|
//undistort( view, rview, cameraMatrix, distCoeffs, cameraMatrix );
|
|
|
|
remap(view, rview, map1, map2, INTER_LINEAR);
|
|
|
|
imshow("Image View", rview);
|
2016-08-12 21:11:30 +08:00
|
|
|
char c = (char)waitKey();
|
|
|
|
if( c == 27 || c == 'q' || c == 'Q' )
|
2010-09-07 23:38:48 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-15 21:04:17 +08:00
|
|
|
|
2010-06-13 11:50:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|