Allegedly_Stupid
Posts: 6
Joined: Wed Aug 14, 2019 10:19 am

Can i produce a depth map using two cameras connected to two different raspberry pi's?

Wed Aug 14, 2019 10:29 am

Hey,

This is my first post here, so please bear with me.

I purchased two raspberry pi 3 B+ boards along with two cameras for a fun little project. I'm a newbie, and i'm interested to learn about computer vision. I initially wanted to buy CM3 because i can connect two cameras at the same time, but the IO board is expensive where i live (3rd world country problems smh) and stereo pi was out of the budget too. Somehow, i ended up buying two pi's and two cameras.

Anyways, my question is whether i can connect two pi's wirelessly and using two cameras as stereo cameras take photos and produce a depth map? Is that even possible?

User avatar
topguy
Posts: 5775
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Wed Aug 14, 2019 12:23 pm

Is that even possible?
It depends...

You can syncronize the camearas in different ways so that they take pictures a approximately the same time. This is probably easier to achieve on a CM3 but the big question is how much "synchronicity" do you really need ?
- Will the camera/pi or objects be moving when you take the pictures ? ( how fast ? )
- How often do you need to take pictures ?
- How quickly do you need them processed into a depthmap ?

Allegedly_Stupid
Posts: 6
Joined: Wed Aug 14, 2019 10:19 am

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Wed Aug 14, 2019 1:44 pm

Yes, the objects would be moving. I should've rephrased my question, i want to produce a depth map of a live video. The Pi and the cameras will be fixed at a position, and the objects would be moving so i want the camera to keep on capturing the video and produce the depth map at the same time.

Also, how can i connect two pi's wirelessly? and also how to make both of the cameras work together.

User avatar
topguy
Posts: 5775
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Wed Aug 14, 2019 11:47 pm

Why wirelessly ? Its unlikely the Pi's will be very far apart from eachother. Best option is to connect them with an short ethernet cable ( IMO ).

Well video is a very different thing.. it has usually smaller resolution that still images but it sets very strict limits on how much time you can use to create the depthmap. Maybe you should try the algorithm on two still images and see what performance you get on a Pi3.

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Thu Aug 15, 2019 2:06 am

You could mount two Raspberry Pi zero Ws together, and connected via 2 GPIO pins for the 'record' or 'sync' signal, and mount one camera on each one.

For Video use a muxer program, to mux both video (and audio) sources into one file.
Quite often it can be done using a secondary video channel in an MP4 file.
The right program can then extrapolate both video signals, and send them to their individual monitors, or as a muxed signal into 1 monitor (usually using R/B or Magenta/Green, or just as 2 video streams side by side, for 3D cardbox experiences).

For photos, it's quite easy.
You can use a bluetooth shutter, and connect it to one Raspberry Pi, while the second Pi will receive the shutter signal via a GPIO pin of the first one.
The photos should be taken within a fraction of a few ms from one another, so pretty identical.
You could also wire a single switch to 2 GPIO pins on each Pi, so that, by closing the switch, both pis will receive the signal simultaneously.
You can then very easily use the two photos for stereoscopic photography, merge the 2 photos in red-blue 3D photo programs, or use one of those 3D Wiggle photography web pages, that will merge 2 (or more) photos into 1 animated Gif.

You want to create a 3D sandbox thing like this?:
https://www.youtube.com/watch?v=j9JXtTj0mzE
Last edited by ProDigit on Thu Aug 15, 2019 2:35 am, edited 1 time in total.

User avatar
Gavinmc42
Posts: 3736
Joined: Wed Aug 28, 2013 3:31 am

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Thu Aug 15, 2019 2:14 am

There is an Ethernet broadcast mode.
Seen this done with 16-32 Pi's for full 3D surround.
Don't remember if it was video?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Allegedly_Stupid
Posts: 6
Joined: Wed Aug 14, 2019 10:19 am

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Fri Aug 16, 2019 1:29 pm

topguy wrote:
Wed Aug 14, 2019 11:47 pm
Why wirelessly ? Its unlikely the Pi's will be very far apart from eachother. Best option is to connect them with an short ethernet cable ( IMO ).

Well video is a very different thing.. it has usually smaller resolution that still images but it sets very strict limits on how much time you can use to create the depthmap. Maybe you should try the algorithm on two still images and see what performance you get on a Pi3.
Hey, sorry for the late reply.

Yeah, I ordered two ethernet cables. I feel like connecting the Pi's using ethernet cables is a better option compared to wireless connection for the time being.

I guess resolution should be smaller because of the performance constraints, because I've seen a few people work on the depth map thingy on videos and everybody pointed towards smaller resolution.

Anyhow, Ill be running some tests on two photos and see the performance like you said.

Thank you :)

Allegedly_Stupid
Posts: 6
Joined: Wed Aug 14, 2019 10:19 am

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Fri Aug 16, 2019 1:32 pm

ProDigit wrote:
Thu Aug 15, 2019 2:06 am
You could mount two Raspberry Pi zero Ws together, and connected via 2 GPIO pins for the 'record' or 'sync' signal, and mount one camera on each one.

For Video use a muxer program, to mux both video (and audio) sources into one file.
Quite often it can be done using a secondary video channel in an MP4 file.
The right program can then extrapolate both video signals, and send them to their individual monitors, or as a muxed signal into 1 monitor (usually using R/B or Magenta/Green, or just as 2 video streams side by side, for 3D cardbox experiences).

For photos, it's quite easy.
You can use a bluetooth shutter, and connect it to one Raspberry Pi, while the second Pi will receive the shutter signal via a GPIO pin of the first one.
The photos should be taken within a fraction of a few ms from one another, so pretty identical.
You could also wire a single switch to 2 GPIO pins on each Pi, so that, by closing the switch, both pis will receive the signal simultaneously.
You can then very easily use the two photos for stereoscopic photography, merge the 2 photos in red-blue 3D photo programs, or use one of those 3D Wiggle photography web pages, that will merge 2 (or more) photos into 1 animated Gif.

You want to create a 3D sandbox thing like this?:
https://www.youtube.com/watch?v=j9JXtTj0mzE
Hey, sorry for the late reply.

Well, I'll also be using PIR sensors for my project so i need GPIO pins which i guess doesn't come with Zero W?

Allegedly_Stupid
Posts: 6
Joined: Wed Aug 14, 2019 10:19 am

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Fri Aug 16, 2019 1:33 pm

Gavinmc42 wrote:
Thu Aug 15, 2019 2:14 am
There is an Ethernet broadcast mode.
Seen this done with 16-32 Pi's for full 3D surround.
Don't remember if it was video?
Hey, sorry for the late reply.

Alright, i'll look into it.

Thank you :)

User avatar
topguy
Posts: 5775
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Fri Aug 16, 2019 2:46 pm

Well, I'll also be using PIR sensors for my project so i need GPIO pins which i guess doesn't come with Zero W?
The PiZero have GPIO, it just doesnt always come with the pin-header presoldered. You can do it youself or solder wires directly if you want.

User avatar
Gavinmc42
Posts: 3736
Joined: Wed Aug 28, 2013 3:31 am

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Sat Aug 17, 2019 1:56 am

I think there is a GPIO pin trigger mode in the Raspistill software.
Not sure about video.

There is also a new small third party CM motherboard that has two camera inputs.
I have used Pi camera cables up to 1m long without problems.

Three versions of the Zero, if you are not good for the soldering just pay the extra for the presoldered header version.
But then you get close in pricing to the model A's which have the standard size camera connector for which there are more cable cable options.

I think the trouble with using two Pi's is extra processing the two video streams.
The Compute motherboard have two camera inputs.
But you might need 4 cores for the encoding.

Is there a standard video format for stereo?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Sat Aug 17, 2019 6:53 am

Allegedly_Stupid wrote:
Fri Aug 16, 2019 1:32 pm
ProDigit wrote:
Thu Aug 15, 2019 2:06 am
You could mount two Raspberry Pi zero Ws together, and connected via 2 GPIO pins for the 'record' or 'sync' signal, and mount one camera on each one.

For Video use a muxer program, to mux both video (and audio) sources into one file.
Quite often it can be done using a secondary video channel in an MP4 file.
The right program can then extrapolate both video signals, and send them to their individual monitors, or as a muxed signal into 1 monitor (usually using R/B or Magenta/Green, or just as 2 video streams side by side, for 3D cardbox experiences).

For photos, it's quite easy.
You can use a bluetooth shutter, and connect it to one Raspberry Pi, while the second Pi will receive the shutter signal via a GPIO pin of the first one.
The photos should be taken within a fraction of a few ms from one another, so pretty identical.
You could also wire a single switch to 2 GPIO pins on each Pi, so that, by closing the switch, both pis will receive the signal simultaneously.
You can then very easily use the two photos for stereoscopic photography, merge the 2 photos in red-blue 3D photo programs, or use one of those 3D Wiggle photography web pages, that will merge 2 (or more) photos into 1 animated Gif.

You want to create a 3D sandbox thing like this?:
https://www.youtube.com/watch?v=j9JXtTj0mzE
Hey, sorry for the late reply.

Well, I'll also be using PIR sensors for my project so i need GPIO pins which i guess doesn't come with Zero W?
Some sites sell them presoldered. I bought mine at $28. I know, rather expensive, but didn't want to go through the trouble of soldering them myself.

User avatar
rpdom
Posts: 15199
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Sat Aug 17, 2019 6:54 am

topguy wrote:
Fri Aug 16, 2019 2:46 pm
Well, I'll also be using PIR sensors for my project so i need GPIO pins which i guess doesn't come with Zero W?
The PiZero have GPIO, it just doesnt always come with the pin-header presoldered. You can do it youself or solder wires directly if you want.
The Pi Zero WH has the header presoldered.

jayben
Posts: 6
Joined: Mon Aug 19, 2019 9:56 pm

Re: Can i produce a depth map using two cameras connected to two different raspberry pi's?

Wed Aug 21, 2019 8:55 am

You may find it easier (and possibly cheaper) to use 2 USB webcams on one RPi, rather than the complication of coordinating 2 separate systems.

See this blog post for a simple Python program that uses 2 cameras at right-angles to track the position of an LED:

https://iosoft.blog/position-measuremen ... ras-opencv

Return to “Beginners”