Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00045 vector<double> tr_delta = estimateMotion(p_matched);
00046
00047
00048 if (tr_delta.size()!=6)
00049 return false;
00050
00051
00052 Tr_delta = transformationVectorToMatrix(tr_delta);
00053 Tr_valid = true;
00054
00055
00056 return true;
00057 }
00058
00059 Matrix VisualOdometry::transformationVectorToMatrix (vector<double> tr) {
00060
00061
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
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
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
00089 vector<int32_t> sample;
00090 vector<int32_t> totalset;
00091
00092
00093 for (int32_t i=0; i<N; i++)
00094 totalset.push_back(i);
00095
00096
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
00105 return sample;
00106 }