Path: blob/master/modules/calib3d/src/distortion_model.hpp
16354 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2009, Willow Garage Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistribution's of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistribution's in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// warranties of merchantability and fitness for a particular purpose are disclaimed.32// In no event shall the Intel Corporation or contributors be liable for any direct,33// indirect, incidental, special, exemplary, or consequential damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#ifndef OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP43#define OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP4445//! @cond IGNORED4647namespace cv { namespace detail {48/**49Computes the matrix for the projection onto a tilted image sensor50\param tauX angular parameter rotation around x-axis51\param tauY angular parameter rotation around y-axis52\param matTilt if not NULL returns the matrix53\f[54\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)}55{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)}56{0}{0}{1} R(\tau_x, \tau_y)57\f]58where59\f[60R(\tau_x, \tau_y) =61\vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)}62\vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} =63\vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)}64{0}{\cos(\tau_x)}{\sin(\tau_x)}65{\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}.66\f]67\param dMatTiltdTauX if not NULL it returns the derivative of matTilt with68respect to \f$\tau_x\f$.69\param dMatTiltdTauY if not NULL it returns the derivative of matTilt with70respect to \f$\tau_y\f$.71\param invMatTilt if not NULL it returns the inverse of matTilt72**/73template <typename FLOAT>74void computeTiltProjectionMatrix(FLOAT tauX,75FLOAT tauY,76Matx<FLOAT, 3, 3>* matTilt = 0,77Matx<FLOAT, 3, 3>* dMatTiltdTauX = 0,78Matx<FLOAT, 3, 3>* dMatTiltdTauY = 0,79Matx<FLOAT, 3, 3>* invMatTilt = 0)80{81FLOAT cTauX = cos(tauX);82FLOAT sTauX = sin(tauX);83FLOAT cTauY = cos(tauY);84FLOAT sTauY = sin(tauY);85Matx<FLOAT, 3, 3> matRotX = Matx<FLOAT, 3, 3>(1,0,0,0,cTauX,sTauX,0,-sTauX,cTauX);86Matx<FLOAT, 3, 3> matRotY = Matx<FLOAT, 3, 3>(cTauY,0,-sTauY,0,1,0,sTauY,0,cTauY);87Matx<FLOAT, 3, 3> matRotXY = matRotY * matRotX;88Matx<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);89if (matTilt)90{91// Matrix for trapezoidal distortion of tilted image sensor92*matTilt = matProjZ * matRotXY;93}94if (dMatTiltdTauX)95{96// Derivative with respect to tauX97Matx<FLOAT, 3, 3> dMatRotXYdTauX = matRotY * Matx<FLOAT, 3, 3>(0,0,0,0,-sTauX,cTauX,0,-cTauX,-sTauX);98Matx<FLOAT, 3, 3> dMatProjZdTauX = Matx<FLOAT, 3, 3>(dMatRotXYdTauX(2,2),0,-dMatRotXYdTauX(0,2),990,dMatRotXYdTauX(2,2),-dMatRotXYdTauX(1,2),0,0,0);100*dMatTiltdTauX = (matProjZ * dMatRotXYdTauX) + (dMatProjZdTauX * matRotXY);101}102if (dMatTiltdTauY)103{104// Derivative with respect to tauY105Matx<FLOAT, 3, 3> dMatRotXYdTauY = Matx<FLOAT, 3, 3>(-sTauY,0,-cTauY,0,0,0,cTauY,0,-sTauY) * matRotX;106Matx<FLOAT, 3, 3> dMatProjZdTauY = Matx<FLOAT, 3, 3>(dMatRotXYdTauY(2,2),0,-dMatRotXYdTauY(0,2),1070,dMatRotXYdTauY(2,2),-dMatRotXYdTauY(1,2),0,0,0);108*dMatTiltdTauY = (matProjZ * dMatRotXYdTauY) + (dMatProjZdTauY * matRotXY);109}110if (invMatTilt)111{112FLOAT inv = 1./matRotXY(2,2);113Matx<FLOAT, 3, 3> invMatProjZ = Matx<FLOAT, 3, 3>(inv,0,inv*matRotXY(0,2),0,inv,inv*matRotXY(1,2),0,0,1);114*invMatTilt = matRotXY.t()*invMatProjZ;115}116}117}} // namespace detail, cv118119120//! @endcond121122#endif // OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP123124125