rgbd
rgbd_to_png.cpp
Go to the documentation of this file.
1 #include <rgbd/serialization.h>
2 #include <rgbd/image.h>
3 #include <rgbd/view.h>
4 
5 #include <fstream>
6 
7 #include <opencv2/highgui/highgui.hpp>
8 
9 int main(int argc, char **argv) {
10 
11  if (argc < 2)
12  {
13  std::cout << "Usage:\n\n rgbd_to_rgb_png FILENAME\n\n";
14  return 1;
15  }
16 
17  for (int i = 1; i < argc; ++i)
18  {
19  std::string name = std::string(argv[i]);
20 
21  // read
22  std::ifstream f_in;
23  f_in.open(name.c_str(), std::ifstream::binary);
24 
25  if (!f_in.is_open())
26  {
27  std::cerr << "Could not open '" << name << "'." << std::endl;
28  continue;
29  }
30 
32 
33  rgbd::Image image;
34  rgbd::deserialize(a_in, image);
35 
36 
37  size_t lastindex = name.find_last_of(".");
38  name = name.substr(0, lastindex);
39 
40  // write rgb image
41  std::string rgb_filename = name + "_rgb.png";
42 
43  if (cv::imwrite(rgb_filename, image.getRGBImage()))
44  std::cout << "Succesfully stored '" << rgb_filename << "'" << std::endl;
45  else
46  std::cerr << "Failed to write rgbd to rgb png" << std::endl;
47 
48  // write depth image
49  std::string depth_filename = name + "_depth.png";
50 
51  if (cv::imwrite(depth_filename, image.getDepthImage()))
52  std::cout << "Succesfully stored '" << depth_filename << "'" << std::endl;
53  else
54  std::cerr << "Failed to write rgbd to depth png" << std::endl;
55  }
56 
57  return 0;
58 }
fstream
std::string
rgbd::Image::getDepthImage
const cv::Mat & getDepthImage() const
Get the depth image.
Definition: image.h:72
rgbd::deserialize
bool deserialize(tue::serialization::InputArchive &a, Image &image)
Definition: serialization.cpp:174
std::cerr
std::cout
main
int main(int argc, char **argv)
Definition: rgbd_to_png.cpp:9
rgbd::Image
Definition: image.h:43
std::string::c_str
T c_str(T... args)
std::string::find_last_of
T find_last_of(T... args)
std::ifstream::open
T open(T... args)
image.h
rgbd::Image::getRGBImage
const cv::Mat & getRGBImage() const
Get the RGB color image.
Definition: image.h:78
std::string::substr
T substr(T... args)
tue::serialization::InputArchive
std::endl
T endl(T... args)
view.h
serialization.h
std::ifstream::is_open
T is_open(T... args)
std::ifstream