-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
121 lines (99 loc) · 3.44 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <Eigen/Dense>
#include <iostream>
#include <string>
#include <vector>
#include <stdint.h>
#include <viso_stereo.h>
#include <png.hpp>
#include "matcher.h"
static Matcher *M;
using namespace std;
using Eigen::MatrixXd;
int main (int argc, char** argv) {
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
if (argc<2) {
cerr << "Usage: ./viso2 path/to/sequence/2010_03_09_drive_0019" << endl;
return 1;
}
//getchar();
// sequence directory
string dir = argv[1];
//string dir = "c:\Users\zhangzheng1993";
// set most important visual odometry parameters
// for a full parameter list, look at: viso_stereo.h
VisualOdometryStereo::parameters param;
// calibration parameters for sequence 2010_03_09_drive_0019
param.calib.f = 645.24; // focal length in pixels
param.calib.cu = 635.96; // principal point (u-coordinate) in pixels
param.calib.cv = 194.13; // principal point (v-coordinate) in pixels
param.base = 0.5707; // baseline in meters
// init visual odometry
VisualOdometryStereo viso(param);
Matcher::parameters param1;
// matcherMex("init",param1);
// current pose (this matrix transforms a point from the current
// frame's camera coordinates to the first frame's camera coordinates)
Matrix pose = Matrix::eye(4);
// loop through all frames i=0:372
for (int32_t i=0; i<373; i++) {
// input file names
char base_name[256]; sprintf(base_name,"%06d.png",i);
string left_img_file_name = dir + "/I1_" + base_name;
string right_img_file_name = dir + "/I2_" + base_name;
// catch image read/write errors here
try {
// load left and right input image
png::image< png::gray_pixel > left_img(left_img_file_name);
png::image< png::gray_pixel > right_img(right_img_file_name);
// image dimensions
int32_t width = left_img.get_width();
int32_t height = left_img.get_height();
// convert input images to uint8_t buffer
uint8_t* left_img_data = (uint8_t*)malloc(width*height*sizeof(uint8_t));
uint8_t* right_img_data = (uint8_t*)malloc(width*height*sizeof(uint8_t));
int32_t k=0;
for (int32_t v=0; v<height; v++) {
for (int32_t u=0; u<width; u++) {
left_img_data[k] = left_img.get_pixel(u,v);
right_img_data[k] = right_img.get_pixel(u,v);
k++;
}
}
// status
cout << "Processing: Frame: " << i;
// compute visual odometry
int32_t dims[] = {width,height,width};
if (viso.process(left_img_data,right_img_data,dims)) {
// on success, update current pose
pose = pose * Matrix::inv(viso.getMotion());
// output some statistics
double num_matches = viso.getNumberOfMatches();
double num_inliers = viso.getNumberOfInliers();
cout << ", Matches: " << num_matches;
cout << ", Inliers: " << 100.0*num_inliers/num_matches << " %" << ", Current pose: " << endl;
cout << pose << endl << endl;
} else {
cout << " ... failed!" << endl;
}
// release uint8_t buffers
free(left_img_data);
free(right_img_data);
//getchar();
// catch image read errors here
} catch (...) {
cerr << "ERROR: Couldn't read input files!" << endl;
return 1;
}
}
getchar();
// output
cout << "Demo complete! Exiting ..." << endl;
// exit
return 0;
}