raspbian bullseye and stereomode

OpenCV, Python and other image processing questions
Post Reply
User avatar
zoldaten
Posts: 48
Joined: Fri Apr 26, 2019 7:07 am

raspbian bullseye and stereomode

Post by zoldaten »

hi!
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"})
camera.configure(config)
camera.start_preview(Preview.QT)
camera.start()
        
#for frame in camera.capture_continuous(capture, format="bgr", use_video_port=True,
                                       #resize=(img_width,img_height)):    
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 ?

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

Re: raspbian bullseye and stereomode

Post 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: https://forums.raspberrypi.com/viewtopi ... 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: https://www.raspberrypi.com/news/a-prev ... nt-1581093

I hope this can help.
Eugene a.k.a. Realizator

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

Re: raspbian bullseye and stereomode

Post 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).
Eugene a.k.a. Realizator

neaveeng
Posts: 13
Joined: Wed May 06, 2020 4:26 pm

Re: raspbian bullseye and stereomode

Post 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.

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

Re: raspbian bullseye and stereomode

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

neaveeng
Posts: 13
Joined: Wed May 06, 2020 4:26 pm

Re: raspbian bullseye and stereomode

Post 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! 🤣

neaveeng
Posts: 13
Joined: Wed May 06, 2020 4:26 pm

Re: raspbian bullseye and stereomode

Post 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.

https://github.com/NeaveEng/stereocam_n ... eo_node.py

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?

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

Re: raspbian bullseye and stereomode

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

neaveeng
Posts: 13
Joined: Wed May 06, 2020 4:26 pm

Re: raspbian bullseye and stereomode

Post 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 :(

neaveeng
Posts: 13
Joined: Wed May 06, 2020 4:26 pm

Re: raspbian bullseye and stereomode

Post by neaveeng »

OMFG I'm an idiot! It turns out that setting the stamp on the image messages was somehow breaking everything!

Post Reply