jsh121988
Posts: 11
Joined: Tue Feb 24, 2015 3:30 pm

Accessing specific area with full resolution

Thu Jul 23, 2015 10:06 am

Hi,

I have a camera setup for surveillance, and I'm using python. I want to record a cropped area with full resolution, and preferably in a specific location of the sensor. The area would be smaller than 1920x1080. Does anyone know if this is possible?

Example: I want to record a 100x100 full res video at coordinates 200x200 from the top left corner (0,0).

Thanks,
Jon

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10239
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Accessing specific area with full resolution

Thu Jul 23, 2015 10:40 am

You're going to need to do a little bit of fiddling.
You don't specify how you're controlling the camera, though your previous posts imply you tend to use Python and picamera so I won't go into too much MMAL detail.

First question is do you need 30fps? If 15fps is sufficient, then force the sensor mode to the 5MPix mode (mode 2), and you can then work out the numbers to specify the region of interest, eg for your example x=200/2592, y=200/1944, w=100/2592, h=100/1944. (If using MMAL directly you'll need to multiply those values by 65536).

If you need 30fps and your region of interest is within the cropped mode that the 1080P reads from the sensor, then you can force that mode (mode 1 IIRC) and do the same set of calculations as above but taking into consideration that the mode already has an offset of x=336 y=432, and width of 1920x1080.

If your region is outside of that crop, then I'm afraid you have to work with the binned mode.

The ISP will rescale anything to anything after having done that crop, so you could take the above ROI and request a 1024x768 (or larger) image from it - it'll look very bad as it is upscaling a long way. If your roi was based on a 100x100 section and you ask to record 100x100, then it will do a small amount of processing but will broadly be 1:1 from the original sensor image.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jsh121988
Posts: 11
Joined: Tue Feb 24, 2015 3:30 pm

Re: Accessing specific area with full resolution

Thu Jul 23, 2015 8:43 pm

Honestly, 5fps is fine. I understand what you're saying. I know that you mainly do C. Would you happen to know how to set it to Mode 2 for video in Python? Zoom is the closest thing I could find for cropping.

It seems this doesn't work, and I'm guessing it's the limitation of h264, though it would be less than the binned resolution.
camera.resolution = (2584, 1944)
camera.zoom = (0.25,0.25,0.4,0.4) # (x, y, w, h)

Error:
mmal: mmal_vc_port_enable: failed to enable port vc.ril.video_encode:in:0(I420): ENOSPC
mmal: mmal_port_enable: failed to enable connected port (vc.ril.video_encode:in:0(I420))0x1162520 (ENOSPC)
mmal: mmal_connection_enable: output port couldn't be enabled

Thanks,
Jon

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10239
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Accessing specific area with full resolution

Thu Jul 23, 2015 9:56 pm

Forcing the sensor mode : http://picamera.readthedocs.org/en/rele ... mera-modes
The input mode can be manually specified with the sensor_mode parameter in the PiCamera constructor (using one of the values from the # column in the table above). This defaults to 0 indicating that the mode should be selected automatically based on the requested resolution and framerate. The rules governing which input mode is selected are as follows:
camera.resolution needs to be set to the output resolution of the cropped area. (Yes anything > 1920x1080 will fail in the H264 encoder).

Your camera.zoom call looks good to me to crop out the middle 1036x777 pixels with an offset of 25% of the way in (or 648,486 pixels in). That has also just given you the numbers for the resolution, so it should be camera.resolution = (1036x778). Do make sure your resolution is a multiple of 2 in each direction - chroma-subsampling becomes very tricky if not, hence it is enforced.

Setting camera.framerate = 5 (or other number below 15) would be the clean thing to do, but if you don't then you should get 15fps having forced the sensor mode.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jsh121988
Posts: 11
Joined: Tue Feb 24, 2015 3:30 pm

Re: Accessing specific area with full resolution

Fri Jul 24, 2015 12:21 am

Thank you, It works!

Here are the basic settings:
camera = picamera.PiCamera(sensor_mode=2) # Use this to set the sensor mode.
#camera.sensor_mode = 2 # This property does not work, need to use sensor_mode during initialization.
camera.resolution = (1296, 972)
camera.zoom = (0.1,0.25,1296/2592,972/1944) # (x, y, w, h)

Thank you so much for your help 6by9!
Jon

photoJames
Posts: 8
Joined: Fri Jan 02, 2015 11:28 pm

Thu Aug 27, 2020 9:30 pm

After a bit of searching I think this is as close to what I want to do as I have found. I have the HQ camera attached to a 4b+. I am using it as a document camera. I don't need to record anything on the Pi as the hdmi is going out to my laptop and the recording is being handled there. I have the 6mm lens and it gives me a good view of my whole desk. I'd like to crop out a couple of different resolutions/zoom to avoid having to move the camera up and down. I've seen region of interest and that sounds like what I would like to do. I would like to keep the image centered. The HQ has a resolution of 2592 x 1944 but the resolutions that I would like to use are 16:9 so 2592x1458, 1920x1080, 1280x720, and possibly 853 x 480. I'm using picamera in python but I'm open to whatever can get the job done. Thanks in advance.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 10239
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re:

Fri Aug 28, 2020 10:25 am

photoJames wrote:
Thu Aug 27, 2020 9:30 pm
After a bit of searching I think this is as close to what I want to do as I have found. I have the HQ camera attached to a 4b+. I am using it as a document camera. I don't need to record anything on the Pi as the hdmi is going out to my laptop and the recording is being handled there. I have the 6mm lens and it gives me a good view of my whole desk. I'd like to crop out a couple of different resolutions/zoom to avoid having to move the camera up and down. I've seen region of interest and that sounds like what I would like to do. I would like to keep the image centered. The HQ has a resolution of 2592 x 1944 but the resolutions that I would like to use are 16:9 so 2592x1458, 1920x1080, 1280x720, and possibly 853 x 480. I'm using picamera in python but I'm open to whatever can get the job done. Thanks in advance.
Effectively a duplicate of viewtopic.php?f=43&t=283963&p=1719293

And the HQ camera has a native resolution of 4056 x 3040. It's the V1 module that has a native resolution of 2592x1944.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Camera board”