Video 4 Linux driver ROI mode

Hello,

As I’m developing a driver for a new imaging sensor, I have been looking at other drivers and see how they implemented all the modes. I successfully implemented 18 modes already, but I can’t seem to understand how to implement Region of Interest functionality.

I’ve been looking around and see that more sensors have a programmable ROI section or even multiple ROI sections like mine does. It allows you to set two coordinates to create a ROI. Unfortunately, it’s a subject I can’t find any information about regarding Video 4 Linux.

I’ve looked up information about sensors with available drivers, but these don’t seem to have any ROI functionality.

How can I implement ROI mode in my driver?

Hi,
It seems not implemented:
https://www.raspberrypi.org/forums/viewtopic.php?t=62364&start=325#p601170
But it is a 2014 post. Maybe it is implemented now. Other users may share more information on this.

We have hardware engine to perform cropping. You can capture full-size frames and leverage the hardware engine to crop the ROI zone. Please refer to 12_camera_v4l2_cuda.

Hello,

That’s rather unfortunate. By using the sensor’s ROI mode, a higher framerate can be achieved instead of cropping sections of a full frame.
Hopefully this function will be implemented in the future.

Hi FPSUsername,

I’m not sure if there is a standard way to do this in V4L2, but I have implemented an ROI mode in an image sensor driver by doing the following:

  1. Add a new sensor mode for ROI that sets the image width and height to the desired output size
  2. Add a custom V4L2 control to the driver to set the starting coordinates of the ROI

With this method you are limited to keeping the ROI a fixed size, but you can move the window around using the V4L2 control.

Mike

Hi D3_msoltiz,

If you’re able to set the starting coordinates of the ROI in a custom control, then shouldn’t it also be possible to set the width and height of the ROI?

I believe I understand how I have to implement the ROI mode, but how do I make use of these custom settings? Do I have to start a video stream through a command with the desired settings?

Hi FPSUsername,

The issue with changing the size of the image is that each sensor mode has a static width and height. So, every time you change the width and height you would need to change the sensor mode. If you wanted to support a few different ROI window sizes, you could implement separate modes for each one. For example, if you had a 1920x1080 image and wanted to support ROIs that are 1/2 and 1/4 of the image, you can do something like this in your device tree:

mode0 {  // Full Resolution
	active_w = "1920";
	active_h = "1080";
        ...
};
mode1 {  // 1/2 Image ROI
	active_w = "960";
	active_h = "540";
        ...
};
mode2 {  // 1/4 Image ROI
	active_w = "480";
	active_h = "270";
        ...
};

If you create v4l2 controls called roi_start_x and roi_start_y that set the starting coordinates, you can use the following terminal command to change the start position:

v4l2-ctl --set-ctrl=roi_start_x=[x coordinate] --set-ctrl=roi_start_y=[y coordinate]

Hmm, my method (which I can not test at the moment) was to create a separate ROI function in the C file. Here the user can input the ROI parameters (they’re vaguely explained in the datasheet of the sensor, so I’m sure I have to change things in my code).
I added a custom entry in the tegracam_ctrl_ops struct that defines the custom ROI function.

The problem now is the device tree, but is it really necessary to include the active widths and heights?
Because in theory, the VMAX is fixed to the value used for all-pixel scan (in my case with a resolution of 1920x1200)