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
00023
00024
00025
00026
00027
00028
00029 #include <iostream>
00030 #include <string>
00031 #include <vector>
00032 #include <stdint.h>
00033
00034 #include <viso_stereo.h>
00035 #include <png++/png.hpp>
00036
00037 using namespace std;
00038
00039 int main (int argc, char** argv) {
00040
00041
00042 if (argc<2) {
00043 cerr << "Usage: ./viso2 path/to/sequence/2010_03_09_drive_0019" << endl;
00044 return 1;
00045 }
00046
00047
00048 string dir = argv[1];
00049
00050
00051
00052 VisualOdometryStereo::parameters param;
00053
00054
00055 param.calib.f = 645.24;
00056 param.calib.cu = 635.96;
00057 param.calib.cv = 194.13;
00058 param.base = 0.5707;
00059
00060
00061 VisualOdometryStereo viso(param);
00062
00063
00064
00065 Matrix pose = Matrix::eye(4);
00066
00067
00068 for (int32_t i=0; i<373; i++) {
00069
00070
00071 char base_name[256]; sprintf(base_name,"%06d.png",i);
00072 string left_img_file_name = dir + "/I1_" + base_name;
00073 string right_img_file_name = dir + "/I2_" + base_name;
00074
00075
00076 try {
00077
00078
00079 png::image< png::gray_pixel > left_img(left_img_file_name);
00080 png::image< png::gray_pixel > right_img(right_img_file_name);
00081
00082
00083 int32_t width = left_img.get_width();
00084 int32_t height = left_img.get_height();
00085
00086
00087 uint8_t* left_img_data = (uint8_t*)malloc(width*height*sizeof(uint8_t));
00088 uint8_t* right_img_data = (uint8_t*)malloc(width*height*sizeof(uint8_t));
00089 int32_t k=0;
00090 for (int32_t v=0; v<height; v++) {
00091 for (int32_t u=0; u<width; u++) {
00092 left_img_data[k] = left_img.get_pixel(u,v);
00093 right_img_data[k] = right_img.get_pixel(u,v);
00094 k++;
00095 }
00096 }
00097
00098
00099 cout << "Processing: Frame: " << i;
00100
00101
00102 int32_t dims[] = {width,height,width};
00103 if (viso.process(left_img_data,right_img_data,dims)) {
00104
00105
00106 pose = pose * Matrix::inv(viso.getMotion());
00107
00108
00109 double num_matches = viso.getNumberOfMatches();
00110 double num_inliers = viso.getNumberOfInliers();
00111 cout << ", Matches: " << num_matches;
00112 cout << ", Inliers: " << 100.0*num_inliers/num_matches << " %" << ", Current pose: " << endl;
00113 cout << pose << endl << endl;
00114
00115 } else {
00116 cout << " ... failed!" << endl;
00117 }
00118
00119
00120 free(left_img_data);
00121 free(right_img_data);
00122
00123
00124 } catch (...) {
00125 cerr << "ERROR: Couldn't read input files!" << endl;
00126 return 1;
00127 }
00128 }
00129
00130
00131 cout << "Demo complete! Exiting ..." << endl;
00132
00133
00134 return 0;
00135 }
00136