36 camera_config_ = std::make_shared<Config>();
40 AINFO <<
"UsbCam config: " << camera_config_->DebugString();
42 camera_device_.reset(
new UsbCam());
43 camera_device_->init(camera_config_);
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();
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();
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;
64 AERROR <<
"Wrong pixel fromat:" << camera_config_->pixel_format()
65 <<
",must be yuyv | uyvy | mjpeg | yuvmono10 | rgb24";
69 if (raw_image_for_compress_->image_size == 0) {
70 raw_image_for_compress_->image =
nullptr;
72 raw_image_for_compress_->image
73 =
reinterpret_cast<char*
>(calloc(raw_image_for_compress_->image_size,
sizeof(
char)));
76 device_wait_ = camera_config_->device_wait_ms();
77 spin_rate_ =
static_cast<uint32_t
>((1.0 / camera_config_->spin_rate()) * 1e6);
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;
84 if (raw_image_->image_size > MAX_IMAGE_SIZE) {
85 AERROR <<
"image size is too big ,must less than " << MAX_IMAGE_SIZE <<
" bytes.";
88 raw_image_->is_new = 0;
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;
97 if (camera_config_->arm_gpu_acceleration()) {
98 if (cudaMallocHost(&raw_image_->image, raw_image_->image_size *
sizeof(
char), cudaHostAllocMapped)
100 AERROR <<
"cuda malloc memory error, size:" << raw_image_->image_size;
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;
112 writer_ =
node_->CreateWriter<
Image>(camera_config_->channel_name());
113 raw_writer_ =
node_->CreateWriter<
Image>(camera_config_->raw_channel_name());
115 async_result_ = cyber::Async(&CameraComponent::run,
this);