licornea_tools
cam_rotation.cc
Go to the documentation of this file.
1 #include "../lib/args.h"
2 #include "../lib/json.h"
3 #include "../lib/rotation.h"
4 #include <iostream>
5 #include <cstdlib>
6 #include <cmath>
7 
8 using namespace tlz;
9 
10 int main(int argc, const char* argv[]) {
11  get_args(argc, argv, "(from rotation_matrix.json / to out_rotation_matrix.json x y z)");
12  std::string mode = enum_arg({"from", "to"});
13 
14  if(mode == "from") {
15  std::string rotation_mat_filename = in_filename_arg();
16 
17  mat33 R = decode_mat(import_json_file(rotation_mat_filename));
18 
19  vec3 euler = to_euler(R);
20 
21  std::cout << "x = " << euler[0] * deg_per_rad << "°" << std::endl;
22  std::cout << "y = " << euler[1] * deg_per_rad << "°" << std::endl;
23  std::cout << "z = " << euler[2] * deg_per_rad << "°" << std::endl;
24 
25  } else if(mode == "to") {
26  std::string out_rotation_mat_filename = out_filename_arg();
27  real x = real_arg() * rad_per_deg;
28  real y = real_arg() * rad_per_deg;
29  real z = real_arg() * rad_per_deg;
30 
31  vec3 euler(x, y, z);
32  mat33 R = to_rotation_matrix(euler);
33 
34  export_json_file(encode_mat(R), out_rotation_mat_filename);
35  }
36 }
constexpr real deg_per_rad
Definition: common.h:78
std::string in_filename_arg()
Definition: args.cc:98
std::string enum_arg(const std::vector< std::string > &options)
Definition: args.cc:154
cv::Mat_< real > decode_mat(const json &j)
Definition: json.cc:32
int main(int argc, const char *argv[])
Definition: cam_rotation.cc:10
cv::Matx< real, 3, 3 > mat33
Definition: common.h:26
json encode_mat(const Mat &mat)
Definition: json.h:19
double real
Definition: common.h:16
void export_json_file(const json &j, const std::string &filename, bool compact)
Definition: json.cc:9
cv::Vec< real, 3 > vec3
Definition: common.h:23
double real_arg()
Definition: args.cc:146
mat33 to_rotation_matrix(const vec3 &euler)
Definition: rotation.cc:17
std::string out_filename_arg()
Definition: args.cc:104
constexpr real rad_per_deg
Definition: common.h:79
vec3 to_euler(const mat33 &R_)
Definition: rotation.cc:39
std::string mode
json import_json_file(const std::string &filename)
Definition: json.cc:24
void get_args(int argc, const char *argv[], const std::string &usage)
Definition: args.cc:49