7 #include "../lib/camera.h" 8 #include "../lib/border.h" 13 std::cout <<
"usage: transform in_cameras.json out_cameras.json/none/replace operation\n" 14 <<
" MPEG2Rt: MPEG convention to standard extrinsic matrix\n" 15 <<
" flip_t: flip sign of translation vectors\n" 16 <<
" scale old new: adapt intrinsic matrix for image scale from old to new\n" 17 <<
" (old/new = pixel length of same segment in old and new image)\n" 18 <<
" border [old] new: adapt intrinsic matrix for image border change from old to new\n" 19 <<
" (old/new = border.json file. if no old, assumed old border is zero)\n" 20 <<
" rename cam_{} [offset=0] [factor=1]: rename according to format, with arg = offset + factor*index\n" 21 <<
" head n: Only n first cameras\n" 22 <<
" tail n: Only n last cameras\n" 23 <<
" nop: No change, just rewrite the cameras file\n" 28 int main(
int argc,
const char* argv[]) {
30 std::string in_cameras_filename = argv[1];
31 std::string out_cameras_filename = argv[2];
32 std::string operation = argv[3];
40 for(
camera& in_cam : in_cameras) {
43 if(operation ==
"Rt2MPEG") {
46 }
else if(operation ==
"MPEG2Rt") {
49 }
else if(operation ==
"flip_t") {
52 }
else if(operation ==
"scale") {
54 int old_sz = std::atoi(argv[4]);
55 int new_sz = std::atoi(argv[5]);
56 float factor = (float)new_sz / old_sz;
62 }
else if(operation ==
"border") {
63 border old_border, new_border;
65 std::string new_border_filename = argv[4];
67 }
else if(argc == 5) {
68 std::string old_border_filename = argv[4];
70 std::string new_border_filename = argv[5];
76 }
else if(operation ==
"rename") {
78 std::string format = argv[4];
81 if(argc > 5) offset = std::atoi(argv[5]);
82 if(argc > 6) factor = std::atoi(argv[6]);
83 std::string new_name = fmt::format(format, factor*index + offset);
84 std::cout << cam.
name <<
" --> " << new_name << std::endl;
87 }
else if(operation ==
"head") {
89 int n = std::atoi(argv[4]);
92 }
else if(operation ==
"tail") {
94 int n = std::atoi(argv[4]);
95 skip = (index < in_cameras.size() - n);
97 }
else if(operation ==
"nop") {
105 if(! skip) out_cameras.push_back(cam);
108 if(out_cameras_filename ==
"none") {
109 std::cout <<
"not writing to output" << std::endl;
111 if(out_cameras_filename ==
"replace") out_cameras_filename = in_cameras_filename;
112 std::cout <<
"writing to " << out_cameras_filename << std::endl;
113 std::ofstream output(out_cameras_filename.c_str());
118 std::cout <<
"done" << std::endl;
void export_cameras_file(const camera_array &cameras, const std::string &filename)
camera_array decode_cameras(const json &j_cams)
border decode_border(const json &j_bord)
std::vector< camera > camera_array
json import_json_file(const std::string &filename)