licornea_tools
viewer.cc
Go to the documentation of this file.
1 #include "../lib/args.h"
2 #include "../lib/viewer.h"
3 #include "../lib/image_io.h"
4 #include "../lib/filesystem.h"
5 #include "lib/live/grabber.h"
6 #include <format.h>
7 #include <iostream>
8 
9 using namespace tlz;
10 
11 int main(int argc, const char* argv[]) {
12  get_args(argc, argv, "[snap_filename{}.png] [images/] [depths/] [ir/]");
13  std::string filename_tpl = string_opt_arg("snap_{:04d}.png");
14  std::string out_images_dir = out_dirname_opt_arg("snap/images/");
15  std::string out_depths_dir = out_dirname_opt_arg("snap/depths/");
16  std::string out_ir_dir = out_dirname_opt_arg("snap/ir/");
17 
19 
20  viewer view(754+512+512, 424);
21  auto& min_d = view.add_int_slider("depth min ", 0, 0, 20000);
22  auto& max_d = view.add_int_slider("depth max", 6000, 0, 20000);
23  auto& min_ir = view.add_int_slider("ir min", 0, 0x0000, 0xffff);
24  auto& max_ir = view.add_int_slider("ir max", 0xffff, 0x0000, 0xffff);
25 
26  int snap_counter = 0;
27 
28  bool cont = true;
29  while(cont) {
30  grab.grab();
31  view.clear();
32 
33  cv::Mat_<cv::Vec3b> image = grab.get_color_frame();
34  cv::Mat_<ushort> ir = grab.get_original_ir_frame();
35  cv::Mat_<real> depth = grab.get_depth_frame();
36 
37  view.draw(cv::Rect(0, 0, 754, 424), image);
38  view.draw(cv::Rect(754, 0, 512, 424), viewer::visualize_ir(ir, min_ir, max_ir));
39  view.draw_depth(cv::Rect(754+512, 0, 512, 424), depth, min_d, max_d);
40 
41  grab.release();
42 
43  int keycode;
44  cont = view.show(keycode);
45  if(keycode == enter_keycode) {
46  std::cout << "taking snapshot " << snap_counter << std::endl;
47  std::string out_filename = fmt::format(filename_tpl, snap_counter);
48  snap_counter++;
49  std::string out_image_filename = filename_append(out_images_dir, out_filename);
50  std::string out_depth_filename = filename_append(out_depths_dir, out_filename);
51  std::string out_ir_filename = filename_append(out_ir_dir, out_filename);
52  save_texture(out_image_filename, image);
53  save_depth(out_depth_filename, depth);
54  save_ir(out_ir_filename, ir);
55  }
56  }
57 }
void save_depth(const std::string &filename, const cv::Mat_< ushort > &depth)
Definition: image_io.cc:43
std::string filename_append(const std::string &a, const std::string &b)
void save_texture(const std::string &filename, const cv::Mat_< cv::Vec3b > &texture)
Definition: image_io.cc:13
cv::Mat_< cv::Vec3b > get_color_frame()
void draw(const cv::Mat_< cv::Vec3b > &, real blend=1.0)
Definition: viewer.cc:119
cv::Mat_< ushort > get_original_ir_frame(bool undistorted=false)
void save_ir(const std::string &filename, const cv::Mat_< ushort > &ir)
Definition: image_io.cc:28
int main(int argc, const char *argv[])
Definition: viewer.cc:11
cv::Mat_< float > get_depth_frame(bool undistorted=false)
bool show(int &keycode)
Definition: viewer.cc:218
void draw_depth(cv::Rect rect, const cv::Mat_< float > &depth_img, float min_d, float max_d, real blend=1.0)
Definition: viewer.cc:161
constexpr int enter_keycode
Definition: common.h:73
std::string out_dirname_opt_arg(const std::string &def)
Definition: args.cc:127
void release()
int_slider & add_int_slider(const std::string &caption, int default_val, int min_val, int max_val, int step=1)
Definition: viewer.cc:263
static cv::Mat_< uchar > visualize_ir(const cv::Mat &, float min_ir, float max_ir)
Definition: viewer.cc:107
void clear(int width, int height)
Definition: viewer.cc:76
std::string string_opt_arg(const std::string &def="")
Definition: args.h:36
void get_args(int argc, const char *argv[], const std::string &usage)
Definition: args.cc:49