Set max resolution

OpenCV, Python and other image processing questions
Post Reply
pascalfust
Posts: 4
Joined: Fri Jan 31, 2020 6:28 am

Set max resolution

Post by pascalfust » Fri Jan 31, 2020 7:20 am

Hi,

I've just started working on the StereoPi, which I want to use as double (still) camera setup on a Raspberry basis.
Working on my Python scripts from other Raspberries, I found one important limitation by the maximum resolution originating probably from the camera drivers. It seems that the resolution of a two-camera-setup capture seems somewhat still limited by the resolution of one camera, i.e. for double V1 Raspi camera modules to somewhat 2592x1944 px.

Obviously, it would be useful to get a capture with a width of 2x2592. Is there any way to get such a modification?
I guess that that limitation is somehow set within the camera drivers, isn't it?

Any advice is warmly welcome!

Thanks in advance

User avatar
Realizator
Site Admin
Posts: 392
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator » Fri Jan 31, 2020 7:41 am

Hi Pascalfust,
Actually you can get one image with the full resolution for both sensors. For V1 (5Mpix) you'll get 10 Mpix photo. We use this, for example, in our SLP image for taking a photo. In my article "The art of stereoscopic photo, Part 2" you can find section "Now let’s check how the ‘Camera’ mode works.", and find an example of such a photo.

Both raspistill and Python PiCamera sits on the same camera API, so this should work.

Can you please try to capture full-res stereoscopic image with Python and write your result here?
Eugene a.k.a. Realizator

pascalfust
Posts: 4
Joined: Fri Jan 31, 2020 6:28 am

Re: Set max resolution

Post by pascalfust » Tue Feb 04, 2020 4:58 pm

Hi Eugene,

thanks for your prompt reply. I tried raspistill (e.g. raspistill -3d sbs -o "test.jpg" -w 5200) which works perfectly, however when it comes to Python, it blocks any attempt of increasing the width above the standard resolution
Screenshot.jpg
Screenshot.jpg (54.18 KiB) Viewed 145 times
Maybe I am missing some specific tweak, but it seems as if it wouldn't work via the Picamera module.

Anybody can give a hint?

User avatar
Realizator
Site Admin
Posts: 392
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator » Thu Feb 06, 2020 2:50 pm

Pascalfust, I confirm this problem. Looks like PiCamera has internal image size limits, and is not taking into account, that we need stereoscopic one (with the twice more width).
I've opened an issue at Github concerning this bug.

But raspistill can capture full resolution stereoscopic images. That is "raspistill -3d sbs -w 5184 -4 1952 -o photo.jpg" works fine.

So if you need to have a solution for taking a full-resolution photos from the Python right now, I can suggest you to run "raspistill" application from Python with appropriate options. There are lot of ways to run shell commands from Python (here, for example). You can pass a parameters like file name for saving. If it works for you?
Eugene a.k.a. Realizator

pascalfust
Posts: 4
Joined: Fri Jan 31, 2020 6:28 am

Re: Set max resolution

Post by pascalfust » Thu Feb 06, 2020 5:06 pm

Realizator, thank you for your feedback.

Unfortunately, the application of running "raspistill" applications by shell commands will not satisfy our requirements in terms of photo interval. As our intention is to use the StereoPi on a "fast" moving vehicle, we need minimum frame rates around 1 fps.
This, however, is barely achievable via the (slow) "raspistill" function that obviously opens and closes the connection after each frame.

While such a frame rate might be possible through Python, using the capture_continuous, there might exist an alternative solution based on C++ or S.L.P. Could you advise on this?

User avatar
Realizator
Site Admin
Posts: 392
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator » Thu Feb 06, 2020 7:46 pm

Pascalfast, we have a discussion with 6by9 at Github (he is one of the hardware and software gurus from RPi team) in my issue I mentioned in a last post. I will try his advice tomorrow, and may be we'll be able to capture this directly from Python.

If this will not work, we'll find another way (like SLP or C++ based approaches you mentioned). Please give me one more day for the tests :-)
Eugene a.k.a. Realizator

User avatar
Realizator
Site Admin
Posts: 392
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator » Fri Feb 07, 2020 9:05 am

Pascalfast, I have a temporarily solution at this moment. Set "stereo_decimate = True", and resolution 2592x1936. In this case you got image with horizontal scale by 0.5 You can scale it horizontally twice to get full-resolution image. I will dig further to find another solutions for you.
Eugene a.k.a. Realizator

User avatar
Realizator
Site Admin
Posts: 392
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator » Fri Feb 07, 2020 12:08 pm

Ok, it works now.
1. Open config.txt file from /BOOT partition and increase number of GPU memory:

Code: Select all

gpu_mem=256
It's strange, but raspistill works with the smaller number of GPU_MEM, and PiCamera needs more.

2. To fix an error from your screenshot, you need to do some changes in this file:

Code: Select all

/usr/lib/python3/dist-packages/picamera/camera.py
You need root level to edit it, so I just run:

Code: Select all

sudo thonny
to open editor with the super user privileges.

Go to the row 2271, mentioned in your error, and add '*2' at the end of expression. So you have:

Code: Select all

(0 < value.width <= self.MAX_RESOLUTION.width*2) and
Do not forget to set "stereo_decimate=False" in your PiCamera settings.

I've attached both files (edited camera.py and my test Python code I used to capture image). Could you please check, if it works for you?
Attachments
camera_py_fullres.zip
camera.py and test capture code
(37.4 KiB) Downloaded 3 times
Eugene a.k.a. Realizator

pascalfust
Posts: 4
Joined: Fri Jan 31, 2020 6:28 am

Re: Set max resolution

Post by pascalfust » Fri Feb 07, 2020 4:51 pm

Works as a charm like this... thanks for digging into that !!
:D :D

User avatar
Realizator
Site Admin
Posts: 392
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator » Mon Feb 10, 2020 8:41 am

Cool! :-)
Can you please share some more details about your project? Or it is under NDA?..
Eugene a.k.a. Realizator

Post Reply