planarSFM.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2009, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 #if !defined(_PLANAR_SFM_H)
00036 #define _PLANAR_SFM_H
00037 
00038 #include <posest/pe.h>
00039 #include <opencv2/core/core.hpp>
00040 #include <opencv2/features2d/features2d.hpp>
00041 
00042 namespace pe
00043 {
00044 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 void planarSFM(const cv::Mat& intrinsics, const std::vector<cv::KeyPoint>& set1, const std::vector<cv::KeyPoint>& set2, const std::vector<int>& indices,
00058                cv::Mat& H, cv::Mat& R, cv::Mat& T, double reprojectionError = 6.0);
00059 
00060 double SFMwithSBA(const cv::Mat& intrinsics, const std::vector<cv::KeyPoint>& points1, const std::vector<cv::KeyPoint>& points2,
00061         const std::vector<int>& indices, cv::Mat& rvec, cv::Mat& T, double reprojectionError);
00062 
00063 double SFMwithSBA(const cv::Mat& intrinsics, std::vector<cv::Point2f>& points1, std::vector<cv::Point2f>& points2,
00064         cv::Mat& rvec, cv::Mat& T, double reprojectionError);
00065 
00066 double SFM(const cv::Mat& intrinsics, const std::vector<cv::KeyPoint>& set1, const std::vector<cv::KeyPoint>& set2, const std::vector<int>& indices,
00067                 cv::Mat& R, cv::Mat& T, double reprojectionError = 6.0);
00068 
00069 double SFM(const cv::Mat& intrinsics, const std::vector<cv::Point2f>& points1, const std::vector<cv::Point2f>& points2,
00070         cv::Mat& R, cv::Mat& T, double reprojectionError = 6.0);
00071 
00072 double avgSampsonusError(const cv::Mat& essential, const std::vector<cv::Point2f>& points1, const std::vector<cv::Point2f>& points2,
00073                 double max_error = 1.0, bool verbose = false);
00074 
00075 cv::Mat calcEssentialMatrix(const cv::Mat& intrinsics_inv, const cv::Mat& R, const cv::Mat& T);
00076 
00077 inline cv::Point3f crossProduct(cv::Point3f& p1, cv::Point3f& p2)
00078 {
00079     cv::Point3f p3(p1.y*p2.z - p1.z*p2.y, p1.z*p2.x - p1.x*p2.z, p1.x*p2.y - p1.y*p2.x);
00080     return p3;
00081 };
00082 
00083 void dumpFltMat(const char* name, const cv::Mat& mat);
00084 
00085 void keyPoints2Point2f(const cv::vector<cv::KeyPoint>& src, std::vector<cv::Point2f>& dst);
00086 
00087 void reprojectPoints(const cv::Mat& intrinsics, const cv::Mat& R, const cv::Mat& T, const std::vector<cv::Point2f>& p1,
00088     const std::vector<cv::Point2f>& p2, std::vector<cv::Point3f>& p, std::vector<bool>& valid);
00089 
00090 void matchesFromIndices(const std::vector<cv::KeyPoint>& _set1, const std::vector<cv::KeyPoint>& _set2, const std::vector<int>& indices,
00091                         std::vector<cv::Point2f>& points1, std::vector<cv::Point2f>& points2);
00092 
00093 void matchesFromIndices(const std::vector<cv::KeyPoint>& src1, const std::vector<cv::KeyPoint>& src2, const std::vector<cv::DMatch>& indices,
00094     std::vector<cv::Point2f>& dst1, std::vector<cv::Point2f>& dst2);
00095 
00096 float calcScaledPointCloudDistance(const std::vector<cv::Point3f>& points1, const std::vector<cv::Point3f>& points2);
00097 
00098 void sba(const cv::Mat& intrinsics, cv::Mat& rvec, cv::Mat& tvec, std::vector<cv::Point3f>& points,
00099     const std::vector<cv::Point2f>& points1, const std::vector<cv::Point2f>& points2);
00100 
00101 template<class T>
00102 void filterVector(const std::vector<T>& src, const std::vector<bool>& valid, std::vector<T>& dst)
00103 {
00104     dst.clear();
00105     for(size_t i = 0; i < valid.size(); i++)
00106     {
00107         if(valid[i])
00108         {
00109             dst.push_back(src[i]);
00110         }
00111     }
00112 };
00113 
00114 template<class T>
00115 void filterVector(const std::vector<T>& src, const std::vector<int>& valid, std::vector<T>& dst)
00116 {
00117     dst.clear();
00118     for(size_t i = 0; i < valid.size(); i++)
00119     {
00120         if(valid[i])
00121         {
00122             dst.push_back(src[i]);
00123         }
00124     }
00125 };
00126 
00127 template<class T>
00128 void filterVector(std::vector<T>& v, const std::vector<bool>& valid)
00129 {
00130     std::vector<T> out;
00131     filterVector(v, valid, out);
00132     v = out;
00133 };
00134 
00135 void computeEpipolarInliers(const cv::Mat& essential, const std::vector<cv::Point2f>& points1, const std::vector<cv::Point2f>& points2,
00136     std::vector<bool>& inliers, double maxError = 3.0);
00137 
00138 void findNaNPoints(const std::vector<cv::Point3f>& points, std::vector<bool>& valid);
00139 
00140 void filterInliers(const std::vector<cv::Point3f>& obj_pts, const std::vector<cv::Point2f>& img1_pts,
00141     const std::vector<cv::Point2f>& img2_pts, const cv::Mat& R, const cv::Mat& T, const cv::Mat& intrinsics,
00142     double reprojectionError, std::vector<bool>& valid);
00143 
00144 void keyPoints2Point2f(const std::vector<cv::KeyPoint>& src, std::vector<cv::Point2f>& dst);
00145 
00146 template<class T>
00147 void vectorSubset(const std::vector<T>& src, const std::vector<int>& indices, std::vector<T>& dst)
00148 {
00149     dst.clear();
00150     for(size_t i = 0; i < indices.size(); i++)
00151     {
00152         dst.push_back(src[indices[i]]);
00153     }
00154 };
00155 
00156 void sample(int max_index, int count, std::vector<int>& sample_indices);
00157 
00158 cv::Point3f mult(const cv::Mat& M, const cv::Point3f& p);
00159 
00160 void calcRelativeRT(const cv::Mat& R1, const cv::Mat& T1, const cv::Mat& R2, const cv::Mat& T2,
00161                     cv::Mat& dR, cv::Mat& dT);
00162 
00163 }
00164 
00165 
00166 #endif //_PLANAR_SFM_H


posest
Author(s): Kurt Konolige
autogenerated on Thu Jan 2 2014 12:12:17