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

#include <compress_component.h>

类 apollo::drivers::smartereye::CompressComponent 继承关系图:
apollo::drivers::smartereye::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.h36 行定义.

成员函数说明

◆ Init()

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

实现了 apollo::cyber::ComponentBase.

在文件 compress_component.cc30 行定义.

30 {
31 if (!GetProtoConfig(&config_)) {
32 AERROR << "Parse config file failed: " << ConfigFilePath();
33 return false;
34 }
35 AINFO << "Camera config: \n" << config_.DebugString();
36 try {
37 image_pool_.reset(new CCObjectPool<CompressedImage>(
38 config_.compress_conf().image_pool_size()));
39 image_pool_->ConstructAll();
40 } catch (const std::bad_alloc& e) {
41 AERROR << e.what();
42 return false;
43 }
44
45 writer_ = node_->CreateWriter<CompressedImage>(
46 config_.compress_conf().output_channel());
47 return true;
48}
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

◆ Proc()

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

在文件 compress_component.cc50 行定义.

50 {
51 ADEBUG << "procing compressed";
52 auto compressed_image = image_pool_->GetObject();
53 compressed_image->mutable_header()->CopyFrom(image->header());
54 compressed_image->set_frame_id(image->frame_id());
55 compressed_image->set_measurement_time(image->measurement_time());
56 compressed_image->set_format(image->encoding() + "; jpeg compressed bgr8");
57
58 std::vector<int> params;
59 params.resize(3, 0);
60 params[0] = cv::IMWRITE_JPEG_QUALITY;
61 params[1] = 95;
62
63 try {
64 cv::Mat mat_image(image->height(), image->width(), CV_8UC3,
65 const_cast<char*>(image->data().data()), image->step());
66 cv::Mat tmp_mat;
67 cv::cvtColor(mat_image, tmp_mat, cv::COLOR_RGB2BGR);
68 std::vector<uint8_t> compress_buffer;
69 if (!cv::imencode(".jpg", tmp_mat, compress_buffer, params)) {
70 AERROR << "cv::imencode (jpeg) failed on input image";
71 return false;
72 }
73 compressed_image->set_data(compress_buffer.data(), compress_buffer.size());
74 writer_->Write(compressed_image);
75 } catch (std::exception& e) {
76 AERROR << "cv::imencode (jpeg) exception :" << e.what();
77 return false;
78 }
79 return true;
80}
#define ADEBUG
Definition log.h:41

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