1 #include "../lib/common.h" 2 #include "../lib/args.h" 3 #include "../lib/opencv.h" 4 #include "../lib/image_io.h" 5 #include "../lib/misc.h" 6 #include "../lib/obj_img_correspondence.h" 7 #include "../lib/viewer.h" 31 }
else if(
mode ==
"ir") {
37 }
else if(
mode ==
"both") {
48 int main(
int argc,
const char* argv[]) {
49 get_args(argc, argv,
"color/ir/both cols rows square_width out_cors_set.json [out_images_dir/] [restore_from_images]");
56 bool restore_from_images =
bool_opt_arg(
"restore_from_images",
false);
58 bool autosave =
false;
60 if(restore_from_images) {
63 std::cout <<
"restoring checkerboards from images" << std::endl;
64 for(
int i = 0; ; ++i) {
66 if(
mode ==
"color" ||
mode ==
"both") {
67 std::string color_filename = out_images_dirname +
"/color_" +
std::to_string(i) +
".png";
68 cv::Mat_<cv::Vec3b> color = cv::imread(color_filename, CV_LOAD_IMAGE_COLOR);
69 if(color.empty())
break;
77 std::string ir_filename = out_images_dirname +
"/ir_" +
std::to_string(i) +
".png";
78 cv::Mat_<ushort> ir = cv::imread(ir_filename, CV_LOAD_IMAGE_ANYDEPTH);
87 if(
mode ==
"color" && color_chk) {
89 std::cout <<
"got color checkerboard " << count << std::endl;
90 }
else if(
mode ==
"ir" && ir_chk) {
91 ir_chks.push_back(ir_chk); ++count;
92 std::cout <<
"got ir checkerboard " << count << std::endl;
93 }
else if(
mode ==
"both" && color_chk && ir_chk) {
97 std::cout <<
"got color+ir checkerboards " << count << std::endl;
101 std::cout <<
"restored " << count <<
" checkerboards, saving correspondences" << std::endl;
108 viewer view(754+512, 424+30);
110 auto& max_ir = view.
add_int_slider(
"ir max", 0xffff, 0x0000, 0xffff);
115 std::cout <<
"running viewer... (enter to capture checkerboard, esc to end)" << std::endl;
124 cv::Mat_<uchar> ir = grab.
get_ir_frame(min_ir.value(), max_ir.value());
138 running = view.
show(keycode);
141 if(! out_images_dirname.empty()) {
142 std::string color_filename = out_images_dirname +
"/color_" +
std::to_string(count) +
".png";
143 std::string ir_filename = out_images_dirname +
"/ir_" +
std::to_string(count) +
".png";
144 std::vector<int> params = { CV_IMWRITE_PNG_COMPRESSION, 0 };
145 if(
mode ==
"color" ||
mode ==
"both") cv::imwrite(color_filename, color, params);
146 if(
mode ==
"ir" ||
mode ==
"both") cv::imwrite(ir_filename, ir_orig, params);
149 if(
mode ==
"color" && color_chk) {
151 std::cout <<
"recorded color checkerboard " << count << std::endl;
152 }
else if(
mode ==
"ir" && ir_chk) {
153 ir_chks.push_back(ir_chk); ++count;
154 std::cout <<
"recorded ir checkerboard " << count << std::endl;
155 }
else if(
mode ==
"both" && color_chk && ir_chk) {
159 std::cout <<
"recorded color+ir checkerboards " << count << std::endl;
163 std::cout <<
"autosaving correspondences" << std::endl;
170 std::cout <<
"now saving correspondences" << std::endl;
176 std::cout <<
"done" << std::endl;
cv::Mat_< uchar > get_ir_frame(float min_ir=0, float max_ir=0xffff, bool undistorted=false)
cv::Mat_< cv::Vec3b > get_color_frame()
std::vector< checkerboard > ir_chks
obj_img_correspondences< 1, 1 > checkerboard_obj_img_correspondences(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)
std::string enum_arg(const std::vector< std::string > &options)
cv::Mat_< ushort > get_original_ir_frame(bool undistorted=false)
checkerboard detect_color_checkerboard(cv::Mat_< cv::Vec3b > &img, int cols, int rows, real square_width)
int main(int argc, const char *argv[])
constexpr int enter_keycode
void export_json_file(const json &j, const std::string &filename, bool compact)
std::string out_dirname_opt_arg(const std::string &def)
std::vector< vec3 > checkerboard_world_corners(int cols, int rows, real square_width)
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)
obj_img_correspondences< 1, 2 > checkerboard_obj_2img_correspondences(const checkerboard &chk1, const checkerboard &chk2)
checkerboard detect_ir_checkerboard(cv::Mat_< uchar > &img, int cols, int rows, real square_width)
void save_correspondences_set()
json encode_obj_img_correspondences_set(const obj_img_correspondences_set< Obj_count, Img_count > &)
std::vector< checkerboard > color_chks
bool bool_opt_arg(const std::string &expected, bool def=false)
void clear(int width, int height)
std::string out_cors_set_filename
std::vector< obj_img_correspondences< Obj_count, Img_count >> obj_img_correspondences_set
void get_args(int argc, const char *argv[], const std::string &usage)