-
Notifications
You must be signed in to change notification settings - Fork 31
/
transform_by_disparity.cc
90 lines (78 loc) · 3.49 KB
/
transform_by_disparity.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <vw/Core.h>
#include <vw/Image.h>
#include <vw/FileIO.h>
#include <vw/Stereo/PreFilter.h>
#include <vw/Stereo/CorrelationView.h>
#include <vw/Stereo/DisparityMap.h>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
using namespace vw;
template <class ImageT>
void block_write_image( const std::string &filename,
vw::ImageViewBase<ImageT> const& image,
vw::ProgressCallback const& progress_callback = vw::ProgressCallback::dummy_instance() ) {
boost::scoped_ptr<vw::DiskImageResourceGDAL> rsrc
(new vw::DiskImageResourceGDAL(filename, image.impl().format(), Vector2i(256,256)));
vw::block_write_image( *rsrc, image.impl(), progress_callback );
}
int main(int argc, char **argv) {
try {
std::string left_file_name, right_file_name, disparity_file_name, tag;
po::options_description desc("Options");
desc.add_options()
("help,h", "Display this help message")
("left", po::value(&left_file_name), "Explicitly specify the \"left\" input file")
("right", po::value(&right_file_name), "Explicitly specify the \"right\" input file")
("disparity", po::value(&disparity_file_name), "Explicitly specify the disparity input file")
("tag", po::value(&tag)->default_value("transformed"), "Output prefix");
po::positional_options_description p;
p.add("left", 1);
p.add("right", 1);
p.add("disparity", 1);
p.add("tag", 1);
po::variables_map vm;
try {
po::store( po::command_line_parser( argc, argv ).options(desc).positional(p).run(), vm );
po::notify( vm );
} catch (const po::error& e) {
std::cout << "An error occured while parsing command line arguments.\n";
std::cout << "\t" << e.what() << "\n\n";
std::cout << desc << std::endl;
return 1;
}
if( vm.count("help") ) {
vw_out() << desc << std::endl;
return 1;
}
if ( vm.count("left") != 1 || vm.count("right") != 1 || vm.count("disparity") != 1) {
vw_out() << "Error: Must specify one (and only one) left, right, and disparity input file!" << std::endl;
vw_out() << desc << std::endl;
return 1;
}
DiskImageView<float> left_disk_image(left_file_name );
DiskImageView<float> right_disk_image(right_file_name );
boost::shared_ptr<DiskImageResource>
disp_rsrc(DiskImageResource::open(disparity_file_name));
disp_rsrc->set_rescale(false);
DiskImageView<PixelMask<Vector2f> > disparity_disk_image(disp_rsrc);
block_write_image(tag + "-tfm.tif",
crop(transform(right_disk_image,
stereo::DisparityTransform
(disparity_disk_image)),
BBox2i(0, 0, left_disk_image.cols(),
left_disk_image.rows())),
TerminalProgressCallback("","Rendering:"));
block_write_image(tag + "-tfm-diff.tif",
abs(left_disk_image -
crop(transform(right_disk_image,
stereo::DisparityTransform
(disparity_disk_image)),
BBox2i(0, 0, left_disk_image.cols(),
left_disk_image.rows()))),
TerminalProgressCallback("","Rendering:"));
} catch (const vw::Exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}