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