52 image_ = std::shared_ptr<cv::Mat>(
new cv::Mat(width, height, CV_32F, 0.f));
55 image_ = std::shared_ptr<cv::Mat>(
56 new cv::Mat(width, height, CV_32FC3, CV_RGB(0.f, 0.f, 0.f)));
61 Image::Image(
const std::string& filename,
bool grayscale) : grayscale_(false) {
62 image_ = std::shared_ptr<cv::Mat>(
new cv::Mat());
63 Read(filename, grayscale);
68 image_ = std::shared_ptr<cv::Mat>(
new cv::Mat(other));
73 CHECK(
image_.get()) <<
"Image data is not allocated.";
76 cv::cvtColor(*
image_, out, CV_RGB2BGR);
80 CHECK(
image_.get()) <<
"Image data is not allocated.";
83 cv::cvtColor(in, *
image_, CV_BGR2RGB);
87 CHECK(
image_.get()) <<
"Image data is not allocated.";
91 void Image::Read(
const std::string& filename,
bool grayscale) {
93 *
image_ = cv::imread(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE);
98 *
image_ = cv::imread(filename.c_str(), CV_LOAD_IMAGE_COLOR);
103 CHECK(
image_->data) <<
"Unable to read image file.";
110 cv::imwrite(filename.c_str(), *
image_);
114 CHECK(
image_.get()) <<
"Image data is not allocated.";
119 CHECK(
image_.get()) <<
"Image data is not allocated.";
124 CHECK(
image_.get()) <<
"Image data is not allocated.";
125 return image_->channels();
129 CHECK(
image_.get()) <<
"Image data is not allocated.";
130 cv::resize(*
image_, *
image_, cv::Size(), scale, scale, CV_INTER_LANCZOS4);
134 CHECK(
image_.get()) <<
"Image data is not allocated.";
135 cv::resize(*
image_, *
image_, cv::Size(new_width, new_height),
140 CHECK(
image_.get()) <<
"Image data is not allocated.";
145 CHECK(
image_.get()) <<
"Image data is not allocated.";
151 CHECK(
image_.get()) <<
"Image data is not allocated.";
157 CHECK(
image_.get()) <<
"Image data is not allocated.";
162 CHECK(
image_.get()) <<
"Image data is not allocated.";
167 CHECK(
image_.get()) <<
"Image data is not allocated.";
170 VLOG(1) <<
"Cannot convert image to grayscale, image is already grayscale.";
179 CHECK(
image_.get()) <<
"Image data is not allocated.";
182 VLOG(1) <<
"Cannot convert image to RGB, image is already RGB.";
190 void Image::ImShow(
const std::string& window_name,
unsigned int wait_time) {
191 CHECK(
image_.get()) <<
"Image data is not allocated.";
193 cv::namedWindow(window_name.c_str(), CV_WINDOW_AUTOSIZE);
199 cv::imshow(window_name.c_str(), bgr_image);
201 cv::imshow(window_name.c_str(), *
image_);
204 cv::waitKey(wait_time);
std::shared_ptr< cv::Mat > image_
void RotateCounterClockwise()
void Write(const std::string &filename) const
void FromCV(const cv::Mat &in)
void Resize(double scale)
void ToEigen(MatrixXf &eigen_out)
void Read(const std::string &filename, bool grayscale=false)
void ConvertToGrayscale()
void OpenCVToEigenMat(const cv::Mat &cv_mat, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &eigen_mat)
void ImShow(const std::string &window_name=std::string(), unsigned int wait_time=0)
void ToCV(cv::Mat &out) const