Apollo 11.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< Node > node_ = nullptr
 
std::string config_file_path_ = ""
 
std::vector< std::shared_ptr< ReaderBase > > readers_
 

详细描述

在文件 camera_component.h 第 34 行定义.

构造及析构函数说明

◆ ~CameraComponent()

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

在文件 camera_component.cc 第 186 行定义.

186 {
187 if (running_.load()) {
188 running_.exchange(false);
189#ifndef __aarch64__
190 free(raw_image_->image);
191#else
192 cudaFreeHost(raw_image_->image);
193#endif
194 async_result_.wait();
195 }
196}

成员函数说明

◆ Init()

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

实现了 apollo::cyber::ComponentBase.

在文件 camera_component.cc 第 34 行定义.

34 {
35 // hook: Apollo License Verification: v_apollo_park
36 camera_config_ = std::make_shared<Config>();
38 return false;
39 }
40 AINFO << "UsbCam config: " << camera_config_->DebugString();
41
42 camera_device_.reset(new UsbCam());
43 camera_device_->init(camera_config_);
44 raw_image_.reset(new CameraImage);
45 raw_image_for_compress_.reset(new CameraImage);
46
47 raw_image_->width = camera_config_->width();
48 raw_image_->height = camera_config_->height();
49 raw_image_->bytes_per_pixel = camera_config_->bytes_per_pixel();
50
51 raw_image_for_compress_->width = camera_config_->width();
52 raw_image_for_compress_->height = camera_config_->height();
53 raw_image_for_compress_->bytes_per_pixel = camera_config_->bytes_per_pixel();
54
55 if (camera_config_->pixel_format() == "yuyv" || camera_config_->pixel_format() == "uyvy"
56 || camera_config_->pixel_format() == "yuvmono10") {
57 raw_image_for_compress_->image_size = raw_image_for_compress_->width * raw_image_for_compress_->height * 2;
58 } else if (camera_config_->pixel_format() == "mjpeg") {
59 AINFO << "Disable sensor raw camera output with format mjpeg";
60 raw_image_for_compress_->image_size = 0;
61 } else if (camera_config_->pixel_format() == "rgb24") {
62 raw_image_for_compress_->image_size = raw_image_for_compress_->width * raw_image_for_compress_->height * 3;
63 } else {
64 AERROR << "Wrong pixel fromat:" << camera_config_->pixel_format()
65 << ",must be yuyv | uyvy | mjpeg | yuvmono10 | rgb24";
66 return false;
67 }
68
69 if (raw_image_for_compress_->image_size == 0) {
70 raw_image_for_compress_->image = nullptr;
71 } else {
72 raw_image_for_compress_->image
73 = reinterpret_cast<char*>(calloc(raw_image_for_compress_->image_size, sizeof(char)));
74 }
75
76 device_wait_ = camera_config_->device_wait_ms();
77 spin_rate_ = static_cast<uint32_t>((1.0 / camera_config_->spin_rate()) * 1e6);
78
79 if (camera_config_->output_type() == YUYV) {
80 raw_image_->image_size = raw_image_->width * raw_image_->height * 2;
81 } else if (camera_config_->output_type() == RGB) {
82 raw_image_->image_size = raw_image_->width * raw_image_->height * 3;
83 }
84 if (raw_image_->image_size > MAX_IMAGE_SIZE) {
85 AERROR << "image size is too big ,must less than " << MAX_IMAGE_SIZE << " bytes.";
86 return false;
87 }
88 raw_image_->is_new = 0;
89 // free memory in this struct desturctor
90#ifndef __aarch64__
91 raw_image_->image = reinterpret_cast<char*>(calloc(raw_image_->image_size, sizeof(char)));
92 if (raw_image_->image == nullptr) {
93 AERROR << "system calloc memory error, size:" << raw_image_->image_size;
94 return false;
95 }
96#else
97 if (camera_config_->arm_gpu_acceleration()) {
98 if (cudaMallocHost(&raw_image_->image, raw_image_->image_size * sizeof(char), cudaHostAllocMapped)
99 != cudaSuccess) {
100 AERROR << "cuda malloc memory error, size:" << raw_image_->image_size;
101 return false;
102 }
103 } else {
104 raw_image_->image = reinterpret_cast<char*>(calloc(raw_image_->image_size, sizeof(char)));
105 if (raw_image_->image == nullptr) {
106 AERROR << "system calloc memory error, size:" << raw_image_->image_size;
107 return false;
108 }
109 }
110#endif
111
112 writer_ = node_->CreateWriter<Image>(camera_config_->channel_name());
113 raw_writer_ = node_->CreateWriter<Image>(camera_config_->raw_channel_name());
114
115 async_result_ = cyber::Async(&CameraComponent::run, this);
116 return true;
117}
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

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