Apollo  v5.5.0
Open source self driving car software
camera_common_io_util.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 #pragma once
17 
18 #include <string>
19 #include "gtest/gtest.h"
20 #include "opencv2/opencv.hpp"
21 
22 #include "cyber/common/log.h"
23 
24 namespace apollo {
25 namespace perception {
26 namespace camera {
27 
28 inline void save_image(const std::string &path, base::Image8U *image) {
29  AINFO << path;
30  int cv_type = image->type() == base::Color::GRAY ? CV_8UC1 : CV_8UC3;
31  cv::Mat cv_img(image->rows(), image->cols(), cv_type,
32  image->mutable_cpu_data(), image->width_step());
33  cv::imwrite(path, cv_img);
34 }
35 
36 inline void save_blob(const std::string &path, base::Blob<uint8_t> *blob) {
37  AINFO << path;
38  blob->Reshape({blob->shape(1), blob->shape(2), blob->shape(3)});
39  int cv_type = blob->shape(2) == 1 ? CV_8UC1 : CV_8UC3;
40  cv::Mat cv_img(blob->shape(0), blob->shape(1), cv_type,
41  blob->mutable_cpu_data());
42  cv::imwrite(path, cv_img);
43 }
44 
45 } // namespace camera
46 } // namespace perception
47 } // namespace apollo
Color type() const
Definition: image_8u.h:119
Definition: blob.h:72
A wrapper around Blob holders serving as the basic computational unit for images. ...
Definition: image_8u.h:44
void save_image(const std::string &path, base::Image8U *image)
Definition: camera_common_io_util.h:28
void save_blob(const std::string &path, base::Blob< uint8_t > *blob)
Definition: camera_common_io_util.h:36
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
int cols() const
Definition: image_8u.h:121
int width_step() const
Definition: image_8u.h:123
uint8_t * mutable_cpu_data()
Definition: image_8u.h:95
int rows() const
Definition: image_8u.h:120
const std::vector< int > & shape() const
Definition: blob.h:130