viso.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright 2011. All rights reserved.
00003 Institute of Measurement and Control Systems
00004 Karlsruhe Institute of Technology, Germany
00005 
00006 This file is part of libviso2.
00007 Authors: Andreas Geiger
00008 
00009 libviso2 is free software; you can redistribute it and/or modify it under the
00010 terms of the GNU General Public License as published by the Free Software
00011 Foundation; either version 2 of the License, or any later version.
00012 
00013 libviso2 is distributed in the hope that it will be useful, but WITHOUT ANY
00014 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
00015 PARTICULAR PURPOSE. See the GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License along with
00018 libviso2; if not, write to the Free Software Foundation, Inc., 51 Franklin
00019 Street, Fifth Floor, Boston, MA 02110-1301, USA
00020 */
00021 
00022 #include "viso.h"
00023 #include <math.h>
00024 
00025 using namespace std;
00026 
00027 VisualOdometry::VisualOdometry (parameters param) : param(param) {
00028   J         = 0;
00029   p_observe = 0;
00030   p_predict = 0;
00031   matcher   = new Matcher(param.match);
00032   Tr_delta  = Matrix::eye(4);
00033   Tr_valid  = false;
00034   srand(0);
00035 }
00036 
00037 VisualOdometry::~VisualOdometry () {
00038   delete matcher;
00039 }
00040 
00041 bool VisualOdometry::updateMotion () {
00042 
00043   // estimate motion
00044   // Choose which method to be use
00045   //vector<double> tr_delta = estimateMotion(p_matched);
00046   vector<double> tr_delta = estimateMotionMaxClique(p_matched);
00047 
00048   // on failure
00049   if (tr_delta.size()!=6)
00050     return false;
00051 
00052   // set transformation matrix (previous to current frame)
00053   Tr_delta = transformationVectorToMatrix(tr_delta);
00054   Tr_valid = true;
00055 
00056   // success
00057   return true;
00058 }
00059 
00060 Matrix VisualOdometry::transformationVectorToMatrix (vector<double> tr) {
00061 
00062   // extract parameters
00063   double rx = tr[0];
00064   double ry = tr[1];
00065   double rz = tr[2];
00066   double tx = tr[3];
00067   double ty = tr[4];
00068   double tz = tr[5];
00069 
00070   // precompute sine/cosine
00071   double sx = sin(rx);
00072   double cx = cos(rx);
00073   double sy = sin(ry);
00074   double cy = cos(ry);
00075   double sz = sin(rz);
00076   double cz = cos(rz);
00077 
00078   // compute transformation
00079   Matrix Tr(4,4);
00080   Tr.val[0][0] = +cy*cz;          Tr.val[0][1] = -cy*sz;          Tr.val[0][2] = +sy;    Tr.val[0][3] = tx;
00081   Tr.val[1][0] = +sx*sy*cz+cx*sz; Tr.val[1][1] = -sx*sy*sz+cx*cz; Tr.val[1][2] = -sx*cy; Tr.val[1][3] = ty;
00082   Tr.val[2][0] = -cx*sy*cz+sx*sz; Tr.val[2][1] = +cx*sy*sz+sx*cz; Tr.val[2][2] = +cx*cy; Tr.val[2][3] = tz;
00083   Tr.val[3][0] = 0;               Tr.val[3][1] = 0;               Tr.val[3][2] = 0;      Tr.val[3][3] = 1;
00084   return Tr;
00085 }
00086 
00087 vector<int32_t> VisualOdometry::getRandomSample(int32_t N,int32_t num) {
00088 
00089   // init sample and totalset
00090   vector<int32_t> sample;
00091   vector<int32_t> totalset;
00092 
00093   // create vector containing all indices
00094   for (int32_t i=0; i<N; i++)
00095     totalset.push_back(i);
00096 
00097   // add num indices to current sample
00098   sample.clear();
00099   for (int32_t i=0; i<num; i++) {
00100     int32_t j = rand()%totalset.size();
00101     sample.push_back(totalset[j]);
00102     totalset.erase(totalset.begin()+j);
00103   }
00104 
00105   // return sample
00106   return sample;
00107 }


dlut_libvo
Author(s): Zhuang Yan
autogenerated on Thu Jun 6 2019 20:03:29