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

#include <camera_component.h>

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

Public 成员函数

bool Init () override
 
 ~CameraComponent ()
 
- 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_
 

详细描述

在文件 camera_component.h40 行定义.

构造及析构函数说明

◆ ~CameraComponent()

apollo::drivers::camera::CameraComponent::~CameraComponent ( )

在文件 camera_component.cc161 行定义.

161 {
162 if (running_.load()) {
163 running_.exchange(false);
164 free(raw_image_->image);
165 async_result_.wait();
166 }
167}

成员函数说明

◆ Init()

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

实现了 apollo::cyber::ComponentBase.

在文件 camera_component.cc23 行定义.

23 {
24 camera_config_ = std::make_shared<Config>();
26 camera_config_.get())) {
27 return false;
28 }
29 AINFO << "UsbCam config: " << camera_config_->DebugString();
30
31 camera_device_.reset(new UsbCam());
32 camera_device_->init(camera_config_);
33 raw_image_.reset(new CameraImage);
34 raw_image_for_compress_.reset(new CameraImage);
35
36 raw_image_->width = camera_config_->width();
37 raw_image_->height = camera_config_->height();
38 raw_image_->bytes_per_pixel = camera_config_->bytes_per_pixel();
39
40 raw_image_for_compress_->width = camera_config_->width();
41 raw_image_for_compress_->height = camera_config_->height();
42 raw_image_for_compress_->bytes_per_pixel = camera_config_->bytes_per_pixel();
43
44 if (camera_config_->pixel_format() == "yuyv" ||
45 camera_config_->pixel_format() == "uyvy" ||
46 camera_config_->pixel_format() == "yuvmono10") {
47 raw_image_for_compress_->image_size =
48 raw_image_for_compress_->width * raw_image_for_compress_->height * 2;
49 } else if (camera_config_->pixel_format() == "mjpeg") {
50 AINFO << "Disable sensor raw camera output with format mjpeg";
51 raw_image_for_compress_->image_size = 0;
52 } else if (camera_config_->pixel_format() == "rgb24") {
53 raw_image_for_compress_->image_size =
54 raw_image_for_compress_->width * raw_image_for_compress_->height * 3;
55 } else {
56 AERROR << "Wrong pixel fromat:" << camera_config_->pixel_format()
57 << ",must be yuyv | uyvy | mjpeg | yuvmono10 | rgb24";
58 return false;
59 }
60
61 if (raw_image_for_compress_->image_size == 0) {
62 raw_image_for_compress_->image = nullptr;
63 } else {
64 raw_image_for_compress_->image = reinterpret_cast<char*>(
65 calloc(raw_image_for_compress_->image_size, sizeof(char)));
66 }
67
68 device_wait_ = camera_config_->device_wait_ms();
69 spin_rate_ = static_cast<uint32_t>((1.0 / camera_config_->spin_rate()) * 1e6);
70
71 if (camera_config_->output_type() == YUYV) {
72 raw_image_->image_size = raw_image_->width * raw_image_->height * 2;
73 } else if (camera_config_->output_type() == RGB) {
74 raw_image_->image_size = raw_image_->width * raw_image_->height * 3;
75 }
76 if (raw_image_->image_size > MAX_IMAGE_SIZE) {
77 AERROR << "image size is too big ,must less than " << MAX_IMAGE_SIZE
78 << " bytes.";
79 return false;
80 }
81 raw_image_->is_new = 0;
82 // free memory in this struct desturctor
83 raw_image_->image =
84 reinterpret_cast<char*>(calloc(raw_image_->image_size, sizeof(char)));
85 if (raw_image_->image == nullptr) {
86 AERROR << "system calloc memory error, size:" << raw_image_->image_size;
87 return false;
88 }
89
90 for (int i = 0; i < buffer_size_; ++i) {
91 auto pb_image = std::make_shared<Image>();
92 pb_image->mutable_header()->set_frame_id(camera_config_->frame_id());
93 pb_image->set_width(raw_image_->width);
94 pb_image->set_height(raw_image_->height);
95 pb_image->mutable_data()->reserve(raw_image_->image_size);
96
97 if (camera_config_->output_type() == YUYV) {
98 pb_image->set_encoding("yuyv");
99 pb_image->set_step(2 * raw_image_->width);
100 } else if (camera_config_->output_type() == RGB) {
101 pb_image->set_encoding("rgb8");
102 pb_image->set_step(3 * raw_image_->width);
103 }
104
105 pb_image_buffer_.push_back(pb_image);
106
107 auto raw_image = std::make_shared<Image>();
108 raw_image->mutable_header()->set_frame_id(camera_config_->frame_id());
109 raw_image->set_width(raw_image_for_compress_->width);
110 raw_image->set_height(raw_image_for_compress_->height);
111 raw_image->mutable_data()->reserve(raw_image_for_compress_->image_size);
112 raw_image->set_encoding(camera_config_->pixel_format());
113
114 raw_image_buffer_.push_back(raw_image);
115 }
116
117 writer_ = node_->CreateWriter<Image>(camera_config_->channel_name());
118 raw_writer_ = node_->CreateWriter<Image>(camera_config_->raw_channel_name());
119 async_result_ = cyber::Async(&CameraComponent::run, this);
120 return true;
121}
std::shared_ptr< Node > node_
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132

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