1 #include "../lib/common.h" 2 #include "../lib/args.h" 3 #include "../lib/opencv.h" 4 #include "../lib/json.h" 5 #include "../lib/misc.h" 6 #include "../lib/viewer.h" 7 #include "lib/common.h" 24 std::size_t x_count = depth.cols, y_count = depth.rows;
26 real min_d = INFINITY;
29 std::vector<real> depth_samples;
30 depth_samples.reserve(x_count * y_count);
31 std::vector<real> hmeans(x_count, 0.0), vmeans(y_count, 0.0);
32 std::vector<std::size_t> hcounts(x_count, 0), vcounts(y_count, 0);
33 for(std::ptrdiff_t y = 0; y < y_count; ++y)
34 for(std::ptrdiff_t x = 0; x < x_count; ++x) {
36 if(d == 0.0)
continue;
43 if(d < min_d) min_d = d;
44 if(d > max_d) max_d = d;
47 for(std::ptrdiff_t y = 0; y < y_count; ++y) vmeans[y] /= vcounts[y];
48 for(std::ptrdiff_t x = 0; x < x_count; ++x) hmeans[x] /= hcounts[x];
52 std::vector<cv::Vec2f> points; points.reserve(x_count);
53 for(std::ptrdiff_t x = 0; x < x_count; ++x)
54 if(! std::isnan(hmeans[x])) points.emplace_back(x, hmeans[x]);
56 cv::fitLine(points, params, CV_DIST_L2, 0, 0.01, 0.01);
57 hslope = params[1] / params[0];
61 std::vector<cv::Vec2f> points; points.reserve(y_count);
62 for(std::ptrdiff_t y = 0; y < y_count; ++y)
63 if(! std::isnan(vmeans[y])) points.emplace_back(y, vmeans[y]);
65 cv::fitLine(points, params, CV_DIST_L2, 0, 0.01, 0.01);
66 vslope = params[1] / params[0];
78 int main(
int argc,
const char* argv[]) {
79 get_args(argc, argv,
"reprojection.json");
82 std::cout <<
"loading reprojection parameters" << std::endl;
88 viewer view(
"Parallel to Wall", 754+754, 424);
92 auto& indicator_precision_slider = view.
add_real_slider(
"precision", 1.0, 0.1, 2.0);
95 cv::Mat_<real> reprojected_depth;
96 cv::Mat_<cv::Vec3b> shown_reprojected_depth;
108 densifier->densify(samples, reprojected_depth);
113 int min_x = border_x_slider, max_x =
texture_width - border_x_slider;
114 int min_y = border_y_slider, max_y =
texture_height - border_y_slider;
116 cv::Rect roi(min_x, min_y, max_x - min_x, max_y - min_y);
117 cv::Mat_<real> depth_roi = reprojected_depth(roi);
123 cv::Mat_<cv::Vec3b> shown_reprojected_depth_col;
124 cv::cvtColor(shown_reprojected_depth, shown_reprojected_depth_col, CV_GRAY2BGR);
126 cv::rectangle(shown_reprojected_depth_col, roi, cv::Scalar(view.
indicator_color), 4);
129 view.
draw(cv::Rect(0, 0, 754, 424), color);
130 cv::Rect depth_rect(754, 0, 754, 424);
131 view.
draw(depth_rect, shown_reprojected_depth_col);
137 running = view.
show();
real_slider & add_real_slider(const std::string &caption, real default_val, real min_val, real max_val, int steps=100)
std::unique_ptr< depth_densify_base > make_depth_densify(const std::string &method)
cv::Mat_< cv::Vec3b > get_color_frame()
constexpr std::size_t texture_height
kinect_reprojection_parameters decode_kinect_reprojection_parameters(const json &j_parameters)
static cv::Mat_< uchar > visualize_depth(const cv::Mat &, float min_d, float max_d)
void draw_2d_cross_indicator(cv::Rect rect, real value_x, real value_y, real max_abs_value)
void draw(const cv::Mat_< cv::Vec3b > &, real blend=1.0)
int main(int argc, const char *argv[])
cv::Vec3b indicator_color
cv::Mat_< float > get_depth_frame(bool undistorted=false)
constexpr std::size_t texture_width
computation_result compute_depth_slopes(const cv::Mat_< real > &depth)
int_slider & add_int_slider(const std::string &caption, int default_val, int min_val, int max_val, int step=1)
std::vector< sample< Value > > reproject_ir_to_color_samples(const cv::Mat_< Value > &distorted_ir_values, const cv::Mat_< Depth > &distorted_ir_z, bool distort_color=true) const
void clear(int width, int height)
json import_json_file(const std::string &filename)
std::string in_filename_opt_arg(const std::string &def="")
void get_args(int argc, const char *argv[], const std::string &usage)