Apollo 10.0
自动驾驶开放平台
apollo::drivers::camera::CompressComponent类 参考

#include <compress_component.h>

类 apollo::drivers::camera::CompressComponent 继承关系图:
apollo::drivers::camera::CompressComponent 的协作图:

Public 成员函数

bool Init () override
 
bool Proc (const std::shared_ptr< Image > &image) override
 
- Public 成员函数 继承自 apollo::cyber::Component< M0, M1, M2, M3 >
 Component ()
 
 ~Component () override
 
bool Initialize (const ComponentConfig &config) override
 init the component by protobuf object.
 
bool Process (const std::shared_ptr< M0 > &msg0, const std::shared_ptr< M1 > &msg1, const std::shared_ptr< M2 > &msg2, const std::shared_ptr< M3 > &msg3)
 
- Public 成员函数 继承自 apollo::cyber::ComponentBase
virtual ~ComponentBase ()
 
virtual bool Initialize (const TimerComponentConfig &config)
 
virtual void Shutdown ()
 
template<typename T >
bool GetProtoConfig (T *config) const
 

额外继承的成员函数

- Public 类型 继承自 apollo::cyber::ComponentBase
template<typename M >
using Reader = cyber::Reader< M >
 
- Protected 成员函数 继承自 apollo::cyber::ComponentBase
virtual void Clear ()
 
const std::string & ConfigFilePath () const
 
void LoadConfigFiles (const ComponentConfig &config)
 
void LoadConfigFiles (const TimerComponentConfig &config)
 
- Protected 属性 继承自 apollo::cyber::ComponentBase
std::atomic< bool > is_shutdown_ = {false}
 
std::shared_ptr< Nodenode_ = nullptr
 
std::string config_file_path_ = ""
 
std::vector< std::shared_ptr< ReaderBase > > readers_
 

详细描述

在文件 compress_component.h38 行定义.

成员函数说明

◆ Init()

bool apollo::drivers::camera::CompressComponent::Init ( )
overridevirtual

实现了 apollo::cyber::ComponentBase.

在文件 compress_component.cc31 行定义.

31 {
32 if (!GetProtoConfig(&config_)) {
33 AERROR << "Parse config file failed: " << ConfigFilePath();
34 return false;
35 }
36 AINFO << "Camera config: \n" << config_.DebugString();
37 try {
38 image_pool_.reset(new CCObjectPool<CompressedImage>(
39 config_.compress_conf().image_pool_size()));
40 image_pool_->ConstructAll();
41 } catch (const std::bad_alloc& e) {
42 AERROR << e.what();
43 return false;
44 }
45
46 width_ = config_.compress_conf().width();
47 height_ = config_.compress_conf().height();
48
49 writer_ = node_->CreateWriter<CompressedImage>(
50 config_.compress_conf().output_channel());
51
52 return true;
53}
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
optional CompressConfig compress_conf
Definition config.proto:58

◆ Proc()

bool apollo::drivers::camera::CompressComponent::Proc ( const std::shared_ptr< Image > &  image)
override

在文件 compress_component.cc55 行定义.

55 {
56 ADEBUG << "procing compressed";
58 image->height() != height_ || image->width() != width_)) {
59 AERROR << "Setting resolution is " << width_ << "x" << height_ <<
60 ", but received " << image->width() << "x" << image->height();
61 return false;
62 }
63 auto compressed_image = image_pool_->GetObject();
64 compressed_image->mutable_header()->CopyFrom(image->header());
65 compressed_image->set_frame_id(image->frame_id());
66 compressed_image->set_measurement_time(image->measurement_time());
67 compressed_image->set_height(height_);
68 compressed_image->set_width(width_);
69
70 compressed_image->set_format(image->encoding() + "; jpeg compressed bgr8");
71
72 std::vector<int> params;
73 params.resize(3, 0);
74 params[0] = cv::IMWRITE_JPEG_QUALITY;
75 params[1] = 95;
76
77 try {
78 cv::Mat mat_image(image->height(), image->width(), CV_8UC3,
79 const_cast<char*>(image->data().data()), image->step());
80 cv::Mat tmp_mat;
81 cv::cvtColor(mat_image, tmp_mat, cv::COLOR_RGB2BGR);
82 std::vector<uint8_t> compress_buffer;
83 if (!cv::imencode(".jpg", tmp_mat, compress_buffer, params)) {
84 AERROR << "cv::imencode (jpeg) failed on input image";
85 return false;
86 }
87 compressed_image->set_data(compress_buffer.data(), compress_buffer.size());
88 } catch (std::exception& e) {
89 AERROR << "cv::imencode (jpeg) exception :" << e.what();
90 return false;
91 }
92
93 writer_->Write(compressed_image);
94 return true;
95}
#define cyber_unlikely(x)
Definition macros.h:30
#define ADEBUG
Definition log.h:41

该类的文档由以下文件生成: