openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

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