1 #include "../lib/args.h" 2 #include "../lib/intrinsics.h" 3 #include "../lib/viewer.h" 4 #include "../lib/json.h" 13 int main(
int argc,
const char* argv[]) {
14 get_args(argc, argv,
"ir_intrinsics.json/internal ir/depth");
15 std::string ir_intrinsics_filename =
string_arg();
18 bool show_depth = (mode ==
"depth");
22 viewer view(512+512, 20+424);
23 int max_possible_val = (show_depth ? 6000 : 0xffff);
24 int min_possible_val = 0;
25 auto& min_val = view.
add_int_slider((show_depth ?
"depth min" :
"ir min"), 0, min_possible_val, max_possible_val);
26 auto& max_val = view.
add_int_slider((show_depth ?
"depth max" :
"ir max"), max_possible_val, min_possible_val, max_possible_val);
30 std::vector<real> distortion_coeffs;
31 if(ir_intrinsics_filename ==
"internal") {
38 distortion_coeffs = { par.k1, par.k2, par.p1, par.p2, par.k3 };
41 camera_mat = ir_intr.
K;
50 cv::Mat_<cv::Vec3b> raw_img, undistorted_img;
53 cv::cvtColor(viz_depth, raw_img, CV_GRAY2BGR);
55 cv::cvtColor(grab.
get_ir_frame(min_val.value(), max_val.value(),
false), raw_img, CV_GRAY2BGR);
61 cv::undistort(raw_img, undistorted_img, camera_mat, distortion_coeffs, camera_mat);
63 if(offset.value() > 3) {
64 int off = offset.value();
65 std::vector<cv::Point2f> raw_pts, undistorted_pts;
66 for(
int x = 512/2; x >= 0; x -= off) {
67 for(
int y = 424/2; y >= 0; y -= off) raw_pts.emplace_back(x, y);
68 for(
int y = 424/2; y < 424; y += off) raw_pts.emplace_back(x, y);
70 for(
int x = 512/2; x < 512; x += off) {
71 for(
int y = 424/2; y >= 0; y -= off) raw_pts.emplace_back(x, y);
72 for(
int y = 424/2; y < 424; y += off) raw_pts.emplace_back(x, y);
75 cv::undistortPoints(raw_pts, undistorted_pts, camera_mat, distortion_coeffs, cv::noArray(), camera_mat);
77 cv::Vec3b raw_point_color(255, 200, 200);
78 cv::Vec3b undistorted_point_color(200, 200, 255);
79 for(
const cv::Point2f& pt : raw_pts) cv::circle(raw_img, pt, 4, cv::Scalar(raw_point_color), 2);
80 for(
const cv::Point2f& pt : undistorted_pts) cv::circle(undistorted_img, pt, 4, cv::Scalar(undistorted_point_color), 2);
84 view.
draw(cv::Rect(0, 20, 512, 424), raw_img);
87 view.
draw(cv::Rect(512, 20, 512, 424), undistorted_img);
cv::Mat_< uchar > get_ir_frame(float min_ir=0, float max_ir=0xffff, bool undistorted=false)
static cv::Mat_< uchar > visualize_depth(const cv::Mat &, float min_d, float max_d)
void draw(const cv::Mat_< cv::Vec3b > &, real blend=1.0)
kinect_internal_parameters internal_parameters()
std::string enum_arg(const std::vector< std::string > &options)
int main(int argc, const char *argv[])
cv::Mat_< float > get_depth_frame(bool undistorted=false)
struct tlz::kinect_internal_parameters::@1 ir
distortion_parameters distortion
cv::Matx< real, 3, 3 > mat33
feature_points undistort(const feature_points &dist_fpoints, const intrinsics &intr)
std::vector< real > cv_coeffs() const
void draw_text(cv::Rect rect, const std::string &text, text_alignment=left)
intrinsics decode_intrinsics(const json &j_intr)
int_slider & add_int_slider(const std::string &caption, int default_val, int min_val, int max_val, int step=1)
void clear(int width, int height)
json import_json_file(const std::string &filename)
void get_args(int argc, const char *argv[], const std::string &usage)