Send downsized images for streaming
Added another v4l2 reader using mainpath to send 640x480 images.
Also had to make some config queue size changes to allow us to add
another image channel.
Signed-off-by: milind-u <milind.upadhyay@gmail.com>
Change-Id: I5714ea774773e1c37ff2647cb75b3dda07f896fe
diff --git a/y2023/vision/camera_reader.cc b/y2023/vision/camera_reader.cc
index b604516..7de3eb5 100644
--- a/y2023/vision/camera_reader.cc
+++ b/y2023/vision/camera_reader.cc
@@ -17,6 +17,8 @@
DEFINE_double(green, 1, "Green gain");
DEFINE_double(blue, 1.96, "Blue gain");
DEFINE_double(exposure, 150, "Camera exposure");
+DEFINE_bool(send_downsized_images, false,
+ "Whether to send downsized image for driver cam streaming.");
namespace y2023 {
namespace vision {
@@ -31,59 +33,70 @@
media_device->Log();
}
- int width = 1296;
- int height = 972;
- int color_format = MEDIA_BUS_FMT_SBGGR10_1X10;
- std::string camera_device_string = "ov5647 4-0036";
- if (FLAGS_lowlight_camera) {
- width = 1920;
- height = 1080;
- color_format = MEDIA_BUS_FMT_SRGGB10_1X10;
- camera_device_string = "arducam-pivariety 4-000c";
- }
+ const int kWidth = (FLAGS_lowlight_camera ? 1920 : 1296);
+ const int kHeight = (FLAGS_lowlight_camera ? 1080 : 972);
+ const int kColorFormat = (FLAGS_lowlight_camera ? MEDIA_BUS_FMT_SRGGB10_1X10
+ : MEDIA_BUS_FMT_SBGGR10_1X10);
+
+ const std::string_view kCameraDeviceString =
+ (FLAGS_lowlight_camera ? "arducam-pivariety 4-000c" : "ov5647 4-0036");
+
+ // Scale down the selfpath images so we can log at 30 Hz (but still detect
+ // april tags at a far enough distance)
+ const double kSelfpathScalar = 2.0 / 3.0;
+ const int kSelfpathWidth = kWidth * kSelfpathScalar;
+ const int kSelfpathHeight = kHeight * kSelfpathScalar;
+
+ // Send heavily downsized images to the drivercam. They go over the network,
+ // and in this case frame rate is more important than quality
+ constexpr int kMainpathWidth = 640;
+ constexpr int kMainpathHeight = 480;
media_device->Reset();
- Entity *camera = media_device->FindEntity(camera_device_string);
- camera->pads()[0]->SetSubdevFormat(width, height, color_format);
+ Entity *camera = media_device->FindEntity(kCameraDeviceString);
+ camera->pads()[0]->SetSubdevFormat(kWidth, kHeight, kColorFormat);
Entity *rkisp1_csi = media_device->FindEntity("rkisp1_csi");
- rkisp1_csi->pads()[0]->SetSubdevFormat(width, height, color_format);
- rkisp1_csi->pads()[1]->SetSubdevFormat(width, height, color_format);
+ rkisp1_csi->pads()[0]->SetSubdevFormat(kWidth, kHeight, kColorFormat);
+ rkisp1_csi->pads()[1]->SetSubdevFormat(kWidth, kHeight, kColorFormat);
// TODO(austin): Should we set this on the link?
Entity *rkisp1_isp = media_device->FindEntity("rkisp1_isp");
- rkisp1_isp->pads(0)->SetSubdevFormat(width, height, color_format);
- rkisp1_isp->pads(0)->SetSubdevCrop(width, height);
+ rkisp1_isp->pads(0)->SetSubdevFormat(kWidth, kHeight, kColorFormat);
+ rkisp1_isp->pads(0)->SetSubdevCrop(kWidth, kHeight);
- rkisp1_isp->pads(2)->SetSubdevFormat(width, height, MEDIA_BUS_FMT_YUYV8_2X8);
- rkisp1_isp->pads(2)->SetSubdevCrop(width, height);
+ rkisp1_isp->pads(2)->SetSubdevFormat(kWidth, kHeight,
+ MEDIA_BUS_FMT_YUYV8_2X8);
+ rkisp1_isp->pads(2)->SetSubdevCrop(kWidth, kHeight);
Entity *rkisp1_resizer_selfpath =
media_device->FindEntity("rkisp1_resizer_selfpath");
- rkisp1_resizer_selfpath->pads(0)->SetSubdevFormat(width, height,
+ rkisp1_resizer_selfpath->pads(0)->SetSubdevFormat(kWidth, kHeight,
MEDIA_BUS_FMT_YUYV8_2X8);
rkisp1_resizer_selfpath->pads(1)->SetSubdevFormat(
- width * 2 / 3, height * 2 / 3, MEDIA_BUS_FMT_YUYV8_2X8);
- rkisp1_resizer_selfpath->pads(0)->SetSubdevCrop(width, height);
+ kSelfpathWidth, kSelfpathHeight, MEDIA_BUS_FMT_YUYV8_2X8);
+ rkisp1_resizer_selfpath->pads(0)->SetSubdevCrop(kWidth, kHeight);
Entity *rkisp1_resizer_mainpath =
media_device->FindEntity("rkisp1_resizer_mainpath");
- rkisp1_resizer_mainpath->pads(0)->SetSubdevFormat(width, height,
+ rkisp1_resizer_mainpath->pads(0)->SetSubdevFormat(kWidth, kHeight,
MEDIA_BUS_FMT_YUYV8_2X8);
- rkisp1_resizer_mainpath->pads(0)->SetSubdevCrop(width, height);
- rkisp1_resizer_mainpath->pads(1)->SetSubdevFormat(width / 2, height / 2,
- MEDIA_BUS_FMT_YUYV8_2X8);
+ rkisp1_resizer_mainpath->pads(0)->SetSubdevCrop(kWidth, kHeight);
+ rkisp1_resizer_mainpath->pads(1)->SetSubdevFormat(
+ kMainpathWidth, kMainpathHeight, MEDIA_BUS_FMT_YUYV8_2X8);
Entity *rkisp1_mainpath = media_device->FindEntity("rkisp1_mainpath");
- rkisp1_mainpath->SetFormat(width / 2, height / 2, V4L2_PIX_FMT_YUV422P);
+ rkisp1_mainpath->SetFormat(kMainpathWidth, kMainpathHeight,
+ V4L2_PIX_FMT_YUYV);
Entity *rkisp1_selfpath = media_device->FindEntity("rkisp1_selfpath");
- rkisp1_selfpath->SetFormat(width * 2 / 3, height * 2 / 3, V4L2_PIX_FMT_YUYV);
+ rkisp1_selfpath->SetFormat(kSelfpathWidth, kSelfpathHeight,
+ V4L2_PIX_FMT_YUYV);
media_device->Enable(
- media_device->FindLink(camera_device_string, 0, "rkisp1_csi", 0));
+ media_device->FindLink(kCameraDeviceString, 0, "rkisp1_csi", 0));
media_device->Enable(
media_device->FindLink("rkisp1_csi", 1, "rkisp1_isp", 0));
media_device->Enable(
@@ -99,16 +112,25 @@
event_loop.SetRuntimeRealtimePriority(55);
event_loop.SetRuntimeAffinity(aos::MakeCpusetFromCpus({2}));
- RockchipV4L2Reader v4l2_reader(&event_loop, event_loop.epoll(),
- rkisp1_selfpath->device(), camera->device());
-
+ // Reader for vision processing
+ RockchipV4L2Reader v4l2_reader_selfpath(&event_loop, event_loop.epoll(),
+ rkisp1_selfpath->device(),
+ camera->device());
if (FLAGS_lowlight_camera) {
- v4l2_reader.SetGainExt(100);
- v4l2_reader.SetVerticalBlanking(1000);
- v4l2_reader.SetExposure(FLAGS_exposure);
+ v4l2_reader_selfpath.SetGainExt(100);
+ v4l2_reader_selfpath.SetVerticalBlanking(1000);
+ v4l2_reader_selfpath.SetExposure(FLAGS_exposure);
} else {
- v4l2_reader.SetGainExt(1000);
- v4l2_reader.SetExposure(1000);
+ v4l2_reader_selfpath.SetGainExt(1000);
+ v4l2_reader_selfpath.SetExposure(1000);
+ }
+
+ std::unique_ptr<RockchipV4L2Reader> v4l2_reader_mainpath;
+ if (FLAGS_send_downsized_images) {
+ // Reader for driver cam streaming on logger pi, sending lower res images
+ v4l2_reader_mainpath = std::make_unique<RockchipV4L2Reader>(
+ &event_loop, event_loop.epoll(), rkisp1_mainpath->device(),
+ camera->device(), "/camera/downsized");
}
{