-
Notifications
You must be signed in to change notification settings - Fork 0
/
visim2binraw.cpp
106 lines (84 loc) · 3.34 KB
/
visim2binraw.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
/***************************************************************************
* *
* Copyright (C) 2017 by Wenbin Li (wenbin.li@imperial.ac.uk) *
* *
* https://www.doc.ic.ac.uk/~wl208 *
* *
* This code is licensed under the BSD-like License. *
* *
***************************************************************************/
#include <iostream>
#include <string>
#include "raw.h"
#include <opencv2/opencv.hpp>
#include "file_tools.h"
namespace ViSimToBinRaw {
void readNext2f(std::ifstream &camera_info, float& x, float& y)
{
std::string line;
getline(camera_info, line);
getline(camera_info, line);
sscanf(line.c_str(), "%f%f", &x, &y);
}
}
int main(int argc, char** argv){
if(argc < 2){
std::cerr << "[INFO] Usage: ./vs2Raw [path-to-ViSim-Folder] [camera-index] [optional: low-quality-image (0 or 1)]" << std::endl;
return 0;
}
std::string path = argv[1];
std::string index = "0";
if(argc == 3){
index = argv[2];
}
std::string isLow = "0";
if (argc == 4) {
isLow = argv[3];
}
std::ifstream camera_info;
std::string info = path + "/cam" + index + ".info";
if(minibr::file_exists(info)){
camera_info.open(info.c_str());
}
else {
info = path + "/cameraInfo.txt";
camera_info.open(info.c_str());
}
std::cerr << "[INFO] Open cameraInfo file: " << info << std::endl;
float resX, resY, fx, fy, cx, cy;
ViSimToBinRaw::readNext2f(camera_info, resX, resY);
ViSimToBinRaw::readNext2f(camera_info, fx, fy);
ViSimToBinRaw::readNext2f(camera_info, cx, cy);
std::cerr << "[INFO] Image resolution, width: " << (unsigned int)resX << ", height: " << (unsigned int)resY << std::endl;
std::cerr << "[INFO] Camera focal lens, fx: " << fx << ", fy: " << fy << std::endl;
std::cerr << "[INFO] Camera center, cx: " << cx << ", cy: " << cy << std::endl;
camera_info.close();
std::string rgb_path = path + "/cam" + index;
if(isLow == "1" || !minibr::directory_exists(rgb_path)){
rgb_path = path + "/cam" + index + "_low";
}
std::string depth_path = path + "/depth" + index;
if(!minibr::directory_exists(rgb_path)) {
std::cerr << "[ERROR] RGB folder not exists" << std::endl;
return 0;
}
else {
std::cerr << "[INFO] loading RGB from: " << rgb_path << std::endl;
}
if(!minibr::directory_exists(depth_path)) {
std::cerr << "[ERROR] Depth folder not exists" << std::endl;
return 0;
}
else {
std::cerr << "[INFO] loading Depth from: " << depth_path << std::endl;
}
std::cerr << "[INFO] Start to convert images..." << std::endl;
if(!minibr::Raw::toBinRaw(rgb_path, depth_path, path, std::stoi(index),
(unsigned int)resX, (unsigned int)resY,
cx, cy, fx, fy)){
std::cerr << "[ERROR] ViSim to Raw convertion fail" << std::endl;
return 0;
}
std::cerr << "[INFO] Finish..." << std::endl;
return 1;
}