Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
c5d4ecae
Commit
c5d4ecae
authored
Dec 15, 2015
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5588 from T-Dunker:ScheimpflugModel
parents
aee03cd5
6882c10b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
223 additions
and
20 deletions
+223
-20
opencv.bib
doc/opencv.bib
+10
-0
calib3d.hpp
modules/calib3d/include/opencv2/calib3d.hpp
+0
-0
calib3d_c.h
modules/calib3d/include/opencv2/calib3d/calib3d_c.h
+2
-0
calibration.cpp
modules/calib3d/src/calibration.cpp
+0
-0
test_cameracalibration_tilt.cpp
modules/calib3d/test/test_cameracalibration_tilt.cpp
+0
-0
matx.hpp
modules/core/include/opencv2/core/matx.hpp
+20
-0
imgproc.hpp
modules/imgproc/include/opencv2/imgproc.hpp
+28
-8
distortion_model.hpp
...gproc/include/opencv2/imgproc/detail/distortion_model.hpp
+123
-0
undistort.cpp
modules/imgproc/src/undistort.cpp
+40
-12
No files found.
doc/opencv.bib
View file @
c5d4ecae
...
...
@@ -415,6 +415,16 @@
pages = {2548--2555},
organization = {IEEE}
}
@ARTICLE{Louhichi07,
author = {Louhichi, H. and Fournel, T. and Lavest, J. M. and Ben Aissia, H.},
title = {Self-calibration of Scheimpflug cameras: an easy protocol},
year = {2007},
pages = {2616–2622},
journal = {Meas. Sci. Technol.},
volume = {18},
number = {8},
publisher = {IOP Publishing Ltd}
}
@ARTICLE{LibSVM,
author = {Chang, Chih-Chung and Lin, Chih-Jen},
title = {LIBSVM: a library for support vector machines},
...
...
modules/calib3d/include/opencv2/calib3d.hpp
View file @
c5d4ecae
This diff is collapsed.
Click to expand it.
modules/calib3d/include/opencv2/calib3d/calib3d_c.h
View file @
c5d4ecae
...
...
@@ -243,6 +243,8 @@ CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
#define CV_CALIB_RATIONAL_MODEL 16384
#define CV_CALIB_THIN_PRISM_MODEL 32768
#define CV_CALIB_FIX_S1_S2_S3_S4 65536
#define CV_CALIB_TILTED_MODEL 262144
#define CV_CALIB_FIX_TAUX_TAUY 524288
/* Finds intrinsic and extrinsic camera parameters
...
...
modules/calib3d/src/calibration.cpp
View file @
c5d4ecae
This diff is collapsed.
Click to expand it.
modules/calib3d/test/test_cameracalibration_tilt.cpp
0 → 100644
View file @
c5d4ecae
This diff is collapsed.
Click to expand it.
modules/core/include/opencv2/core/matx.hpp
View file @
c5d4ecae
...
...
@@ -114,6 +114,10 @@ public:
Matx
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
,
_Tp
v10
,
_Tp
v11
);
//!< 1x12, 2x6, 3x4, 4x3, 6x2 or 12x1 matrix
Matx
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
,
_Tp
v10
,
_Tp
v11
,
_Tp
v12
,
_Tp
v13
);
//!< 1x14, 2x7, 7x2 or 14x1 matrix
Matx
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
,
_Tp
v10
,
_Tp
v11
,
...
...
@@ -319,6 +323,7 @@ public:
Vec
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
);
//!< 8-element vector constructor
Vec
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
);
//!< 9-element vector constructor
Vec
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
);
//!< 10-element vector constructor
Vec
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
,
_Tp
v10
,
_Tp
v11
,
_Tp
v12
,
_Tp
v13
);
//!< 14-element vector constructor
explicit
Vec
(
const
_Tp
*
values
);
Vec
(
const
Vec
<
_Tp
,
cn
>&
v
);
...
...
@@ -581,6 +586,17 @@ Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp
for
(
int
i
=
12
;
i
<
channels
;
i
++
)
val
[
i
]
=
_Tp
(
0
);
}
template
<
typename
_Tp
,
int
m
,
int
n
>
inline
Matx
<
_Tp
,
m
,
n
>::
Matx
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
,
_Tp
v10
,
_Tp
v11
,
_Tp
v12
,
_Tp
v13
)
{
CV_StaticAssert
(
channels
==
14
,
"Matx should have at least 14 elements."
);
val
[
0
]
=
v0
;
val
[
1
]
=
v1
;
val
[
2
]
=
v2
;
val
[
3
]
=
v3
;
val
[
4
]
=
v4
;
val
[
5
]
=
v5
;
val
[
6
]
=
v6
;
val
[
7
]
=
v7
;
val
[
8
]
=
v8
;
val
[
9
]
=
v9
;
val
[
10
]
=
v10
;
val
[
11
]
=
v11
;
val
[
12
]
=
v12
;
val
[
13
]
=
v13
;
}
template
<
typename
_Tp
,
int
m
,
int
n
>
inline
Matx
<
_Tp
,
m
,
n
>::
Matx
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
,
_Tp
v10
,
_Tp
v11
,
_Tp
v12
,
_Tp
v13
,
_Tp
v14
,
_Tp
v15
)
{
...
...
@@ -931,6 +947,10 @@ template<typename _Tp, int cn> inline
Vec
<
_Tp
,
cn
>::
Vec
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
)
:
Matx
<
_Tp
,
cn
,
1
>
(
v0
,
v1
,
v2
,
v3
,
v4
,
v5
,
v6
,
v7
,
v8
,
v9
)
{}
template
<
typename
_Tp
,
int
cn
>
inline
Vec
<
_Tp
,
cn
>::
Vec
(
_Tp
v0
,
_Tp
v1
,
_Tp
v2
,
_Tp
v3
,
_Tp
v4
,
_Tp
v5
,
_Tp
v6
,
_Tp
v7
,
_Tp
v8
,
_Tp
v9
,
_Tp
v10
,
_Tp
v11
,
_Tp
v12
,
_Tp
v13
)
:
Matx
<
_Tp
,
cn
,
1
>
(
v0
,
v1
,
v2
,
v3
,
v4
,
v5
,
v6
,
v7
,
v8
,
v9
,
v10
,
v11
,
v12
,
v13
)
{}
template
<
typename
_Tp
,
int
cn
>
inline
Vec
<
_Tp
,
cn
>::
Vec
(
const
_Tp
*
values
)
:
Matx
<
_Tp
,
cn
,
1
>
(
values
)
{}
...
...
modules/imgproc/include/opencv2/imgproc.hpp
View file @
c5d4ecae
...
...
@@ -2598,8 +2598,8 @@ the same.
@param dst Output (corrected) image that has the same size and type as src .
@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ .
@param distCoeffs Input vector of distortion coefficients
\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6
]])\f$ of 4, 5, or 8 elements. If the vector is
NULL/empty, the zero distortion coefficients are assumed.
\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6
[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$
of 4, 5, 8, 12 or 14 elements. If the vector is
NULL/empty, the zero distortion coefficients are assumed.
@param newCameraMatrix Camera matrix of the distorted image. By default, it is the same as
cameraMatrix but you may additionally scale and shift the result by using a different matrix.
*/
...
...
@@ -2625,8 +2625,28 @@ The function actually builds the maps for the inverse mapping algorithm that is
is, for each pixel \f$(u, v)\f$ in the destination (corrected and rectified) image, the function
computes the corresponding coordinates in the source image (that is, in the original image from
camera). The following process is applied:
\f[\begin{array}{l} x \leftarrow (u - {c'}_x)/{f'}_x \\ y \leftarrow (v - {c'}_y)/{f'}_y \\{[X\,Y\,W]} ^T \leftarrow R^{-1}*[x \, y \, 1]^T \\ x' \leftarrow X/W \\ y' \leftarrow Y/W \\ x" \leftarrow x' (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + 2p_1 x' y' + p_2(r^2 + 2 x'^2) \\ y" \leftarrow y' (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' \\ map_x(u,v) \leftarrow x" f_x + c_x \\ map_y(u,v) \leftarrow y" f_y + c_y \end{array}\f]
where \f$(k_1, k_2, p_1, p_2[, k_3])\f$ are the distortion coefficients.
\f[
\begin{array}{l}
x \leftarrow (u - {c'}_x)/{f'}_x \\
y \leftarrow (v - {c'}_y)/{f'}_y \\
{[X\,Y\,W]} ^T \leftarrow R^{-1}*[x \, y \, 1]^T \\
x' \leftarrow X/W \\
y' \leftarrow Y/W \\
r^2 \leftarrow x'^2 + y'^2 \\
x'' \leftarrow x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6}
+ 2p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4\\
y'' \leftarrow y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6}
+ p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\
s\vecthree{x'''}{y'''}{1} =
\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)}
{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)}
{0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\
map_x(u,v) \leftarrow x''' f_x + c_x \\
map_y(u,v) \leftarrow y''' f_y + c_y
\end{array}
\f]
where \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$
are the distortion coefficients.
In case of a stereo camera, this function is called twice: once for each camera head, after
stereoRectify, which in its turn is called after cv::stereoCalibrate. But if the stereo camera
...
...
@@ -2639,8 +2659,8 @@ where cameraMatrix can be chosen arbitrarily.
@param cameraMatrix Input camera matrix \f$A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ .
@param distCoeffs Input vector of distortion coefficients
\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6
]])\f$ of 4, 5, or 8 elements. If the vector is
NULL/empty, the zero distortion coefficients are assumed.
\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6
[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$
of 4, 5, 8, 12 or 14 elements. If the vector is
NULL/empty, the zero distortion coefficients are assumed.
@param R Optional rectification transformation in the object space (3x3 matrix). R1 or R2 ,
computed by stereoRectify can be passed here. If the matrix is empty, the identity transformation
is assumed. In cvInitUndistortMap R assumed to be an identity matrix.
...
...
@@ -2715,8 +2735,8 @@ The function can be used for both a stereo camera head or a monocular camera (wh
transformation. If matrix P is identity or omitted, dst will contain normalized point coordinates.
@param cameraMatrix Camera matrix \f$\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ .
@param distCoeffs Input vector of distortion coefficients
\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6
]])\f$ of 4, 5, or 8 elements. If the vector is
NULL/empty, the zero distortion coefficients are assumed.
\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6
[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$
of 4, 5, 8, 12 or 14 elements. If the vector is
NULL/empty, the zero distortion coefficients are assumed.
@param R Rectification transformation in the object space (3x3 matrix). R1 or R2 computed by
cv::stereoRectify can be passed here. If the matrix is empty, the identity transformation is used.
@param P New camera matrix (3x3) or new projection matrix (3x4). P1 or P2 computed by
...
...
modules/imgproc/include/opencv2/imgproc/detail/distortion_model.hpp
0 → 100644
View file @
c5d4ecae
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP__
#define __OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP__
//! @cond IGNORED
namespace
cv
{
namespace
detail
{
/**
Computes the matrix for the projection onto a tilted image sensor
\param tauX angular parameter rotation around x-axis
\param tauY angular parameter rotation around y-axis
\param matTilt if not NULL returns the matrix
\f[
\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)}
{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)}
{0}{0}{1} R(\tau_x, \tau_y)
\f]
where
\f[
R(\tau_x, \tau_y) =
\vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)}
\vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} =
\vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)}
{0}{\cos(\tau_x)}{\sin(\tau_x)}
{\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}.
\f]
\param dMatTiltdTauX if not NULL it returns the derivative of matTilt with
respect to \f$\tau_x\f$.
\param dMatTiltdTauY if not NULL it returns the derivative of matTilt with
respect to \f$\tau_y\f$.
\param invMatTilt if not NULL it returns the inverse of matTilt
**/
template
<
typename
FLOAT
>
void
computeTiltProjectionMatrix
(
FLOAT
tauX
,
FLOAT
tauY
,
Matx
<
FLOAT
,
3
,
3
>*
matTilt
=
0
,
Matx
<
FLOAT
,
3
,
3
>*
dMatTiltdTauX
=
0
,
Matx
<
FLOAT
,
3
,
3
>*
dMatTiltdTauY
=
0
,
Matx
<
FLOAT
,
3
,
3
>*
invMatTilt
=
0
)
{
FLOAT
cTauX
=
cos
(
tauX
);
FLOAT
sTauX
=
sin
(
tauX
);
FLOAT
cTauY
=
cos
(
tauY
);
FLOAT
sTauY
=
sin
(
tauY
);
Matx
<
FLOAT
,
3
,
3
>
matRotX
=
Matx
<
FLOAT
,
3
,
3
>
(
1
,
0
,
0
,
0
,
cTauX
,
sTauX
,
0
,
-
sTauX
,
cTauX
);
Matx
<
FLOAT
,
3
,
3
>
matRotY
=
Matx
<
FLOAT
,
3
,
3
>
(
cTauY
,
0
,
-
sTauY
,
0
,
1
,
0
,
sTauY
,
0
,
cTauY
);
Matx
<
FLOAT
,
3
,
3
>
matRotXY
=
matRotY
*
matRotX
;
Matx
<
FLOAT
,
3
,
3
>
matProjZ
=
Matx
<
FLOAT
,
3
,
3
>
(
matRotXY
(
2
,
2
),
0
,
-
matRotXY
(
0
,
2
),
0
,
matRotXY
(
2
,
2
),
-
matRotXY
(
1
,
2
),
0
,
0
,
1
);
if
(
matTilt
)
{
// Matrix for trapezoidal distortion of tilted image sensor
*
matTilt
=
matProjZ
*
matRotXY
;
}
if
(
dMatTiltdTauX
)
{
// Derivative with respect to tauX
Matx
<
FLOAT
,
3
,
3
>
dMatRotXYdTauX
=
matRotY
*
Matx
<
FLOAT
,
3
,
3
>
(
0
,
0
,
0
,
0
,
-
sTauX
,
cTauX
,
0
,
-
cTauX
,
-
sTauX
);
Matx
<
FLOAT
,
3
,
3
>
dMatProjZdTauX
=
Matx
<
FLOAT
,
3
,
3
>
(
dMatRotXYdTauX
(
2
,
2
),
0
,
-
dMatRotXYdTauX
(
0
,
2
),
0
,
dMatRotXYdTauX
(
2
,
2
),
-
dMatRotXYdTauX
(
1
,
2
),
0
,
0
,
0
);
*
dMatTiltdTauX
=
(
matProjZ
*
dMatRotXYdTauX
)
+
(
dMatProjZdTauX
*
matRotXY
);
}
if
(
dMatTiltdTauY
)
{
// Derivative with respect to tauY
Matx
<
FLOAT
,
3
,
3
>
dMatRotXYdTauY
=
Matx
<
FLOAT
,
3
,
3
>
(
-
sTauY
,
0
,
-
cTauY
,
0
,
0
,
0
,
cTauY
,
0
,
-
sTauY
)
*
matRotX
;
Matx
<
FLOAT
,
3
,
3
>
dMatProjZdTauY
=
Matx
<
FLOAT
,
3
,
3
>
(
dMatRotXYdTauY
(
2
,
2
),
0
,
-
dMatRotXYdTauY
(
0
,
2
),
0
,
dMatRotXYdTauY
(
2
,
2
),
-
dMatRotXYdTauY
(
1
,
2
),
0
,
0
,
0
);
*
dMatTiltdTauY
=
(
matProjZ
*
dMatRotXYdTauY
)
+
(
dMatProjZdTauY
*
matRotXY
);
}
if
(
invMatTilt
)
{
FLOAT
inv
=
1.
/
matRotXY
(
2
,
2
);
Matx
<
FLOAT
,
3
,
3
>
invMatProjZ
=
Matx
<
FLOAT
,
3
,
3
>
(
inv
,
0
,
inv
*
matRotXY
(
0
,
2
),
0
,
inv
,
inv
*
matRotXY
(
1
,
2
),
0
,
0
,
1
);
*
invMatTilt
=
matRotXY
.
t
()
*
invMatProjZ
;
}
}
}}
// namespace detail, cv
//! @endcond
#endif // __OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP__
modules/imgproc/src/undistort.cpp
View file @
c5d4ecae
...
...
@@ -41,6 +41,7 @@
//M*/
#include "precomp.hpp"
#include "opencv2/imgproc/detail/distortion_model.hpp"
cv
::
Mat
cv
::
getDefaultNewCameraMatrix
(
InputArray
_cameraMatrix
,
Size
imgsize
,
bool
centerPrincipalPoint
)
...
...
@@ -94,7 +95,7 @@ void cv::initUndistortRectifyMap( InputArray _cameraMatrix, InputArray _distCoef
distCoeffs
=
Mat_
<
double
>
(
distCoeffs
);
else
{
distCoeffs
.
create
(
1
2
,
1
,
CV_64F
);
distCoeffs
.
create
(
1
4
,
1
,
CV_64F
);
distCoeffs
=
0.
;
}
...
...
@@ -109,7 +110,8 @@ void cv::initUndistortRectifyMap( InputArray _cameraMatrix, InputArray _distCoef
CV_Assert
(
distCoeffs
.
size
()
==
Size
(
1
,
4
)
||
distCoeffs
.
size
()
==
Size
(
4
,
1
)
||
distCoeffs
.
size
()
==
Size
(
1
,
5
)
||
distCoeffs
.
size
()
==
Size
(
5
,
1
)
||
distCoeffs
.
size
()
==
Size
(
1
,
8
)
||
distCoeffs
.
size
()
==
Size
(
8
,
1
)
||
distCoeffs
.
size
()
==
Size
(
1
,
12
)
||
distCoeffs
.
size
()
==
Size
(
12
,
1
));
distCoeffs
.
size
()
==
Size
(
1
,
12
)
||
distCoeffs
.
size
()
==
Size
(
12
,
1
)
||
distCoeffs
.
size
()
==
Size
(
1
,
14
)
||
distCoeffs
.
size
()
==
Size
(
14
,
1
));
if
(
distCoeffs
.
rows
!=
1
&&
!
distCoeffs
.
isContinuous
()
)
distCoeffs
=
distCoeffs
.
t
();
...
...
@@ -127,6 +129,12 @@ void cv::initUndistortRectifyMap( InputArray _cameraMatrix, InputArray _distCoef
double
s2
=
distCoeffs
.
cols
+
distCoeffs
.
rows
-
1
>=
12
?
distPtr
[
9
]
:
0.
;
double
s3
=
distCoeffs
.
cols
+
distCoeffs
.
rows
-
1
>=
12
?
distPtr
[
10
]
:
0.
;
double
s4
=
distCoeffs
.
cols
+
distCoeffs
.
rows
-
1
>=
12
?
distPtr
[
11
]
:
0.
;
double
tauX
=
distCoeffs
.
cols
+
distCoeffs
.
rows
-
1
>=
14
?
distPtr
[
12
]
:
0.
;
double
tauY
=
distCoeffs
.
cols
+
distCoeffs
.
rows
-
1
>=
14
?
distPtr
[
13
]
:
0.
;
// Matrix for trapezoidal distortion of tilted image sensor
cv
::
Matx33d
matTilt
=
cv
::
Matx33d
::
eye
();
cv
::
detail
::
computeTiltProjectionMatrix
(
tauX
,
tauY
,
&
matTilt
);
for
(
int
i
=
0
;
i
<
size
.
height
;
i
++
)
{
...
...
@@ -142,8 +150,12 @@ void cv::initUndistortRectifyMap( InputArray _cameraMatrix, InputArray _distCoef
double
x2
=
x
*
x
,
y2
=
y
*
y
;
double
r2
=
x2
+
y2
,
_2xy
=
2
*
x
*
y
;
double
kr
=
(
1
+
((
k3
*
r2
+
k2
)
*
r2
+
k1
)
*
r2
)
/
(
1
+
((
k6
*
r2
+
k5
)
*
r2
+
k4
)
*
r2
);
double
u
=
fx
*
(
x
*
kr
+
p1
*
_2xy
+
p2
*
(
r2
+
2
*
x2
)
+
s1
*
r2
+
s2
*
r2
*
r2
)
+
u0
;
double
v
=
fy
*
(
y
*
kr
+
p1
*
(
r2
+
2
*
y2
)
+
p2
*
_2xy
+
s3
*
r2
+
s4
*
r2
*
r2
)
+
v0
;
double
xd
=
(
x
*
kr
+
p1
*
_2xy
+
p2
*
(
r2
+
2
*
x2
)
+
s1
*
r2
+
s2
*
r2
*
r2
);
double
yd
=
(
y
*
kr
+
p1
*
(
r2
+
2
*
y2
)
+
p2
*
_2xy
+
s3
*
r2
+
s4
*
r2
*
r2
);
cv
::
Vec3d
vecTilt
=
matTilt
*
cv
::
Vec3d
(
xd
,
yd
,
1
);
double
invProj
=
vecTilt
(
2
)
?
1.
/
vecTilt
(
2
)
:
1
;
double
u
=
fx
*
invProj
*
vecTilt
(
0
)
+
u0
;
double
v
=
fy
*
invProj
*
vecTilt
(
1
)
+
v0
;
if
(
m1type
==
CV_16SC2
)
{
int
iu
=
saturate_cast
<
int
>
(
u
*
INTER_TAB_SIZE
);
...
...
@@ -266,7 +278,7 @@ void cvUndistortPoints( const CvMat* _src, CvMat* _dst, const CvMat* _cameraMatr
const
CvMat
*
_distCoeffs
,
const
CvMat
*
matR
,
const
CvMat
*
matP
)
{
double
A
[
3
][
3
],
RR
[
3
][
3
],
k
[
1
2
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
fx
,
fy
,
ifx
,
ify
,
cx
,
cy
;
double
A
[
3
][
3
],
RR
[
3
][
3
],
k
[
1
4
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
fx
,
fy
,
ifx
,
ify
,
cx
,
cy
;
CvMat
matA
=
cvMat
(
3
,
3
,
CV_64F
,
A
),
_Dk
;
CvMat
_RR
=
cvMat
(
3
,
3
,
CV_64F
,
RR
);
const
CvPoint2D32f
*
srcf
;
...
...
@@ -276,6 +288,7 @@ void cvUndistortPoints( const CvMat* _src, CvMat* _dst, const CvMat* _cameraMatr
int
stype
,
dtype
;
int
sstep
,
dstep
;
int
i
,
j
,
n
,
iters
=
1
;
cv
::
Matx33d
invMatTilt
=
cv
::
Matx33d
::
eye
();
CV_Assert
(
CV_IS_MAT
(
_src
)
&&
CV_IS_MAT
(
_dst
)
&&
(
_src
->
rows
==
1
||
_src
->
cols
==
1
)
&&
...
...
@@ -296,13 +309,16 @@ void cvUndistortPoints( const CvMat* _src, CvMat* _dst, const CvMat* _cameraMatr
(
_distCoeffs
->
rows
*
_distCoeffs
->
cols
==
4
||
_distCoeffs
->
rows
*
_distCoeffs
->
cols
==
5
||
_distCoeffs
->
rows
*
_distCoeffs
->
cols
==
8
||
_distCoeffs
->
rows
*
_distCoeffs
->
cols
==
12
));
_distCoeffs
->
rows
*
_distCoeffs
->
cols
==
12
||
_distCoeffs
->
rows
*
_distCoeffs
->
cols
==
14
));
_Dk
=
cvMat
(
_distCoeffs
->
rows
,
_distCoeffs
->
cols
,
CV_MAKETYPE
(
CV_64F
,
CV_MAT_CN
(
_distCoeffs
->
type
)),
k
);
cvConvert
(
_distCoeffs
,
&
_Dk
);
iters
=
5
;
if
(
k
[
12
]
!=
0
||
k
[
13
]
!=
0
)
cv
::
detail
::
computeTiltProjectionMatrix
<
double
>
(
k
[
12
],
k
[
13
],
NULL
,
NULL
,
NULL
,
&
invMatTilt
);
}
if
(
matR
)
...
...
@@ -354,8 +370,14 @@ void cvUndistortPoints( const CvMat* _src, CvMat* _dst, const CvMat* _cameraMatr
y
=
srcd
[
i
*
sstep
].
y
;
}
x0
=
x
=
(
x
-
cx
)
*
ifx
;
y0
=
y
=
(
y
-
cy
)
*
ify
;
x
=
(
x
-
cx
)
*
ifx
;
y
=
(
y
-
cy
)
*
ify
;
// compensate tilt distortion
cv
::
Vec3d
vecUntilt
=
invMatTilt
*
cv
::
Vec3d
(
x
,
y
,
1
);
double
invProj
=
vecUntilt
(
2
)
?
1.
/
vecUntilt
(
2
)
:
1
;
x0
=
x
=
invProj
*
vecUntilt
(
0
);
y0
=
y
=
invProj
*
vecUntilt
(
1
);
// compensate distortion iteratively
for
(
j
=
0
;
j
<
iters
;
j
++
)
...
...
@@ -500,7 +522,7 @@ float cv::initWideAngleProjMap( InputArray _cameraMatrix0, InputArray _distCoeff
OutputArray
_map1
,
OutputArray
_map2
,
int
projType
,
double
_alpha
)
{
Mat
cameraMatrix0
=
_cameraMatrix0
.
getMat
(),
distCoeffs0
=
_distCoeffs0
.
getMat
();
double
k
[
1
2
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
M
[
9
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
double
k
[
1
4
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
M
[
9
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
Mat
distCoeffs
(
distCoeffs0
.
rows
,
distCoeffs0
.
cols
,
CV_MAKETYPE
(
CV_64F
,
distCoeffs0
.
channels
()),
k
);
Mat
cameraMatrix
(
3
,
3
,
CV_64F
,
M
);
Point2f
scenter
((
float
)
cameraMatrix
.
at
<
double
>
(
0
,
2
),
(
float
)
cameraMatrix
.
at
<
double
>
(
1
,
2
));
...
...
@@ -513,7 +535,7 @@ float cv::initWideAngleProjMap( InputArray _cameraMatrix0, InputArray _distCoeff
int
ndcoeffs
=
distCoeffs0
.
cols
*
distCoeffs0
.
rows
*
distCoeffs0
.
channels
();
CV_Assert
((
distCoeffs0
.
cols
==
1
||
distCoeffs0
.
rows
==
1
)
&&
(
ndcoeffs
==
4
||
ndcoeffs
==
5
||
ndcoeffs
==
8
));
(
ndcoeffs
==
4
||
ndcoeffs
==
5
||
ndcoeffs
==
8
||
ndcoeffs
==
12
||
ndcoeffs
==
14
));
CV_Assert
(
cameraMatrix0
.
size
()
==
Size
(
3
,
3
));
distCoeffs0
.
convertTo
(
distCoeffs
,
CV_64F
);
cameraMatrix0
.
convertTo
(
cameraMatrix
,
CV_64F
);
...
...
@@ -540,6 +562,8 @@ float cv::initWideAngleProjMap( InputArray _cameraMatrix0, InputArray _distCoeff
Mat
mapxy
(
dsize
,
CV_32FC2
);
double
k1
=
k
[
0
],
k2
=
k
[
1
],
k3
=
k
[
2
],
p1
=
k
[
3
],
p2
=
k
[
4
],
k4
=
k
[
5
],
k5
=
k
[
6
],
k6
=
k
[
7
],
s1
=
k
[
8
],
s2
=
k
[
9
],
s3
=
k
[
10
],
s4
=
k
[
11
];
double
fx
=
cameraMatrix
.
at
<
double
>
(
0
,
0
),
fy
=
cameraMatrix
.
at
<
double
>
(
1
,
1
),
cx
=
scenter
.
x
,
cy
=
scenter
.
y
;
cv
::
Matx33d
matTilt
;
cv
::
detail
::
computeTiltProjectionMatrix
(
k
[
12
],
k
[
13
],
&
matTilt
);
for
(
int
y
=
0
;
y
<
dsize
.
height
;
y
++
)
{
...
...
@@ -556,8 +580,12 @@ float cv::initWideAngleProjMap( InputArray _cameraMatrix0, InputArray _distCoeff
double
x2
=
q
.
x
*
q
.
x
,
y2
=
q
.
y
*
q
.
y
;
double
r2
=
x2
+
y2
,
_2xy
=
2
*
q
.
x
*
q
.
y
;
double
kr
=
1
+
((
k3
*
r2
+
k2
)
*
r2
+
k1
)
*
r2
/
(
1
+
((
k6
*
r2
+
k5
)
*
r2
+
k4
)
*
r2
);
double
u
=
fx
*
(
q
.
x
*
kr
+
p1
*
_2xy
+
p2
*
(
r2
+
2
*
x2
)
+
s1
*
r2
+
s2
*
r2
*
r2
)
+
cx
;
double
v
=
fy
*
(
q
.
y
*
kr
+
p1
*
(
r2
+
2
*
y2
)
+
p2
*
_2xy
+
s3
*
r2
+
s4
*
r2
*
r2
)
+
cy
;
double
xd
=
(
q
.
x
*
kr
+
p1
*
_2xy
+
p2
*
(
r2
+
2
*
x2
)
+
s1
*
r2
+
s2
*
r2
*
r2
);
double
yd
=
(
q
.
y
*
kr
+
p1
*
(
r2
+
2
*
y2
)
+
p2
*
_2xy
+
s3
*
r2
+
s4
*
r2
*
r2
);
cv
::
Vec3d
vecTilt
=
matTilt
*
cv
::
Vec3d
(
xd
,
yd
,
1
);
double
invProj
=
vecTilt
(
2
)
?
1.
/
vecTilt
(
2
)
:
1
;
double
u
=
fx
*
invProj
*
vecTilt
(
0
)
+
cx
;
double
v
=
fy
*
invProj
*
vecTilt
(
1
)
+
cy
;
mxy
[
x
]
=
Point2f
((
float
)
u
,
(
float
)
v
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment