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" 16 int main(
int argc,
const char* argv[]) {
17 get_args(argc, argv,
"chk_samples.json cols rows square_width ir_intr.json out_stat.txt");
25 struct checkerboard_sample {
26 std::vector<vec2> corners;
27 std::vector<checkerboard_pixel_depth_sample> pixel_samples;
29 std::vector<checkerboard_sample> chk_samples;
31 std::cout <<
"loading checkerboard samples" << std::endl;
34 for(
const auto& j_chk_sample : j_chk_samples) {
35 checkerboard_sample chk_samp;
37 const json& j_corners = j_chk_sample[
"corners"];
38 if(j_corners.size() != cols*
rows)
throw std::runtime_error(
"wrong checkerboard sample corner count");
39 for(
const auto& j_corner : j_corners) {
40 chk_samp.corners.emplace_back(j_corner[
"x"], j_corner[
"y"]);
42 const json& j_pixels = j_chk_sample[
"pixels"];
43 for(
const auto& j_pixel : j_pixels) {
47 chk_samp.pixel_samples.push_back(pix);
50 chk_samples.push_back(chk_samp);
59 real calculated_depth;
61 real chk_reprojection_error;
69 std::vector<point_sample> point_samples;
72 std::vector<vec2> all_distorted_coordinates;
73 std::vector<vec2> all_undistorted_coordinates;
76 std::cout <<
"processing checkerboards (calculate projected distances, reprojection errors)" << std::endl;
78 for(checkerboard_sample& chk_samp : chk_samples) {
79 checkerboard ir_chk(cols, rows, square_width, chk_samp.corners);
86 for(
const auto& pix : chk_samp.pixel_samples) {
88 s.dist_x = pix.coordinates[0];
89 s.dist_y = pix.coordinates[1];
90 s.measured_depth = pix.measured_depth;
91 s.calculated_depth = pix.calculated_depth;
92 s.chk_reprojection_error = reprojection_error;
95 point_samples.push_back(s);
97 all_distorted_coordinates.push_back(pix.coordinates);
102 std::cout <<
"calculating undistorted points" << std::endl;
103 all_undistorted_coordinates.reserve(all_distorted_coordinates.size());
105 all_distorted_coordinates,
106 all_undistorted_coordinates,
112 auto samp_it = point_samples.begin();
113 for(
const vec2& undist : all_undistorted_coordinates) {
114 point_sample& s = *(samp_it++);
120 std::cout <<
"saving collected pixel depth samples" << std::endl;
122 std::ofstream stream(out_stat_filename);
123 stream <<
"x y measured calculated difference chk_reprojection_err dist_x dist_y chk_rot_x chk_rot_y chk_rot_z chk_t_x chk_t_y chk_t_z\n";
124 stream << std::setprecision(10);
125 for(
const point_sample& samp : point_samples)
129 << samp.measured_depth <<
" " 130 << samp.calculated_depth <<
" " 131 << samp.measured_depth-samp.calculated_depth <<
" " 132 << samp.chk_reprojection_error <<
" " 133 << samp.dist_x <<
" " 134 << samp.dist_y <<
" " 135 << samp.chk_rotation[0] <<
" " 136 << samp.chk_rotation[1] <<
" " 137 << samp.chk_rotation[2] <<
" " 138 << samp.chk_translation[0] <<
" " 139 << samp.chk_translation[1] <<
" " 140 << samp.chk_translation[2] <<
"\n";
143 std::cout <<
"done" << std::endl;
void calculate_checkerboard_pixel_depths(const intrinsics &intr, const checkerboard_extrinsics &ext, std::vector< checkerboard_pixel_depth_sample > &inout_samples)
std::string in_filename_arg()
int main(int argc, const char *argv[])
checkerboard_extrinsics estimate_checkerboard_extrinsics(const checkerboard &chk, const intrinsics &intr)
intrinsics intrinsics_arg()
distortion_parameters distortion
std::vector< vec3 > checkerboard_world_corners(int cols, int rows, real square_width)
std::string out_filename_arg()
std::vector< real > cv_coeffs() const
real checkerboard_reprojection_error(const checkerboard &chk, const intrinsics &intr, const checkerboard_extrinsics &ext)
json import_json_file(const std::string &filename)
void get_args(int argc, const char *argv[], const std::string &usage)