24 camera_config_ = std::make_shared<Config>();
26 camera_config_.get())) {
29 AINFO <<
"UsbCam config: " << camera_config_->DebugString();
31 camera_device_.reset(
new UsbCam());
32 camera_device_->init(camera_config_);
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();
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();
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;
56 AERROR <<
"Wrong pixel fromat:" << camera_config_->pixel_format()
57 <<
",must be yuyv | uyvy | mjpeg | yuvmono10 | rgb24";
61 if (raw_image_for_compress_->image_size == 0) {
62 raw_image_for_compress_->image =
nullptr;
64 raw_image_for_compress_->image =
reinterpret_cast<char*
>(
65 calloc(raw_image_for_compress_->image_size,
sizeof(
char)));
68 device_wait_ = camera_config_->device_wait_ms();
69 spin_rate_ =
static_cast<uint32_t
>((1.0 / camera_config_->spin_rate()) * 1e6);
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;
76 if (raw_image_->image_size > MAX_IMAGE_SIZE) {
77 AERROR <<
"image size is too big ,must less than " << MAX_IMAGE_SIZE
81 raw_image_->is_new = 0;
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;
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);
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);
105 pb_image_buffer_.push_back(pb_image);
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());
114 raw_image_buffer_.push_back(raw_image);
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);