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 
00024 #include <math.h>
00025 
00026 using namespace std;
00027 
00028 VisualOdometry::VisualOdometry (parameters param) : param(param) {
00029   J         = 0;
00030   p_observe = 0;
00031   p_predict = 0;
00032   matcher   = new Matcher(param.match);
00033   Tr_delta  = Matrix::eye(4);
00034   Tr_valid  = false;
00035   srand(0);
00036 }
00037 
00038 VisualOdometry::~VisualOdometry () {
00039   delete matcher;
00040 }
00041 
00042 bool VisualOdometry::updateMotion () {
00043   
00044   // estimate motion
00045   vector<double> tr_delta = estimateMotion(p_matched);
00046   
00047   // on failure
00048   if (tr_delta.size()!=6)
00049     return false;
00050   
00051   // set transformation matrix (previous to current frame)
00052   Tr_delta = transformationVectorToMatrix(tr_delta);
00053   Tr_valid = true;
00054   
00055   // success
00056   return true;
00057 }
00058 
00059 Matrix VisualOdometry::transformationVectorToMatrix (vector<double> tr) {
00060 
00061   // extract parameters
00062   double rx = tr[0];
00063   double ry = tr[1];
00064   double rz = tr[2];
00065   double tx = tr[3];
00066   double ty = tr[4];
00067   double tz = tr[5];
00068 
00069   // precompute sine/cosine
00070   double sx = sin(rx);
00071   double cx = cos(rx);
00072   double sy = sin(ry);
00073   double cy = cos(ry);
00074   double sz = sin(rz);
00075   double cz = cos(rz);
00076 
00077   // compute transformation
00078   Matrix Tr(4,4);
00079   Tr.val[0][0] = +cy*cz;          Tr.val[0][1] = -cy*sz;          Tr.val[0][2] = +sy;    Tr.val[0][3] = tx;
00080   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;
00081   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;
00082   Tr.val[3][0] = 0;               Tr.val[3][1] = 0;               Tr.val[3][2] = 0;      Tr.val[3][3] = 1;
00083   return Tr;
00084 }
00085 
00086 vector<int32_t> VisualOdometry::getRandomSample(int32_t N,int32_t num) {
00087 
00088   // init sample and totalset
00089   vector<int32_t> sample;
00090   vector<int32_t> totalset;
00091   
00092   // create vector containing all indices
00093   for (int32_t i=0; i<N; i++)
00094     totalset.push_back(i);
00095 
00096   // add num indices to current sample
00097   sample.clear();
00098   for (int32_t i=0; i<num; i++) {
00099     int32_t j = rand()%totalset.size();
00100     sample.push_back(totalset[j]);
00101     totalset.erase(totalset.begin()+j);
00102   }
00103   
00104   // return sample
00105   return sample;
00106 }


libviso2
Author(s): Andreas Geiger, Stephan Wirth
autogenerated on Thu Jun 6 2019 21:23:13