Page 1 of 1

raspbian bullseye and stereomode

Posted: Mon Aug 15, 2022 7:25 am
by zoldaten
I`m trying to start stereo mode on Raspbian x64 bullseye with picamera2 and stereopiV2.

Everything works but only with 1 camera at once:

Code: Select all

import os;import cv2;import numpy as np;from datetime import datetime
#from picamera.array import PiRGBArray
#from picamera import PiCamera
from picamera2 import MappedArray, Picamera2, Preview

# Initialize the camera
#     camera = PiCamera(stereo_mode='side-by-side',stereo_decimate=False)
#     camera.resolution=(cam_width, cam_height)
#     camera.framerate = 5
#     camera.exposure_mode = 'off'     
#     camera.shutter_speed = 1000000    
#     camera.contrast = 0  # Контрастность
#     camera.brightness = 60  # Яркость
#     camera.saturation = 0  # Насыщенность
#     camera.ISO = 800  # Чувствительность
#     camera.awb_mode = "auto"  # "fluorescent"
camera = Picamera2()

config = camera.create_preview_configuration(main={"format": "RGB888"})
#for frame in camera.capture_continuous(capture, format="bgr", use_video_port=True,
while True:    
    origin_img = camera.capture_array()
I see 2 cameras registered:

Code: Select all

[0:29:08.795269441] [5481]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3700-f30ad033
[0:29:08.832856316] [5490]  INFO RPI raspberrypi.cpp:1368 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media3 and ISP device /dev/media0
As stereopi wiki suggested i put .bin file to /boot partition and added to config.txt what it needs.

How to start up stereo mode ?

Re: raspbian bullseye and stereomode

Posted: Thu Sep 08, 2022 8:10 am
by Realizator
Hi Zoldaten,

Huh, libcamera is still in the early stage... And the stereoscopic mode activation works another way.

I can help you with two pieces of information:
1. Here is our first experiment of getting two images from two cameras using libcamera: ... 9#p1965619

2. As for Picamera2 - by default it has no stereoscopic mode, but here is an answer from the Picamera2 maintainer on RPF website: ... nt-1581093

I hope this can help.

Re: raspbian bullseye and stereomode

Posted: Fri Sep 09, 2022 6:37 pm
by Realizator
I've played with Picamera 2 today. Well, it's working in some cases, but I wasn't able to get the stable stream from both cams at the same time.

After digging I localized the issue using on of the simplest examples, and opened an issue on GitHub.

While they are fixing this, I'm going to play with transferring two videos from libcamera to python script over pipe, with no Picamera/Picamera2 at all. We used this approach in our C++ examples (here is an article).

Re: raspbian bullseye and stereomode

Posted: Wed Sep 21, 2022 2:34 pm
by neaveeng
Any update on the libcamera testing please? I'm really starting to feel the pain of having to remain on the old 32bit OS is all, if there's an example script you could share for capturing simultaneous images on Bullseye 64bit I'd massively appreciate it.

Re: raspbian bullseye and stereomode

Posted: Thu Sep 29, 2022 6:19 pm
by Realizator
Hey neaveeng,

Things are moving slowly... I'm still trying to find the combination of picamera1/2 and lib camera to get a stable result.

Re: raspbian bullseye and stereomode

Posted: Thu Sep 29, 2022 9:43 pm
by neaveeng
Cool, I'll do some tinkering too. I can't imagine I'll have better luck than you but not knowing how anything works I may stumble on something by accident! 🤣

Re: raspbian bullseye and stereomode

Posted: Sun Oct 16, 2022 9:32 pm
by neaveeng
I've taken a different tack and I'm trying to use CV2 to publish images from left and right, I'm using threading to run the two publishers in parallel and it's publishing fine. The problem is ROS is saying the images aren't sync'd. Even setting approximate sync it doesn't work. ...

Is there any way to get sync'd images using open cv like this? You've mentioned something about sync'ing in hardware, could that work here and if so how do I do that please?

Re: raspbian bullseye and stereomode

Posted: Mon Oct 17, 2022 9:26 am
by Realizator
Hey neaveeng,

You might have two issues under the hood here. The first is a hardware unsync, and the second is a software unsync due to independent thread processing for each image.

As for the first issue - it depends on which cameras you use. For HQ cams, this can be done relatively quickly (but on the old MMAL subsystem only) using their hardware sync feature. If you have V1/V2 cameras, the simplest way to hardware sync them is to use an oscillator trick. Each camera module has an oscillator soldered, so you need to unsolder one on the 1st camera and wire it to the oscillator from the 2nd camera. Yup, that's dirty, but this is the only way for the old V1/V2 modules.

Re: raspbian bullseye and stereomode

Posted: Mon Oct 17, 2022 10:56 am
by neaveeng
I'm guessing for the side by side feature in picamera it did something under the hood to sync them that it hidden in the broadcom stack somewhere then?

These camera modules are the ov5647 waveshare g type, I don't suppose you know of a guide for doing the hack on these do you please as I've not been able to find one and wouldn't risk trying to figure it out myself. It looks like arducam mod these with the same hack but I can find any details there either :(

Re: raspbian bullseye and stereomode

Posted: Wed Oct 19, 2022 10:31 pm
by neaveeng
OMFG I'm an idiot! It turns out that setting the stamp on the image messages was somehow breaking everything!