34 {
35
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_);
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
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_
std::string config_file_path_
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,...