RPP.h
Go to the documentation of this file.
00001 /*
00002 This is a C++ port using OpenCV of the Robust Pose Estimation from a Planar Target algorithm by Gerald Schweighofer and Axel Pinz.
00003 
00004 It is a line by line port of the Matlab code at
00005 
00006 http://www.emt.tugraz.at/~pinz/code/
00007 
00008 I have no idea what their license is, if any. I'll make my code BSD for now unless I later find they have a more restrictive one.
00009 */
00010 
00011 /*
00012 Copyright 2011 Nghia Ho. All rights reserved.
00013 
00014 Redistribution and use in source and binary forms, with or without modification, are
00015 permitted provided that the following conditions are met:
00016 
00017    1. Redistributions of source code must retain the above copyright notice, this list of
00018       conditions and the following disclaimer.
00019 
00020    2. Redistributions in binary form must reproduce the above copyright notice, this list
00021       of conditions and the following disclaimer in the documentation and/or other materials
00022       provided with the distribution.
00023 
00024 THIS SOFTWARE IS PROVIDED BY NGHIA HO ''AS IS'' AND ANY EXPRESS OR IMPLIED
00025 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00026 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NGHIA HO OR
00027 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00030 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00032 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 The views and conclusions contained in the software and documentation are those of the
00035 authors and should not be interpreted as representing official policies, either expressed
00036 or implied, of Nghia Ho.
00037 */
00038 
00039 #ifndef __RPP_H__
00040 #define __RPP_H__
00041 
00042 #include <opencv2/core/core.hpp>
00043 #include <vector>
00044 #include "Rpoly.h"
00045 
00046 namespace RPP
00047 {
00048 
00049 class Quaternion
00050 {
00051 public:
00052 
00053     cv::Vec3d vector;
00054     double scalar;
00055 
00056     Quaternion(){}
00057     Quaternion(const cv::Vec3d &v, double s) {
00058         vector = v;
00059         scalar = s;
00060     }
00061 };
00062 
00063 class Solution
00064 {
00065 public:
00066     Solution()
00067     {
00068         R = cv::Mat::zeros(3,3,CV_64F);
00069         t = cv::Mat::zeros(3,1,CV_64F);
00070     }
00071 
00072     Solution(const Solution &s) {
00073         R = s.R.clone();
00074         t = s.t.clone();
00075         E = s.E;
00076         bl = s.bl;
00077         at = s.at;
00078         obj_err = s.obj_err;
00079         img_err = s.img_err;
00080     }
00081 
00082 
00083     cv::Mat R;
00084     cv::Mat t;
00085     double E;
00086     double bl;
00087     double at;
00088     double obj_err;
00089     double img_err;
00090 };
00091 
00092 bool Rpp(const cv::Mat &model_3D, const cv::Mat &iprts,
00093             cv::Mat &Rlu, cv::Mat &tlu, int &it1, double &obj_err1, double &img_err1, std::vector<Solution>&sol);
00094 
00095 void ObjPose(const cv::Mat P, cv::Mat Qp, cv::Mat initR,
00096              cv::Mat &R, cv::Mat &t, int &it, double &obj_err, double &img_err);
00097 
00098 void AbsKernel(cv::Mat P, cv::Mat Q, const std::vector <cv::Mat> &F, const cv::Mat &G,
00099                cv::Mat &R, cv::Mat &t, cv::Mat &Qout, double &err2);
00100 
00101 cv::Mat EstimateT(const cv::Mat &R, const cv::Mat &G, const std::vector <cv::Mat> &F, const cv::Mat &P);
00102 cv::Mat NormRv(const cv::Mat &R);
00103 cv::Mat NormRv(const cv::Vec3d &V);
00104 
00105 Quaternion Quaternion_byAngleAndVector(double q_angle, const cv::Vec3d &q_vector);
00106 cv::Mat quat2mat(const Quaternion &Q);
00107 cv::Mat GetRotationbyVector(const cv::Vec3d &v1, const cv::Vec3d &v2);
00108 
00109 bool Get2ndPose_Exact(const cv::Mat &v, const cv::Mat &P, const cv::Mat &R, const cv::Mat &t, std::vector <Solution> &ret);
00110 
00111 bool GetRfor2ndPose_V_Exact(const cv::Mat &v, const cv::Mat &P, const cv::Mat &R, const cv::Mat &t, std::vector <Solution> &ret);
00112 
00113 void GetRotationY_wrtT(const cv::Mat &v, const cv::Mat &P, const cv::Mat &t, const cv::Mat &Rz,
00114                         std::vector <double> &al, cv::Mat &tnew, std::vector <double> &at);
00115 
00116 
00117 bool DecomposeR(const cv::Mat &R, cv::Mat &Rz2, cv::Mat &ret);
00118 
00119 cv::Mat RpyMat(const cv::Vec3d &angs);
00120 bool RpyAng(const cv::Mat &R, cv::Vec3d &ret); // returns roll,pitch,yaw
00121 cv::Mat Mean(const cv::Mat &m);
00122 cv::Mat Sum(const cv::Mat &m, int dim=1);
00123 cv::Mat Mul(const cv::Mat &a, const cv::Mat &b);
00124 cv::Mat Sq(const cv::Mat &m);
00125 cv::Mat Xform(const cv::Mat &P, const cv::Mat &R, const cv::Mat &t);
00126 double Norm(const cv::Mat &m);
00127 
00128 void Print(const cv::Mat &m);
00129 void Print(const Quaternion &q);
00130 
00131 // Makes homogenous points
00132 cv::Mat Point2Mat(const std::vector <cv::Point3d> &pts);
00133 cv::Mat Point2Mat(const std::vector <cv::Point2d> &pts);
00134 cv::Mat Vec2Mat(const cv::Vec3d &v);
00135 
00136 bool RpyAng_X(const cv::Mat &R, cv::Vec3d &ret);
00137 
00138 
00139 inline Quaternion Quaternion_byVectorAndScalar(const cv::Vec3d &vector, double scalar)
00140 {
00141     return Quaternion(vector, scalar);
00142 }
00143 
00144 inline Quaternion Quaternion_multiplyByScalar(const Quaternion &q, double scalar)
00145 {
00146     Quaternion ret;
00147 
00148     ret.vector[0] = q.vector[0]*scalar;
00149     ret.vector[1] = q.vector[1]*scalar;
00150     ret.vector[2] = q.vector[2]*scalar;
00151 
00152     ret.scalar = q.scalar*scalar;
00153 
00154     return ret;
00155 }
00156 
00157 inline double Quaternion_Norm(const Quaternion &Q)
00158 {
00159     return sqrt(Q.vector[0]*Q.vector[0] + Q.vector[1]*Q.vector[1] + Q.vector[2]*Q.vector[2] + Q.scalar*Q.scalar);
00160 }
00161 
00162 inline int sign(double x)
00163 {
00164     if(x < 0)
00165         return -1;
00166 
00167     if(x > 0)
00168         return 1;
00169 
00170     return 0;
00171 }
00172 
00173 } // End namespace
00174 #endif


fiducial_pose
Author(s): Jim Vaughan
autogenerated on Thu Jun 6 2019 18:08:11