Set max resolution

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

Set max resolution

Post by pascalfust »

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: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator »

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: 9
Joined: Fri Jan 31, 2020 6:28 am

Re: Set max resolution

Post by pascalfust »

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 23827 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: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator »

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: 9
Joined: Fri Jan 31, 2020 6:28 am

Re: Set max resolution

Post by pascalfust »

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: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator »

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: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator »

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: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Set max resolution

Post by Realizator »

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 534 times
Eugene a.k.a. Realizator

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

Re: Set max resolution

Post by pascalfust »

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

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

Re: Set max resolution

Post by Realizator »

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

[email protected]
Posts: 6
Joined: Wed Jul 01, 2020 1:16 pm

Re: Set max resolution

Post by [email protected] »

I am working on a project with similar goals in terms of image collection: I would like to take full-resolution stereo images with the stereopi using two V2 camera modules.

I followed the instructions in this thread to take full resolution images with piCamera, however when I tried running the script 1_tmp.py in a raspian desktop environment, the raspberry pi appeared to crash and reboot several times, and no image was saved. I tried disabling the desktop environment and when I ran the 1_tmp.py script, there was no reboot, but it generated no output in the terminal and did not save an image.

I'm using a 8Gb Compute module 3+ for reference.

Eugene - is there anything that I am doing wrong or different from how you achieved full resolution through picamera?

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

Re: Set max resolution

Post by pascalfust »

jlurban: What power supply are you using ? Via the USB or the pins? Do you encounter the same problem at lower resolution?

[email protected]
Posts: 6
Joined: Wed Jul 01, 2020 1:16 pm

Re: Set max resolution

Post by [email protected] »

pascalfust: I am using the pins for power. I was able to successfully collect images in the stereopi-tutorial and was able to set the re-scale factor to 1. (the default in the 0.5).

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

Re: Set max resolution

Post by Realizator »

Hi Jlurban!
You see, the full-resolution video capture is extremely consuming task. You should try either use a photo capture for the full resolution, or, for example, set a very small FPS. Can you please share a piece of code you use for the camera settings?
Pascalfaust asked a good question. What kind of a power source you are using?
Also running 1_test.py without a GUI is a good idea, on ly if you disable all the code, responsible for the image show.

UPD> Ohm wait! My fault! You're using my simple 1_tmp.py from the attached archive!
Could you please answer some questions:
1. Did you modify your camera.py, or put my attached version? It is better to modify your file, as the latest camera.py might have some difference with the old version I used.

2. Can you please confirm, that after your modification of the "camera.py" you other PiCamera-related scripts (like 1_test.py) works fine? I mean, if PiCamera continue to work correctly after your modification?

3. Are you working with one of our OpenCV images, or you are using a fresh Raspberry OS and just put OpenCV code on it?
Eugene a.k.a. Realizator

[email protected]
Posts: 6
Joined: Wed Jul 01, 2020 1:16 pm

Re: Set max resolution

Post by [email protected] »

Hi Eugene,

Right now I am using the 1_tmp.py script that you provided earlier in this thread without any modifications.

I also changed the settings in the `/boot/config.txt` file and the `/usr/..../picamera.py` file.

A small FPS is perfectly acceptable and photo capture would be preferred. Ideally I could get a full-resolution raw image stereo pair.

In terms of a power source I am using the pins powered through a USB power cable plugged into a powered Computer Dock and USB hub for my laptop. If you suggest another way please let me know.

I'll try disabling all GUI and imshow features and see if that helps.

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

Re: Set max resolution

Post by Realizator »

Jlurban, I put an update to my previous answer. Please take a look :-)
UPD> As for your power source - please try to provide power from the dedicated power adaptor, like a phone or tablet charger, able to provide at least 2A current.
Eugene a.k.a. Realizator

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

Re: Set max resolution

Post by pascalfust »

The USB ports offen lack power, sometimes limiting to 2 amps. The stereopi, however, might ask for mor than that

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

Re: Set max resolution

Post by Realizator »

pascalfust wrote:
Wed Jul 01, 2020 4:30 pm
The USB ports offen lack power, sometimes limiting to 2 amps. The stereopi, however, might ask for mor than that
Actually, USB 2.0 is limited by 0.5A (500 mA). But I agree, to catch up that problem we need at least to exclude the power issue.
Eugene a.k.a. Realizator

[email protected]
Posts: 6
Joined: Wed Jul 01, 2020 1:16 pm

Re: Set max resolution

Post by [email protected] »

Switching to a 2A power supply fixed it! Thank you Eugene and Pascalfust for the quick responses!
  1. I modified my picamera.py adding the `*1`
  2. 1_test.py works
  3. I'm using a fresh Raspberry OS and OpenCV installed on it

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

Re: Set max resolution

Post by Realizator »

Whoa, great! Congratulations! :-)
Eugene a.k.a. Realizator

Post Reply