Apollo 10.0
自动驾驶开放平台
image_decompress.cc
浏览该文件的文档.
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
18
19#include <vector>
20
21#include "opencv2/opencv.hpp"
22
23namespace apollo {
24namespace image_decompress {
25
27
29 if (!GetProtoConfig(&config_)) {
30 AERROR << "Parse config file failed: " << ConfigFilePath();
31 return false;
32 }
33 AINFO << "Decompress config: \n" << config_.DebugString();
34 writer_ = node_->CreateWriter<Image>(config_.channel_name());
35 return true;
36}
37
39 const std::shared_ptr<apollo::drivers::CompressedImage>& compressed_image) {
40 auto image = std::make_shared<Image>();
41 image->mutable_header()->CopyFrom(compressed_image->header());
42 if (compressed_image->has_measurement_time()) {
43 image->set_measurement_time(compressed_image->measurement_time());
44 } else {
45 image->set_measurement_time(compressed_image->header().timestamp_sec());
46 }
47 std::vector<uint8_t> compressed_raw_data(compressed_image->data().begin(),
48 compressed_image->data().end());
49 cv::Mat mat_image = cv::imdecode(compressed_raw_data, cv::IMREAD_COLOR);
50 cv::cvtColor(mat_image, mat_image, cv::COLOR_BGR2RGB);
51 image->set_width(mat_image.cols);
52 image->set_height(mat_image.rows);
53 // Now olny rgb
54 image->set_encoding("rgb8");
55 image->set_step(3 * image->width());
56
57 auto size = mat_image.step * mat_image.rows;
58 image->set_data(&(mat_image.data[0]), size);
59 writer_->Write(image);
60 return true;
61}
62
63} // namespace image_decompress
64} // namespace apollo
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
bool Proc(const std::shared_ptr< apollo::drivers::CompressedImage > &image) override
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37