-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_decoders.cpp
157 lines (137 loc) · 5.48 KB
/
run_decoders.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <iostream>
#include <fstream>
#include "processors.h"
#include "libfreenect2_data_structures.h"
#include "read_file_handler.h"
#include "device_parameters.h"
#include "setup_parser.h"
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
if(argc != 3)
{
std::cout<<"usage:\n ./kinectv2_decoders /path/to/config/setup.xml dataset";
return 0;
}
std::cout<<"Processing depth data...";
std::string setup_xmlfile = argv[1];
std::string data_set = argv[2];
std::string data_file_name = "../dataset/logs/";
data_file_name.append(data_set);
data_file_name.append(".h5");
//parse parameter file
SetupParser parser;
parser.init(setup_xmlfile);
std::vector<Parameters> params = parser.getParameters();
//Load device specific parameters
DeviceParametersHandler dev;
dev.init("../parameters/calib_pose_fixed_ir_2.h5");
//Load data file containig raw kinect v2 measurents
ReadFileHandler myfile(data_file_name);
unsigned char* p0_table;
int len_p0_table;
myfile.ReadBuffer(&p0_table, &len_p0_table, "/P0Tables");
std::vector<DepthPacketProcessor*> processors;
std::vector<std::fstream*> depth_files, conf_files;
for(unsigned int i = 0; i < params.size(); ++i)
{
if(strcmp(params[i].pipeline.c_str(),"libfreenect2") == 0)
{
std::string depth_filename = "../dataset/data/";
depth_filename.append(params[i].pipeline);
std::string conf_filename = "../dataset/data/";
conf_filename.append(params[i].pipeline);
depth_filename.append("_depth_");
depth_filename.append(params[i].setup_name);
depth_filename.append("_");
depth_filename.append(data_set);
depth_filename.append(".bin");
conf_filename.append("_conf_");
conf_filename.append(params[i].setup_name);
conf_filename.append("_");
conf_filename.append(data_set);
conf_filename.append(".bin");
if(!(std::ifstream(depth_filename.c_str()) || std::ifstream(conf_filename.c_str())))
{
std::fstream* depth_file = new std::fstream(depth_filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
std::fstream* conf_file = new std::fstream(conf_filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
depth_files.push_back(depth_file);
conf_files.push_back(conf_file);
//initialize libreenect2 decoder
CpuDepthPacketProcessor* libfreenect2 = new CpuDepthPacketProcessor();
libfreenect2->initParameters(params[i]);
libfreenect2->loadP0TablesFromCommandResponse(p0_table, len_p0_table);
libfreenect2->loadXZTables(&dev.xtable[0], &dev.ztable[0]);
libfreenect2->loadLookupTable(&dev.lut[0]);
processors.push_back(libfreenect2);
}
}
else if(strcmp(params[i].pipeline.c_str(),"kde") == 0)
{
//initialize kde decoder
std::string depth_filename = "../dataset/data/";
depth_filename.append(params[i].pipeline);
std::string conf_filename = "../dataset/data/";
conf_filename.append(params[i].pipeline);
depth_filename.append("_depth_");
depth_filename.append(params[i].setup_name);
depth_filename.append("_");
depth_filename.append(data_set);
depth_filename.append(".bin");
conf_filename.append("_conf_");
conf_filename.append(params[i].setup_name);
conf_filename.append("_");
conf_filename.append(data_set);
conf_filename.append(".bin");
if(!(std::ifstream(depth_filename.c_str()) || std::ifstream(conf_filename.c_str())))
{
std::fstream* depth_file = new std::fstream(depth_filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
std::fstream* conf_file = new std::fstream(conf_filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
depth_files.push_back(depth_file);
conf_files.push_back(conf_file);
CpuKdeDepthPacketProcessor* kde = new CpuKdeDepthPacketProcessor();
kde->initParameters(params[i]);
kde->loadP0TablesFromCommandResponse(p0_table, len_p0_table);
kde->loadXZTables(&dev.xtable[0], &dev.ztable[0]);
kde->loadLookupTable(&dev.lut[0]);
processors.push_back(kde);
}
}
else
{
std::cout<<"pipeline "<<params[i].pipeline<<" not implemented\n";
continue;
}
}
//decode and save frames to file
int frame_num;
int frame_num_offset = 0;
int num_frames = 25;
for(frame_num = frame_num_offset; frame_num < num_frames+frame_num_offset; frame_num++)
{
std::cout<<"Frame: "<<frame_num<<std::endl;
unsigned char *buffer;
int len;
myfile.ReadIrBuffer(&buffer, &len, frame_num);
for(unsigned int i = 0; i < processors.size(); ++i)
{
float *depth, *conf;
processors[i]->process(buffer, &depth, &conf);
depth_files[i]->write((char*)depth, 512*424*sizeof(float));
conf_files[i]->write((char*)conf, 512*424*sizeof(float));
delete[] depth;
delete[] conf;
}
delete[] buffer;
}
//clean up
for(unsigned int i = 0; i < processors.size(); ++i)
{
delete processors[i];
delete depth_files[i];
delete conf_files[i];
}
std::cout<<"Done!\n";
return 0;
}