StereoPi max resolution

S.L.P. image questions, stereoscopic video livestream and recording, stereoscopic photo capture etc.
Post Reply
ciltatarza
Posts: 3
Joined: Thu Oct 22, 2020 6:51 am

StereoPi max resolution

Post by ciltatarza »

Hi folks,

I want to capture two 1920x1440 images but i get black screen when i try it.

5 or 10 fps is enough for me.

Is it possible ?

If possible, would you send sample code :?:

Thanks in advance :!:

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

Re: StereoPi max resolution

Post by Realizator »

Hi ciltatarza,
Could you please tell us more details?
Are you plan to capture these images by Python for further processing? Or you are trying to record this video using SLP image and create a video file?
Which cameras you are using? (v1/v2/HQ?)
Eugene a.k.a. Realizator

ciltatarza
Posts: 3
Joined: Thu Oct 22, 2020 6:51 am

Re: StereoPi max resolution

Post by ciltatarza »

Hi a little car and a lighter!

I have a slave and a master.
Slave is StereoPi (compute module v3) and I use ROS.

I want to publish stereo images from slave to master via ethernet cable.

Now the whole system is ready. ( e.g. master and slave communication, ros )

I can use python and c++. It doesn't matter.

Sample code that I have ;

Code: Select all

    
    cam_width = 640*4
    cam_height = 480*2
    scale_ratio = 0.5

    # Buffer for captured image settings
    img_width = int (cam_width * scale_ratio)
    img_height = int (cam_height * scale_ratio)
    capture = np.zeros((img_height*img_width*3), dtype=np.uint8)
    
    # Initialize the camera
    camera = PiCamera(stereo_mode='side-by-side', stereo_decimate=False)
    camera.resolution=(cam_width, cam_height)
    camera.framerate = 20
    camera.hflip = True
    camera.vflip = True
    
    for frame in camera.capture_continuous(capture, format="bgr", use_video_port=False, resize=(img_width,img_height)):
        frame = frame.reshape((480, 1280, 3))
        imgL = frame[0:img_height, 0:img_width/2]
        imgR = frame[0:img_height, img_width/2:img_width]
    
I need to quality images so i set to use_video_port=False.
That code runs with 1-2 FPS and 640x480 resolution for each image. But i need to high resolution and acceptable FPS(at least 3-5 FPS).

I use raspberry pi camera V2 and Ubuntu Mate.I do not use GUI.

I think I can not publish images with SLP.


Thanks for reply.

ciltatarza
Posts: 3
Joined: Thu Oct 22, 2020 6:51 am

Re: StereoPi max resolution

Post by ciltatarza »

Hi the lighter!

I inspect your some blogs.

Code: Select all

Why do we use BGRA capture, but not BGR?
As we mentioned before, we resize the images using the GPU, and a native GPU format is BGRA (or RGBA, as you wish). If you use BGR you will find two issues; the first is a lower FPS (about 10–20% in our case) and the second is a PiCamera warning «PiCameraAlfaStripping: using alpha-stripping to convert to non-alpha format; you may find equivalent alpha format faster”. Googling this error led us to PiCamera documentation where we found the BGRA method.
I will update the code through this information. But I'll still be waiting your advice.

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

Re: StereoPi max resolution

Post by Realizator »

ciltatarza, you wrote "I need to quality images so i set to use_video_port=False."
This is the key point here. In this mode (actually "still image mode"), GPU does A LOT of image improvements (like noise cancellation, color adjustments etc.). So this mode can't be used for the fast frames capture, even theoretically. Please try to use this in "use_video_port=False" mode.

If you are an experienced Python/CPP user, I can give you 3 points for consideration. I tested them all, and will implement one of these in our upcoming update of the Python code.

1. You can try to use threads to capture images in Python, as it helps to avoid waiting for the IO operations. This can increase FPS ~2-3 times. As a negative effect - your CPU will be loaded up to 100% for all 4 kernels. The explanation can be found here.
I attached an example of the code I used to play with (FPS_test_basic.py.zip). You can try to change the resolution and see the result.

2. You can try to use "np.frombuffer" feature in Python. It will create frames in memory, without copying/modifying them. Also, you can use YUV colorspace, and take Y (Intensity) only - i.e. 3 times smaller amount of data. I.e. in this case camera provide you a color image in the memory, but you are using the grayscale part only. This is the approach I will use in our scripts. Take a look at the explanation and a code example (the second code in the first answer) here. JFYI, the author of this answer is actually an author of the PiCamera python library. :-)

3. C++ and the most efficient way. In addition to the raspivid, we have raspividyuv utility. It has one extremely useful parameter, "--luma" or "-l". If you use it, raspividyuv will give you ONLY the Y parameter (i.e. grayscale image). It means IO process will not use the bandwidth, needed to push a full color image.
So you can use this utility and pass all frames to your processing part over a pipe. We used exactly this trick in our article about C++/Python speed comparison.


Which approach looks more interesting to you? :-)

p.s. raspividyuv got the stereoscopis support just a few months ago. please use the latest firmware/kernel to get stereoscopic image from raspividyuv
Attachments
FPS_test_basic.py.zip
(1.13 KiB) Downloaded 175 times
Eugene a.k.a. Realizator

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

Re: StereoPi max resolution

Post by Realizator »

p.s. ciltatarza, could you please contact me by email? I have one ROS-specific question for you... my email is my nickname @gmail.com
Eugene a.k.a. Realizator

Post Reply