1 #include "../lib/common.h" 2 #include "../lib/args.h" 3 #include "../lib/opencv.h" 4 #include "../lib/intrinsics.h" 5 #include "../lib/misc.h" 6 #include "../lib/obj_img_correspondence.h" 7 #include "../lib/viewer.h" 18 int main(
int argc,
const char* argv[]) {
19 get_args(argc, argv,
"cols rows out_chk_samples.json");
26 viewer view(512+512, 424+30);
28 auto& max_ir = view.
add_int_slider(
"ir max", 0xffff, 0x0000, 0xffff);
33 bool autocollect =
false;
34 struct checkerboard_sample {
35 std::vector<vec2> corners;
36 std::vector<checkerboard_pixel_depth_sample> pixel_samples;
38 std::vector<checkerboard_sample> samples;
41 checkerboard_sample current_sample;
44 std::cout <<
"running viewer... (enter to capture samples, esc to end)" << std::endl;
51 cv::Mat_<uchar> ir = grab.
get_ir_frame(min_ir.value(), max_ir.value());
56 if(ir_chk && granularity.value() > 0) {
57 current_sample = checkerboard_sample();
65 else view.
draw_depth(cv::Rect(512, 0, 512, 424), depth, min_d.value(), max_d.value());
67 view.
draw_text(cv::Rect(20, 424, 512+512-20, 30), std::string(
"(a) autocollect is ") + (autocollect ?
"ON" :
"off"),
viewer::left);
73 running = view.
show(keycode);
78 else if(keycode ==
'a') autocollect = !autocollect;
80 if(autocollect) collect =
true;
82 if(collect && has_sample) {
83 samples.push_back(current_sample);
84 total_pixels += current_sample.pixel_samples.size();
89 std::cout <<
"saving collected checkerboard samples" << std::endl;
91 json j_chk_samples = json::array();
92 for(
const checkerboard_sample& chk : samples) {
93 json j_chk_samp = json::object();
95 json j_corners = json::array();
96 for(
const vec2& corner : chk.corners) {
97 json j_corner = json::object();
98 j_corner[
"x"] = corner[0];
99 j_corner[
"y"] = corner[1];
100 j_corners.push_back(j_corner);
102 j_chk_samp[
"corners"] = j_corners;
104 json j_pixels = json::array();
106 json j_pixel = json::object();
110 j_pixels.push_back(j_pixel);
112 j_chk_samp[
"pixels"] = j_pixels;
114 j_chk_samples.push_back(j_chk_samp);
119 std::cout <<
"done" << std::endl;
cv::Mat_< uchar > get_ir_frame(float min_ir=0, float max_ir=0xffff, bool undistorted=false)
const real reprojection_error_max_threshold
static cv::Mat_< uchar > visualize_depth(const cv::Mat &, float min_d, float max_d)
std::vector< vec2 > checkerboard_image_corners(const checkerboard &chk)
void draw(const cv::Mat_< cv::Vec3b > &, real blend=1.0)
cv::Mat_< cv::Vec3b > visualize_checkerboard(const cv::Mat_< cv::Vec3b > &img, const checkerboard &chk, const checkerboard_visualization_parameters ¶m)
int main(int argc, const char *argv[])
cv::Mat_< float > get_depth_frame(bool undistorted=false)
cv::Mat_< cv::Vec3b > visualize_checkerboard_pixel_samples(const cv::Mat_< cv::Vec3b > &img, const std::vector< checkerboard_pixel_depth_sample > &pixels, int rad)
void draw_depth(cv::Rect rect, const cv::Mat_< float > &depth_img, float min_d, float max_d, real blend=1.0)
constexpr int enter_keycode
void export_json_file(const json &j, const std::string &filename, bool compact)
std::string to_string(const T &)
std::string out_filename_arg()
void draw_text(cv::Rect rect, const std::string &text, text_alignment=left)
int_slider & add_int_slider(const std::string &caption, int default_val, int min_val, int max_val, int step=1)
checkerboard detect_ir_checkerboard(cv::Mat_< uchar > &img, int cols, int rows, real square_width)
void clear(int width, int height)
std::vector< checkerboard_pixel_depth_sample > checkerboard_pixel_depth_samples(const checkerboard &chk, const cv::Mat_< float > &depth_image, int granularity)
void get_args(int argc, const char *argv[], const std::string &usage)