Generate Depth Map on Every Raspberry Pi Model Easily with Arducam Stereo Camera HAT and OpenCV, No Compute Module Needed
Stereo vision for Raspberry Pi
Most creatures have evolved to see the world with two eyes, but most of the Rasberry Pi models have not – the standard Raspberry Pi only comes with a single camera port. Hard as we try, the multi-camera and stereo vision applications on a Raspberry Pi did not deliver a smooth experience, until Arducam introduced the synchronized stereo camera HAT. It allows the simultaneous connection of two Pi cameras but tricks the Pi board to believe only one is connected.
That being said, it’s not totally impossible to use a stereo camera setup on the Raspberry Pi platform. With a Raspberry Pi Compute Module and a StereoPi, you can make good used of the dual-camera system. However, won’t it be cool if all those features can come to the standard consumer-end Raspberry Pi model, like the Raspberry Pi 3/4?
That is a challenge that Arducam stereo camera HAT can take. Recently, we have used the HAT to build a depth mapping system with some software help from OpenCV and hardware help from our stereo camera board, just like what you would expect from the setup mentioned above.
Open Computer Vision (OpenCV) and Depth Mapping
OpenCV, short for Open Computer Vision, is a huge set of libraries of programs for real-time computer vision. As it’s easy to use and open-source, it’s extremely popular among developers. With both images from the same scene captured, OpenCV can be used to get depth information from that and calculate a depth map with some simple mathematics.
A depth map, on the other hand, is like a contour map(such as a topographic map) but without the contour lines for illustration. Objects from different distances will be painted in different colors, so you can easily tell from the map what is in the front and what’s in the back. The depth map brings some kind of intelligence to the camera set up to capture more information other than the picture itself, and the depth information can be used in a lot of projects such as robotics.
Depth Map Image Samples
Here are some of the depth map we’ve generated with Arducam stereo camera HAT.
Tutorials on Depth Mapping with Arducam Stereo Camera HAT
You can read about a detailed tutorial about how to get a depth map with Raspberry Pi from our documentation here.
Can I use two spy cameras instead?
Yes, it is possible, but more tiny handwork. You have to wire one camera oscillator output to the other camera and remove the current one. It is better to use a stereo camera bar with two cameras on the bar and connect it directly to the 5MP stereo camera HAT without effort.
Does this stereo board work on Raspberry Pi Zero W?
Yes, it does (Once you’ve soldered the GPIO pins to the Pi Zero or get a pre-soldered one). Check the following pictures about how it looks like with a Pi Zero.
Is there a way to wire two of the official V2 modules up and use them as a stereoscopic camera?
Yes, remove the resistor and crypto IC marked in a circle from one of the camera board and using jumping wires soldered to the pads as shown in the picture below, and twist the jumping wires to improve the signal quality. However, we will recommend you to use our 8MP stereo Camera board.
Can I try this dual camera on Nvidia Jetson Nano?
As the Jetson Nano comes with the same 40-pin GPIO and MIPI CSI-2 camera slot, it’s feasible to use this stereo camera on that platform. You can check more information about using this HAT on Jetson Nano here.