licornea_tools
image_io.cc
Go to the documentation of this file.
1 #include "image_io.h"
2 #include <stdexcept>
3 
4 namespace tlz {
5 
6 cv::Mat_<cv::Vec3b> load_texture(const std::string& filename) {
7  cv::Mat mat = cv::imread(filename, CV_LOAD_IMAGE_COLOR);
8  if(mat.empty()) throw std::runtime_error("could not load texture " + filename);
9  cv::Mat_<cv::Vec3b> mat_ = mat;
10  return mat_;
11 }
12 
13 void save_texture(const std::string& filename, const cv::Mat_<cv::Vec3b>& texture) {
14  std::vector<int> params = { CV_IMWRITE_PNG_COMPRESSION, 0 };
15  cv::imwrite(filename, texture, params);
16 }
17 
19 
20 cv::Mat_<ushort> load_ir(const std::string& filename) {
21  cv::Mat mat = cv::imread(filename, CV_LOAD_IMAGE_ANYDEPTH);
22  if(mat.empty()) throw std::runtime_error("could not load ir image " + filename);
23  if(mat.depth() != CV_16U) throw std::runtime_error("input ir image " + filename + " is not must be 16 bit");
24  cv::Mat_<ushort> mat_ = mat;
25  return mat_;
26 }
27 
28 void save_ir(const std::string& filename, const cv::Mat_<ushort>& ir) {
29  std::vector<int> params = { CV_IMWRITE_PNG_COMPRESSION, 0 };
30  cv::imwrite(filename, ir, params);
31 }
32 
34 
35 cv::Mat_<ushort> load_depth(const std::string& filename) {
36  cv::Mat mat = cv::imread(filename, CV_LOAD_IMAGE_ANYDEPTH);
37  if(mat.empty()) throw std::runtime_error("could not load depth map " + filename);
38  if(mat.depth() != CV_16U) throw std::runtime_error("input depth map " + filename + " is not must be 16 bit");
39  cv::Mat_<ushort> mat_ = mat;
40  return mat_;
41 }
42 
43 void save_depth(const std::string& filename, const cv::Mat_<ushort>& depth) {
44  std::vector<int> params = { CV_IMWRITE_PNG_COMPRESSION, 0 };
45  cv::imwrite(filename, depth, params);
46 }
47 
48 }
void save_depth(const std::string &filename, const cv::Mat_< ushort > &depth)
Definition: image_io.cc:43
void save_texture(const std::string &filename, const cv::Mat_< cv::Vec3b > &texture)
Definition: image_io.cc:13
cv::Mat_< ushort > load_ir(const std::string &filename)
Definition: image_io.cc:20
cv::Mat_< ushort > load_depth(const std::string &filename)
Definition: image_io.cc:35
void save_ir(const std::string &filename, const cv::Mat_< ushort > &ir)
Definition: image_io.cc:28
cv::Mat_< cv::Vec3b > load_texture(const std::string &filename)
Definition: image_io.cc:6