Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/src/distortion_model.hpp
16354 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
22
//
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
26
//
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
29
//
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
40
//
41
//M*/
42
43
#ifndef OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP
44
#define OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP
45
46
//! @cond IGNORED
47
48
namespace cv { namespace detail {
49
/**
50
Computes the matrix for the projection onto a tilted image sensor
51
\param tauX angular parameter rotation around x-axis
52
\param tauY angular parameter rotation around y-axis
53
\param matTilt if not NULL returns the matrix
54
\f[
55
\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)}
56
{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)}
57
{0}{0}{1} R(\tau_x, \tau_y)
58
\f]
59
where
60
\f[
61
R(\tau_x, \tau_y) =
62
\vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)}
63
\vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} =
64
\vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)}
65
{0}{\cos(\tau_x)}{\sin(\tau_x)}
66
{\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}.
67
\f]
68
\param dMatTiltdTauX if not NULL it returns the derivative of matTilt with
69
respect to \f$\tau_x\f$.
70
\param dMatTiltdTauY if not NULL it returns the derivative of matTilt with
71
respect to \f$\tau_y\f$.
72
\param invMatTilt if not NULL it returns the inverse of matTilt
73
**/
74
template <typename FLOAT>
75
void computeTiltProjectionMatrix(FLOAT tauX,
76
FLOAT tauY,
77
Matx<FLOAT, 3, 3>* matTilt = 0,
78
Matx<FLOAT, 3, 3>* dMatTiltdTauX = 0,
79
Matx<FLOAT, 3, 3>* dMatTiltdTauY = 0,
80
Matx<FLOAT, 3, 3>* invMatTilt = 0)
81
{
82
FLOAT cTauX = cos(tauX);
83
FLOAT sTauX = sin(tauX);
84
FLOAT cTauY = cos(tauY);
85
FLOAT sTauY = sin(tauY);
86
Matx<FLOAT, 3, 3> matRotX = Matx<FLOAT, 3, 3>(1,0,0,0,cTauX,sTauX,0,-sTauX,cTauX);
87
Matx<FLOAT, 3, 3> matRotY = Matx<FLOAT, 3, 3>(cTauY,0,-sTauY,0,1,0,sTauY,0,cTauY);
88
Matx<FLOAT, 3, 3> matRotXY = matRotY * matRotX;
89
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);
90
if (matTilt)
91
{
92
// Matrix for trapezoidal distortion of tilted image sensor
93
*matTilt = matProjZ * matRotXY;
94
}
95
if (dMatTiltdTauX)
96
{
97
// Derivative with respect to tauX
98
Matx<FLOAT, 3, 3> dMatRotXYdTauX = matRotY * Matx<FLOAT, 3, 3>(0,0,0,0,-sTauX,cTauX,0,-cTauX,-sTauX);
99
Matx<FLOAT, 3, 3> dMatProjZdTauX = Matx<FLOAT, 3, 3>(dMatRotXYdTauX(2,2),0,-dMatRotXYdTauX(0,2),
100
0,dMatRotXYdTauX(2,2),-dMatRotXYdTauX(1,2),0,0,0);
101
*dMatTiltdTauX = (matProjZ * dMatRotXYdTauX) + (dMatProjZdTauX * matRotXY);
102
}
103
if (dMatTiltdTauY)
104
{
105
// Derivative with respect to tauY
106
Matx<FLOAT, 3, 3> dMatRotXYdTauY = Matx<FLOAT, 3, 3>(-sTauY,0,-cTauY,0,0,0,cTauY,0,-sTauY) * matRotX;
107
Matx<FLOAT, 3, 3> dMatProjZdTauY = Matx<FLOAT, 3, 3>(dMatRotXYdTauY(2,2),0,-dMatRotXYdTauY(0,2),
108
0,dMatRotXYdTauY(2,2),-dMatRotXYdTauY(1,2),0,0,0);
109
*dMatTiltdTauY = (matProjZ * dMatRotXYdTauY) + (dMatProjZdTauY * matRotXY);
110
}
111
if (invMatTilt)
112
{
113
FLOAT inv = 1./matRotXY(2,2);
114
Matx<FLOAT, 3, 3> invMatProjZ = Matx<FLOAT, 3, 3>(inv,0,inv*matRotXY(0,2),0,inv,inv*matRotXY(1,2),0,0,1);
115
*invMatTilt = matRotXY.t()*invMatProjZ;
116
}
117
}
118
}} // namespace detail, cv
119
120
121
//! @endcond
122
123
#endif // OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP
124
125