How to setup StereoPi using fresh Raspbian image

Other software discussion
Post Reply
piofthings
Posts: 7
Joined: Fri Aug 30, 2019 11:29 pm

How to setup StereoPi using fresh Raspbian image

Post by piofthings »

Hi,
I am primarily interested in having the latest version of Raspbian and OpenCV to run StereoPi.
My hardware is StereoPi Slim + USB ports soldered on + Waveshare 160 FoV Cameras + Compute Module 3+ with 32GB memory
As i understand from the instructions:

1. Download Raspbian (desktop but no recommended software)
2. Use etcher to write to CM eMMC via StereoPi
3. Drop dt-blob.bin in the boot partition
4. Drop stereopi.config in the boot partition
5. Unmount/Unplug Micro USB
6. Power up Compute module

While all of this happens StereoPi doesn't seem to get up on the network. The top LED blinks a few times and stops. Then only two LEDs stay on, but nothing else budges.

Earlier when I had installed the SLP image, everything had worked perfectly.
Cameras are connected.
Nothing on GPIO ports.

Am I missing a step? Is Raspbian Buster completely unsupported ? Are there known issues with Buster and dt-blob.bin ?

Thanks and Regards,
Sumit
(aka @piofthings)

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: How to setup StereoPi using fresh Raspbian image

Post by stereomaton »

I have no experience with the hardware you talk about but I can provide my expertise on embedded Linux in general.

The hardware of stereopi is very very similar to the raspberry-pi so that everything not too fancy (Raspbian is obviously the least exotic one) that runs on the compute module should run on the stereopi.
The dt-blob.bin is a special file used by the raspberry-pi to configure it's pins in an early stage, far before the Linux kernel kicks in. Therefore it is likely independant of the distribution you use except if they changed the boot loading process incompatibly which is pretty unlikely here.
stereopi.conf is an userland software configuration so it does not influence neither.

In short, from what I understand of the thing, there is nothing that could prevent the last version of Raspbian to work on StereoPi (provided that it supports your compute module)

The first thing is of course to check the checksums of your files. On the systems I work on at work, I would then connect a USB-serial converter on the debug uart of the chip to monitor the boot process and identify when the failure occures. I did not check if it is available on StereoPi though.
If you suspect that Raspbian version can interfere, you can also try to flash an older version (not SLP but stock Raspbian) to verify your procedure as well.

These are some basic advices, but they might be useful until someone more informed answers.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

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

Re: How to setup StereoPi using fresh Raspbian image

Post by Realizator »

Hi Sumit,
Stereomaton, thank you for your description!
If SLP works fine, it means hardware is Ok.
Sumit, I think in your case you’ve been misleaded by our stereopi.conf file. This file is not used by stock Raspbian, and was designed specially for SLP. So all your settings (like WiFi, cameras modes etc.) are ignored now.

You just need to setup network in your Raspbian as with classic Raspberry Pi.
By the way, I was not able to find steps like “insert WiFi dongle” or “connect Ethernet cable” (if you’ve soldered RJ45 to your Slim edition) in your 6 steps mentioned.

Also one more question - are you using full Raspbian image with GUI? This way you may set up WiFi easily using GUI.
Eugene a.k.a. Realizator

piofthings
Posts: 7
Joined: Fri Aug 30, 2019 11:29 pm

Re: How to setup StereoPi using fresh Raspbian image

Post by piofthings »

Thanks to both @realizator and @stereomaton.

I have got both Raspbian Buster Lite and Raspbian Buster Desktop (without recommended software) running via Compute Module on Stereo PI.

The only thing I did different was use new image so I guess @Stereomaton was right about the image integrity last night.

After testing them out I connected them back to computer using the Firmware write mode and copied dt-blob.bin over the boot partition and went back to starting the StereoPi up. It started fine.

However, I am unable to get PiCamera to take stereo Pictures

Code: Select all

from picamera import PiCamera
camera = PiCamera(stereo_mode='side-by-side', resolution=(1280,720))
camera.capture('foo.jpg')
When I run the above code, the whole system freezes up. I can ssh into it, but I can't kill it. When I used a second ssh session to initiate reboot it killed all the ssh sessions but didn't actually reboot for 5 minutes. I know because the monitor was plugged in and the desktop didn't change (only the ssh sessions died).

When I did it from Desktop, it froze the desktop and I couldn't shut it down from desktop either.

Before I had enabled the camera PiCamera threw an exception about enabling Camera using raspiconfig. I did so. But it has only option to enable one camera (?)... Do I need to enable two cameras separately somehow?

After placing dt-blob.bin do I need to put Stereopi.conf in there too ?

Thanks again

piofthings
Posts: 7
Joined: Fri Aug 30, 2019 11:29 pm

Re: How to setup StereoPi using fresh Raspbian image

Post by piofthings »

_Update_

Super excited to mention that raspistill works and both cs0 and cs1 are reporting some images from the camera... flipped but we have images.

Yay!

Now to figure out why RpiCamera is buggered. Maybe it has a bug in Buster.

Cheers,

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: How to setup StereoPi using fresh Raspbian image

Post by stereomaton »

This rpicamera python module sends commands to the mmal subsystem.
The API of this very specific driver or the internals of the coprocessor firmware might have changed with the update (kernel or firmware) that possibly comes with new version of Raspbian. If this is a case, a downgrade of only this part might be a temporary workaround.
I already saw a freeze like the one you described with a misconfiguration of the image processing units of another processor and this survived to soft reboot and reset signals which made it tricky to spot.
Whatever the reason, it is probably a problem to search/discuss on the tools (issue tracker, forum, mailing-list, whatever they use) of the rpicamera library instated of here.
However, any significative update you have on the problem would be interesting to read on this forum thread.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

piofthings
Posts: 7
Joined: Fri Aug 30, 2019 11:29 pm

Re: How to setup StereoPi using fresh Raspbian image

Post by piofthings »

@stereomaton do you know if openCV Python uses the same subsystem or it uses a different stack ? Also RaspiStill seems to be working and taking pictures from both cameras on request.

If what you say is right, I should be able to crash Raspbian Buster on Pi using the same camera right? Let me try the camera on Pi4 and confirm.

brb :-)


Oh I need a Pi 3B+ for a closer to metal test... this might take a while longer :D

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

Re: How to setup StereoPi using fresh Raspbian image

Post by Realizator »

piofthings wrote:
Sun Sep 01, 2019 12:03 pm
@stereomaton do you know if openCV Python uses the same subsystem or it uses a different stack ? Also RaspiStill seems to be working and taking pictures from both cameras on request.
For OpenCV the PiCamera is used (MMAL-based). If your raspistill/raspivid tests are passed, PiCamera should work too.
piofthings wrote:
Sun Sep 01, 2019 12:03 pm
If what you say is right, I should be able to crash Raspbian Buster on Pi using the same camera right? Let me try the camera on Pi4 and confirm.
brb :-)
You can use right the same code on RPi4 without any changes (except work with 2 cameras, as RPi4 has access to one cam only).
piofthings wrote:
Sun Sep 01, 2019 12:03 pm
Oh I need a Pi 3B+ for a closer to metal test... this might take a while longer :D
As RPi4 is much more faster than CM3+, I think it is good idea to use "Big brother helps to Small brother" approach. If I will have a time, I try to set up a couple StereoPi+RPi4, when StereoPi does all video capture/recording/livestream tasks, and also streams to nearby RPi4 (for quicker OpenCV image processing).
Eugene a.k.a. Realizator

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: How to setup StereoPi using fresh Raspbian image

Post by stereomaton »

Realizator answered while I wrote my own answer (again).

I know the mmal thing because rpicamera wrote it in their documentation.
For opencv, I think they use v4l2 abstraction of the kernel, which is a generic layer for video capture.
Linux drivers (except for some specific drivers such as mmal for advanced features) are often organised in layers with some abstraction ones that the applications can connect to and concrete ones that communicates to the actual hardware and with the abstraction (actually it is less linear than that, but this is a big picture). This way, the applications only have to know how to communicate with the generic part, and they have access to all the actual drivers that register to the abstraction automatically. For example, if the application uses v4l2, it does not have to implement some code for each camera that exists, and as user you just have to check that your camera has a v4l2-compatible driver.
I did not check if the raspberry-pi camera module has a v4l2 driver (which would probably use the mmal driver internally), but if it is the case, they are likely in sync because probably developed by the same/related people and packaged in the same repository. (Realizator seems to confirm that there is a such one, although he did not use the same terms)

Because of advanced features, I guess that raspistill talks to the mmal driver directly too, but it is a different implementation. It might not use the same commands or have already been updated for the (hypothetical, I emphases that it is a supposition) new version of the driver.

Indeed, you can test this hypothesis by trying to capture one camera stream with rpicamera python module on a regular raspberry-pi and stereopi with the same software versions.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

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

Re: How to setup StereoPi using fresh Raspbian image

Post by Realizator »

Stereomaton, V4L2 has been mentioned in this stereoscopic mode for CM thread on RPi forum. There are about 7 pages, you can just search page by "V4L". As I understand, V4L2 driver exists, but stereoscopic mode is not implemented here (yet?).
Eugene a.k.a. Realizator

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: How to setup StereoPi using fresh Raspbian image

Post by stereomaton »

The (sub)question I answered was about how opencv captures videos, which did not mention stereoscopy. The only way I know with opencv is to capture monoscopic independant videos, or use external capture such as the python module mentioned in a previous post but which was not the subject of the question.

However, I have very little experience in this domain. Perhaps you know some other procedure that might be useful.

About v4l2, I don't remember any support of stereoscopy by the driver, so any attempt to support it nonetheless would probably be a hack. The last project I had with it was several years ago though.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: How to setup StereoPi using fresh Raspbian image

Post by stereomaton »

I just checked on my stereopi. The raspberry-pi CSI cameras do not have video4linux driver associated (at least it is not enabled in SLP by default), thus opencv complains about missing camera "VIDEOIO ERROR: V4L: can't open camera by index 0".

I realize that I was confused by names of the python picamera module (not rpicamera as I thought) and I misunderstood the message from Realizator who talked about this module to capture the streams. If I understood well, the problem that piofthings faces is precisely that this module makes the system freeze with a recent Raspbian system, hence my guesses on a probable cause to explore.

By the way, the code provided captures stereo image and writes it in foo.jpg as expected on my module with SLP.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

piofthings
Posts: 7
Joined: Fri Aug 30, 2019 11:29 pm

Re: How to setup StereoPi using fresh Raspbian image

Post by piofthings »

Hi @stereomaton, thank you very much for coming back with your results.

I am able to take pictures with Python Picamera script now. As long as I close the camera after each capture it works fairly reliably. Though I suggest the sample be updated to show use of try and finally for the camera cleanup :-)

I have to use 'sudo' (because I am not logged in as root on my Pi).

Code: Select all

from picamera import PiCamera

try:
    camera = PiCamera(stereo_mode='side-by-side', resolution=(1280,720))
    # Uncomment following lines if your images are upside down
    # camera.rotation = 180
    camera.capture('foo.jpg')
finally:
    camera.close()
However, raspistill and raspivid still refuse to work. They effectively put the stereopi in some deadlock condition which I can't even overcome by invoking `sudo shutdown now` or `sudo reboot`. I have to switch power off and turn it back on again.

Reminder: This is the latest Raspbian Buster image with the dt-blob.bin file provided by StereoPi documentation.

Also where is additional documentation for the side-by-side mode. My images are coming out wrong way round, left camera image on right and right camera image on left. Using hflip results in incorrect image, I want the side-by-side to be flipped not the image filpped.

piofthings
Posts: 7
Joined: Fri Aug 30, 2019 11:29 pm

Re: How to setup StereoPi using fresh Raspbian image

Post by piofthings »

I think most of my issues stem from trying to use the bleeding edge of technology... Raspbian Buster + self compiled version of OpenCV 4.1.0 doesn't seem to be working great. I am going to roll back to Raspbian Stretch and first try OpenCV from PiWheels, whatever version that is. If that works without issue, I'll try 'upgrading' to OpenCV 4.1.0

Overall I think all Windowing libraries are having trouble on Buster. In my case imshow seems to be crashing left, right and center. Even the raspistill issues I said was something to do with windowing (I plugged in a display and an image came up and then crashed everything. So unless someone sorts that out, I wouldn't reccomend a n00bie like me should try building their own Image from scratch using Raspbian Buster. Waay too many problems.

I'll report back on my experiments with Raspbian Stretch.

Realizator any comments on official Raspbian Buster support? I won't blame you if you say no clues yet :D ....

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

Re: How to setup StereoPi using fresh Raspbian image

Post by Realizator »

Hey @piofthings, welcome to the unknown territory of the newest releases! :-)
As I mentioned in Twitter, we prefer to use stable tested releases for production solutions. That's why it is not Buster, and not 4.xx version of OpenCV.
At first, some key points here:
1. Fresh-installed Buster has passed all raspistill and raspivid tests with our dt-blob.bin
2. I will test for OpenCV with Buster and update our image. But I will use PiWheels-compiled OpenCV. AFAIK it is 3.xx version, but there are also one 4.0.0.21 available. I will try to setup 3.x subversion, as it is "just works"
3. With our OpenCV image @Kai user have reported an issue about problems after update/upgrade (this thread). I'm doing upgrade at our OpenCV image to test this issue.

A bit offtop, but may be useful info. You see, RPi4 has another video subsystem. It is a problem for us, as in one of our production solution (based on classic RPi, not StereoPi) we're using video overlay for putting telemetry and additional data on the video. So all code from RPi3 does not work on RPi4. Forum discussions at Pi forum confirms this issue. I can suggest that some deep changes in Raspbian, intended for newest RPi4 support, might broke some features on older RPis. It's just back-compatibility issues, and I think they will be fixed in the nearest time.
Eugene a.k.a. Realizator

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

Re: How to setup StereoPi using fresh Raspbian image

Post by Realizator »

piofthings wrote:
Sun Sep 08, 2019 5:47 pm
Also where is additional documentation for the side-by-side mode. My images are coming out wrong way round, left camera image on right and right camera image on left. Using hflip results in incorrect image, I want the side-by-side to be flipped not the image filpped.
As for image flip. It is a bug in -3dswap option in raspistill and raspivid.
To say briefly, for swap left and right images add "-cs 1" option. This options makes master camera slave and vise versa.
If you use -hf (horisontal flip), each image in the stereopair will be flipped horisontally, but image will not be swapped.
If you will look inside SLP code, you find we use this "-cs 1" trick for flipping. It also works with the PiCamera.
Eugene a.k.a. Realizator

piofthings
Posts: 7
Joined: Fri Aug 30, 2019 11:29 pm

Re: How to setup StereoPi using fresh Raspbian image

Post by piofthings »

@realizator thank you so much and apologies for the the trouble I have caused. I am beginning the process of reverting to Vanilla buster with python3-opencv.

As to your note about Pi4, I am not trying anything on Pi4. My setup is StereoPi Slim + USB ports + CM3+ with 32Gb eMMC. I did try compiling OpenCV 4.1.0 on Pi4, just to test that the script actually works. I then used the same script on the CM3+ in my stereopi. Anyway, I'll just go with your suggestions for now.

If things don't work after this, I will attribute that to my rather melty CSI connector that I messed up while soldering. I'll try and replace that before any further complains :oops:

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

Re: How to setup StereoPi using fresh Raspbian image

Post by Realizator »

It's definitely a bug in the latest Raspbian update (or some libraries affected). We are about to localize it, as I mentioned in Twitter DM. I hope we will do it in the nearest time, as a lot of users are doing software upgrade right now on their Raspbian, and all of them are going right to this trap. :?
Eugene a.k.a. Realizator

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

Re: How to setup StereoPi using fresh Raspbian image

Post by Realizator »

UPD> After several tests I've put a question to RPi engineers at Raspberry Pi forum here: https://www.raspberrypi.org/forums/view ... 0#p1533680
Eugene a.k.a. Realizator

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

Re: How to setup StereoPi using fresh Raspbian image

Post by Realizator »

UPD>: if you're trying to use stereoscopic mode on a fresh Raspbian, you may use this solution suggested by RPi engineers:
https://forum.stereopi.com/viewtopic.ph ... =744#p1293
Eugene a.k.a. Realizator

Post Reply