Apollo  6.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 
21 #include <opencv2/opencv.hpp>
22 
23 #include "cyber/common/log.h"
24 
25 namespace apollo {
26 namespace perception {
27 namespace camera {
28 
29 inline void save_image(const std::string &path, base::Image8U *image) {
30  AINFO << path;
31  int cv_type = image->type() == base::Color::GRAY ? CV_8UC1 : CV_8UC3;
32  cv::Mat cv_img(image->rows(), image->cols(), cv_type,
33  image->mutable_cpu_data(), image->width_step());
34  cv::imwrite(path, cv_img);
35 }
36 
37 inline void save_blob(const std::string &path, base::Blob<uint8_t> *blob) {
38  AINFO << path;
39  blob->Reshape({blob->shape(1), blob->shape(2), blob->shape(3)});
40  int cv_type = blob->shape(2) == 1 ? CV_8UC1 : CV_8UC3;
41  cv::Mat cv_img(blob->shape(0), blob->shape(1), cv_type,
42  blob->mutable_cpu_data());
43  cv::imwrite(path, cv_img);
44 }
45 
46 } // namespace camera
47 } // namespace perception
48 } // namespace apollo
Color type() const
Definition: image_8u.h:119
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
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:29
void save_blob(const std::string &path, base::Blob< uint8_t > *blob)
Definition: camera_common_io_util.h:37
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
#define AINFO
Definition: log.h:42
const std::vector< int > & shape() const
Definition: blob.h:130