OutputArray R1, OutputArray R2, OutputArray P1, OutputArray P2, OutputArray Q, int flags, const Size &newImageSize = Size(),
double balance = 0.0, double fov_scale = 1.0);
- ...
+ //! performs stereo calibration
+ static double stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2,
+ InputOutputArray K1, InputOutputArray D1, InputOutputArray K2, InputOutputArray D2, Size imageSize,
+ OutputArray R, OutputArray T, int flags = CALIB_FIX_INTRINSIC,
+ TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON));
};
Definitions:
Let P be a point in 3D of coordinates X in the world reference frame (stored in the matrix X)
-The coordinate vector of P in the camera reference frame is:
+The coordinate vector of P in the camera reference frame is:
.. class:: center
.. math::
.. math::
x = Xc_1 \\
y = Xc_2 \\
- z = Xc_3
+ z = Xc_3
-The pinehole projection coordinates of P is [a; b] where
+The pinehole projection coordinates of P is [a; b] where
.. class:: center
.. math::
-
+
a = x / z \ and \ b = y / z \\
r^2 = a^2 + b^2 \\
\theta = atan(r)
Fisheye distortion:
.. class:: center
-.. math::
-
+.. math::
+
\theta_d = \theta (1 + k_1 \theta^2 + k_2 \theta^4 + k_3 \theta^6 + k_4 \theta^8)
The distorted point coordinates are [x'; y'] where
-.. class:: center
-.. math::
-
+..class:: center
+.. math::
+
x' = (\theta_d / r) x \\
y' = (\theta_d / r) y
Finally, convertion into pixel coordinates: The final pixel coordinates vector [u; v] where:
.. class:: center
-.. math::
+.. math::
u = f_x (x' + \alpha y') + c_x \\
v = f_y yy + c_y
.. ocv:function:: void Fisheye::projectPoints(InputArray objectPoints, OutputArray imagePoints, const Affine3d& affine, InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray())
-.. ocv:function:: void Fisheye::projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec,
- InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray())
+.. ocv:function:: void Fisheye::projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec, InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray())
:param objectPoints: Array of object points, 1xN/Nx1 3-channel (or ``vector<Point3f>`` ), where N is the number of points in the view.
- :param rvec: Rotation vector. See :ocv:func:`Rodrigues` for details.
+ :param rvec: Rotation vector. See :ocv:func:`Rodrigues` for details.
:param tvec: Translation vector.
- :param K: Camera matrix :math:`K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}` .
+ :param K: Camera matrix :math:`K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}`.
:param D: Input vector of distortion coefficients :math:`(k_1, k_2, k_3, k_4)`.
:param alpha: The skew coefficient.
- :param imagePoints: Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or ``vector<Point2f>`` .
+ :param imagePoints: Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or ``vector<Point2f>``.
:param jacobian: Optional output 2Nx15 jacobian matrix of derivatives of image points with respect to components of the focal lengths, coordinates of the principal point, distortion coefficients, rotation vector, translation vector, and the skew. In the old interface different components of the jacobian are returned via different output parameters.
-The function computes projections of 3D
-points to the image plane given intrinsic and extrinsic camera
-parameters. Optionally, the function computes Jacobians - matrices
-of partial derivatives of image points coordinates (as functions of all the
-input parameters) with respect to the particular parameters, intrinsic and/or
-extrinsic.
+The function computes projections of 3D points to the image plane given intrinsic and extrinsic camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of image points coordinates (as functions of all the input parameters) with respect to the particular parameters, intrinsic and/or extrinsic.
Fisheye::distortPoints
-------------------------
Distorts 2D points using fisheye model.
.. ocv:function:: void Fisheye::distortPoints(InputArray undistorted, OutputArray distorted, InputArray K, InputArray D, double alpha = 0)
-
+
:param undistorted: Array of object points, 1xN/Nx1 2-channel (or ``vector<Point2f>`` ), where N is the number of points in the view.
:param K: Camera matrix :math:`K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}`.
-----------------------------
Undistorts 2D points using fisheye model
-.. ocv:function:: void Fisheye::undistortPoints(InputArray distorted, OutputArray undistorted,
- InputArray K, InputArray D, InputArray R = noArray(), InputArray P = noArray())
+.. ocv:function:: void Fisheye::undistortPoints(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray R = noArray(), InputArray P = noArray())
:param distorted: Array of object points, 1xN/Nx1 2-channel (or ``vector<Point2f>`` ), where N is the number of points in the view.
:param D: Input vector of distortion coefficients :math:`(k_1, k_2, k_3, k_4)`.
- :param R: Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel
+ :param R: Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel
:param P: New camera matrix (3x3) or new projection matrix (3x4)
- :param undistorted: Output array of image points, 1xN/Nx1 2-channel, or ``vector<Point2f>`` .
+ :param undistorted: Output array of image points, 1xN/Nx1 2-channel, or ``vector<Point2f>`` .
Fisheye::initUndistortRectifyMap
-------------------------------------
Computes undistortion and rectification maps for image transform by cv::remap(). If D is empty zero distortion is used, if R or P is empty identity matrixes are used.
-.. ocv:function:: void Fisheye::initUndistortRectifyMap(InputArray K, InputArray D, InputArray R, InputArray P,
- const cv::Size& size, int m1type, OutputArray map1, OutputArray map2)
+.. ocv:function:: void Fisheye::initUndistortRectifyMap(InputArray K, InputArray D, InputArray R, InputArray P, const cv::Size& size, int m1type, OutputArray map1, OutputArray map2)
:param K: Camera matrix :math:`K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}`.
:param D: Input vector of distortion coefficients :math:`(k_1, k_2, k_3, k_4)`.
- :param R: Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel
+ :param R: Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel
:param P: New camera matrix (3x3) or new projection matrix (3x4)
:param map2: The second output map.
Fisheye::undistortImage
--------------
+-----------------------
Transforms an image to compensate for fisheye lens distortion.
-.. ocv:function:: void Fisheye::undistortImage(InputArray distorted, OutputArray undistorted,
- InputArray K, InputArray D, InputArray Knew = cv::noArray(), const Size& new_size = Size())
+.. ocv:function:: void Fisheye::undistortImage(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray Knew = cv::noArray(), const Size& new_size = Size())
:param distorted: image with fisheye lens distortion.
See below the results of undistortImage.
* a\) result of :ocv:func:`undistort` of perspective camera model (all possible coefficients (k_1, k_2, k_3, k_4, k_5, k_6) of distortion were optimized under calibration)
- * b\) result of :ocv:func:`Fisheye::undistrortImage` of fisheye camera model (all possible coefficients (k_1, k_2, k_3, k_4) of fisheye distortion were optimized under calibration)
+ * b\) result of :ocv:func:`Fisheye::undistortImage` of fisheye camera model (all possible coefficients (k_1, k_2, k_3, k_4) of fisheye distortion were optimized under calibration)
* c\) original image was captured with fisheye lens
Pictures a) and b) almost the same. But if we consider points of image located far from the center of image, we can notice that on image a) these points are distorted.
----------------------------------------------------------
Estimates new camera matrix for undistortion or rectification.
-.. ocv:function:: void Fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, InputArray D, const Size &image_size, InputArray R,
- OutputArray P, double balance = 0.0, const Size& new_size = Size(), double fov_scale = 1.0);
+.. ocv:function:: void Fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, InputArray D, const Size &image_size, InputArray R, OutputArray P, double balance = 0.0, const Size& new_size = Size(), double fov_scale = 1.0)
:param K: Camera matrix :math:`K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}`.
:param D: Input vector of distortion coefficients :math:`(k_1, k_2, k_3, k_4)`.
- :param R: Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel
+ :param R: Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel
:param P: New camera matrix (3x3) or new projection matrix (3x4)
------------------------------
Stereo rectification for fisheye camera model
-.. ocv:function:: void Fisheye::stereoRectify(InputArray K1, InputArray D1, InputArray K2, InputArray D2, const Size &imageSize, InputArray R, InputArray tvec,
- OutputArray R1, OutputArray R2, OutputArray P1, OutputArray P2, OutputArray Q, int flags, const Size &newImageSize = Size(),
- double balance = 0.0, double fov_scale = 1.0)
+.. ocv:function:: void Fisheye::stereoRectify(InputArray K1, InputArray D1, InputArray K2, InputArray D2, const Size &imageSize, InputArray R, InputArray tvec, OutputArray R1, OutputArray R2, OutputArray P1, OutputArray P2, OutputArray Q, int flags, const Size &newImageSize = Size(), double balance = 0.0, double fov_scale = 1.0)
:param K1: First camera matrix.
----------------------------
Performs camera calibaration
-.. ocv:function:: double Fisheye::calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size& image_size,
- InputOutputArray K, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0,
- TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON))
+.. ocv:function:: double Fisheye::calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size& image_size, InputOutputArray K, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0, TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON))
:param objectPoints: vector of vectors of calibration pattern points in the calibration pattern coordinate space.
Fisheye::stereoCalibrate
----------------------------
-Performs stereo calibration calibaration
+Performs stereo calibration
-.. ocv:function:: double stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputOutputArray K1, InputOutputArray D1, InputOutputArray K2, InputOutputArray D2, Size imageSize, OutputArray R, OutputArray T, int flags = CALIB_FIX_INTRINSIC, TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON))
+.. ocv:function:: double Fisheye::stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputOutputArray K1, InputOutputArray D1, InputOutputArray K2, InputOutputArray D2, Size imageSize, OutputArray R, OutputArray T, int flags = CALIB_FIX_INTRINSIC, TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON))
:param objectPoints: Vector of vectors of the calibration pattern points.
-#include "opencv2/opencv.hpp"
-#include "opencv2/core/affine.hpp"
-#include "opencv2/core/affine.hpp"
#include "fisheye.hpp"
-#include "iomanip"
namespace cv { namespace
{
cv::Vec2d f, c;
if (_K.depth() == CV_32F)
{
+
Matx33f K = _K.getMat();
f = Vec2f(K(0, 0), K(1, 1));
c = Vec2f(K(0, 2), K(1, 2));
const double thresh_cond = 1e6;
const int check_cond = 1;
- size_t n_points = objectPoints.getMat(0).total();
- size_t n_images = objectPoints.total();
+ int n_points = (int)objectPoints.getMat(0).total();
+ int n_images = (int)objectPoints.total();
double change = 1;
//Init values for rotation and translation between two views
cv::Mat om_list(1, n_images, CV_64FC3), T_list(1, n_images, CV_64FC3);
cv::Mat om_ref, R_ref, T_ref, R1, R2;
- for (size_t image_idx = 0; image_idx < n_images; ++image_idx)
+ for (int image_idx = 0; image_idx < n_images; ++image_idx)
{
cv::Rodrigues(rvecs1[image_idx], R1);
cv::Rodrigues(rvecs2[image_idx], R2);
cv::Mat omr, Tr, domrdomckk, domrdTckk, domrdom, domrdT, dTrdomckk, dTrdTckk, dTrdom, dTrdT;
- for (size_t image_idx = 0; image_idx < n_images; ++image_idx)
+ for (int image_idx = 0; image_idx < n_images; ++image_idx)
{
Jkk = cv::Mat::zeros(4 * n_points, 18 + 6 * (n_images + 1), CV_64FC1);
//check goodness of sterepair
double abs_max = 0;
- for (size_t i = 0; i < 4 * n_points; i++)
+ for (int i = 0; i < 4 * n_points; i++)
{
if (fabs(ekk.at<double>(i)) > abs_max)
{
abs_max = fabs(ekk.at<double>(i));
}
}
- if (abs_max < threshold)
- {
- Jkk.copyTo(J.rowRange(image_idx * 4 * n_points, (image_idx + 1) * 4 * n_points));
- ekk.copyTo(e.rowRange(image_idx * 4 * n_points, (image_idx + 1) * 4 * n_points));
- }
- else
- {
- CV_Assert(!"Bad stereo pair");
- }
+
+ CV_Assert(abs_max < threshold); // bad stereo pair
+
+ Jkk.copyTo(J.rowRange(image_idx * 4 * n_points, (image_idx + 1) * 4 * n_points));
+ ekk.copyTo(e.rowRange(image_idx * 4 * n_points, (image_idx + 1) * 4 * n_points));
}
cv::Vec6d oldTom(Tcur[0], Tcur[1], Tcur[2], omcur[0], omcur[1], omcur[2]);
intrinsicRight = intrinsicRight + deltas.rowRange(a, a + b);
omcur = omcur + cv::Vec3d(deltas.rowRange(a + b, a + b + 3));
Tcur = Tcur + cv::Vec3d(deltas.rowRange(a + b + 3, a + b + 6));
- for (size_t image_idx = 0; image_idx < n_images; ++image_idx)
+ for (int image_idx = 0; image_idx < n_images; ++image_idx)
{
rvecs1[image_idx] = cv::Mat(cv::Mat(rvecs1[image_idx]) + deltas.rowRange(a + b + 6 + image_idx * 6, a + b + 9 + image_idx * 6));
tvecs1[image_idx] = cv::Mat(cv::Mat(tvecs1[image_idx]) + deltas.rowRange(a + b + 9 + image_idx * 6, a + b + 12 + image_idx * 6));
rms += ptr_e[i][0] * ptr_e[i][0] + ptr_e[i][1] * ptr_e[i][1];
}
- rms /= (e.total() / 2);
+ rms /= ((double)e.total() / 2.0);
rms = sqrt(rms);
_K1 = Matx33d(intrinsicLeft.f[0], intrinsicLeft.f[0] * intrinsicLeft.alpha, intrinsicLeft.c[0],
int nonzeros_cols = cv::countNonZero(cols);
Mat tmp(src.rows, nonzeros_cols, CV_64FC1);
- for (size_t i = 0, j = 0; i < cols.size(); i++)
+ for (int i = 0, j = 0; i < (int)cols.size(); i++)
{
if (cols[i])
{
int nonzeros_rows = cv::countNonZero(rows);
Mat tmp1(nonzeros_rows, nonzeros_cols, CV_64FC1);
- for (size_t i = 0, j = 0; i < rows.size(); i++)
+ for (int i = 0, j = 0; i < (int)rows.size(); i++)
{
if (rows[i])
{
if (check_cond)
{
SVD svd(JJ_kk, SVD::NO_UV);
- if (svd.w.at<double>(0) / svd.w.at<double>((int)svd.w.total() - 1) > thresh_cond)
- {
- CV_Assert(!"cond > thresh_cond");
- }
+ CV_Assert(svd.w.at<double>(0) / svd.w.at<double>((int)svd.w.total() - 1) < thresh_cond);
}
omckk.reshape(3,1).copyTo(omc.getMat().col(image_idx));
Tckk.reshape(3,1).copyTo(Tc.getMat().col(image_idx));
{
Mat JJ_kk = B.t();
SVD svd(JJ_kk, SVD::NO_UV);
- double cond = svd.w.at<double>(0) / svd.w.at<double>(svd.w.rows - 1);
- if (cond > thresh_cond)
- {
- CV_Assert(!"cond > thresh_cond");
- }
+ CV_Assert(svd.w.at<double>(0) / svd.w.at<double>(svd.w.rows - 1) < thresh_cond);
}
}
Mat ex((int)(objectPoints.getMat(0).total() * objectPoints.total()), 1, CV_64FC2);
- for (size_t image_idx = 0; image_idx < objectPoints.total(); ++image_idx)
+ for (int image_idx = 0; image_idx < (int)objectPoints.total(); ++image_idx)
{
Mat image, object;
objectPoints.getMat(image_idx).convertTo(object, CV_64FC3);
}
meanStdDev(ex, noArray(), std_err);
- std_err *= sqrt(ex.total()/(ex.total() - 1.0));
+ std_err *= sqrt((double)ex.total()/((double)ex.total() - 1.0));
Mat sigma_x;
meanStdDev(ex.reshape(1, 1), noArray(), sigma_x);
- sigma_x *= sqrt(2 * ex.total()/(2 * ex.total() - 1.0));
+ sigma_x *= sqrt(2.0 * (double)ex.total()/(2.0 * (double)ex.total() - 1.0));
Mat _JJ2_inv, ex3;
ComputeJacobians(objectPoints, imagePoints, params, omc, Tc, check_cond, thresh_cond, _JJ2_inv, ex3);
rms += ptr_ex[i][0] * ptr_ex[i][0] + ptr_ex[i][1] * ptr_ex[i][1];
}
- rms /= ex.total();
+ rms /= (double)ex.total();
rms = sqrt(rms);
}
CV_Assert(A.getMat().cols == B.getMat().rows);
CV_Assert(A.type() == CV_64FC1 && B.type() == CV_64FC1);
- size_t p = A.getMat().rows;
- size_t n = A.getMat().cols;
- size_t q = B.getMat().cols;
+ int p = A.getMat().rows;
+ int n = A.getMat().cols;
+ int q = B.getMat().cols;
dABdA.create(p * q, p * n, CV_64FC1);
dABdB.create(p * q, q * n, CV_64FC1);
dABdA.getMat() = Mat::zeros(p * q, p * n, CV_64FC1);
dABdB.getMat() = Mat::zeros(p * q, q * n, CV_64FC1);
- for (size_t i = 0; i < q; ++i)
+ for (int i = 0; i < q; ++i)
{
- for (size_t j = 0; j < p; ++j)
+ for (int j = 0; j < p; ++j)
{
- size_t ij = j + i * p;
- for (size_t k = 0; k < n; ++k)
+ int ij = j + i * p;
+ for (int k = 0; k < n; ++k)
{
- size_t kj = j + k * p;
+ int kj = j + k * p;
dABdA.getMat().at<double>(ij, kj) = B.getMat().at<double>(k, i);
}
}
}
- for (size_t i = 0; i < q; ++i)
+ for (int i = 0; i < q; ++i)
{
A.getMat().copyTo(dABdB.getMat().rowRange(i * p, i * p + p).colRange(i * n, i * n + n));
}
CV_Assert(!row.empty() && row.rows == 1);
Mat tmp = row.clone();
sort(tmp, tmp, 0);
- if (tmp.total() % 2) return tmp.at<double>(tmp.total() / 2);
- else return 0.5 *(tmp.at<double>(tmp.total() / 2) + tmp.at<double>(tmp.total() / 2 - 1));
+ if ((int)tmp.total() % 2) return tmp.at<double>((int)tmp.total() / 2);
+ else return 0.5 *(tmp.at<double>((int)tmp.total() / 2) + tmp.at<double>((int)tmp.total() / 2 - 1));
}
cv::Vec3d cv::internal::median3d(InputArray m)