Apollo 7.0自动驾驶开发笔记48——apollo获取裁剪图像并使用openv显示
发布时间
阅读量:
阅读量
在Apollo代码中,通过frame->data_provider->GetImage(data_provider_image_option_, image_.get());这个函数可以获取图像,但无法直观显示,无法确认数据的准确性。特别地,当do_crop设为true时,我们希望确认裁剪后的图像是否符合预期。通过这段代码,我们可以获取Apollo处理后的裁剪图像并使用OpenV进行展示。
data_provider_image_option_.crop_roi = light->region.detection_roi;
data_provider_image_option_.do_crop = true;
frame->data_provider->GetImage(data_provider_image_option_,
image_.get());
cv::Mat class_img;
class_img =
cv::Mat(light->region.detection_roi.height,
light->region.detection_roi.width,
CV_8UC3, cv::Scalar(0,
0, 0));
uchar* image_data = class_img.data;
const auto* source_data =
image_->cpu_data();
// 计算裁剪区域的起始像素位置
const unsigned char* pixel_ptr
= source_data;
// 遍历裁剪区域内的每个像素
for (int row = 0;
row < light->region.detection_roi.height;
row++) {
for (int col = 0;
col < light->region.detection_roi.width;
col++) {
// 使用指针偏移访问当前像素的通道值
unsigned char red = pixel_ptr[0];
unsigned char green = pixel_ptr[1];
unsigned char blue = pixel_ptr[2];
// 在这里可以对裁剪区域内的像素进行处理,或者将其复制到新的图像数据中
// ...
// 将裁剪后的像素数据复制到新的数组或指针中
unsigned char* cropped_pixel_ptr =
image_data + (row * light->region.detection_roi.width
+ col) * 3;
cropped_pixel_ptr[0] = blue;
cropped_pixel_ptr[1] = green;
cropped_pixel_ptr[2] = red;
// 将指针偏移到下一个像素位置
pixel_ptr += 3;
}
// 将指针偏移到下一行的起始像素位置
pixel_ptr += (3840 - light->region.detection_roi.width)
* 3;
}
cv::circle(class_img, cv::Point2d(5,
5), 1, cv::Scalar(0,
0, 255), 5);
std::string windows_name_string =
"class_img";
const char* window_name =
windows_name_string.c_str();
cv::namedWindow(window_name, 0);
cv::imshow(window_name, class_img);
cv::imwrite("/mnt/movex/class_input_image.jpg",
class_img);
cv::waitKey(100);
AI助手
全部评论 (0)
还没有任何评论哟~
