1 #include "../lib/common.h" 2 #include "../lib/args.h" 3 #include <opencv2/opencv.hpp> 14 while(length--) output.put(0);
19 std::ofstream output(filename, std::ios::binary);
20 std::streamsize sz = mat.cols * mat.rows;
21 output.write(reinterpret_cast<const std::ofstream::char_type*>(mat.data), sz);
25 std::ofstream output(filename, std::ios::binary);
26 std::streamsize sz = mat.cols * mat.rows * 2;
27 output.write(reinterpret_cast<const std::ofstream::char_type*>(mat.data), sz);
32 template<
typename Distance,
typename Depth>
34 const cv::Mat_<Distance>& in_z,
35 cv::Mat_<Depth>& out_d,
39 const real z_diff = z_far - z_near;
40 const real offset = ((d_far * z_far) - (d_near * z_near)) / z_diff;
41 const real factor = ((d_near - d_far) * z_near * z_far) / z_diff;
43 cv::Mat_<real> z_real = in_z;
44 cv::Mat_<real> d_real = offset + factor / z_real;
50 int main(
int argc,
const char* argv[]) {
51 get_args(argc, argv,
"depth.png out_disparity.yuv z_near z_far [8/16]");
56 bool output_disparity_16bit = (
enum_opt_arg({
"8",
"16"},
"8") ==
"16");
58 cv::Mat_<ushort> depth;
60 cv::Mat depth_ = cv::imread(input_filename, CV_LOAD_IMAGE_ANYDEPTH);
61 if(depth_.depth() != CV_16U)
throw std::runtime_error(
"input depth map: must be 16 bit");
65 if(output_disparity_16bit) {
66 cv::Mat_<ushort> disparity;
67 orthogonal_distance_to_depth<ushort, ushort>(depth, disparity, 0xffff, 0, z_near, z_far);
68 disparity.setTo(0, depth == 0);
72 cv::Mat_<uchar> disparity;
73 orthogonal_distance_to_depth<ushort, uchar>(depth, disparity, 0xff, 0, z_near, z_far);
74 disparity.setTo(0, depth == 0);
void orthogonal_distance_to_depth(const cv::Mat_< Distance > &in_z, cv::Mat_< Depth > &out_d, real d_near, real d_far, real z_near, real z_far)
std::string in_filename_arg()
int main(int argc, const char *argv[])
void export_yuv_disparity(std::string filename, const cv::Mat_< uchar > &mat)
std::string enum_opt_arg(const std::vector< std::string > &options, const std::string &def)
void append_null_tail(std::ostream &output, std::streamsize length)
std::string out_filename_arg()
void get_args(int argc, const char *argv[], const std::string &usage)