Skip to content

Matchstic/depthmapper

Repository files navigation

depthmapper

This is a (relatively) small utility to be used as a testbed for experimenting with stereo depth mapping in OpenCV.

I built this to find how well depth mapping works on the Nvidia Jetson Nano. Support is present for StereoBM and StereoSGBM, as well as experimental support for AANet+.

Hardware-wise, this utility has been used with the WaveShare IMX219-83 stereo camera.

Python 3.6 or higher is needed.

See this YouTube video for a brief(-ish) overview:

Stereo depth mapping with OpenCV and Jetson Nano | DIY drone pt. 2

Running the utility

First, update submodules: git submodule update --init --recursive

You'll want to install requirements:

conda env create -f environment.yml
conda activate depthmapper

(note: PyTorch is optional)

Assuming you have a stereo camera board attached and available on /dev/video0 and /dev/video1, you should be able to just run:

python3 main.py

By default, cameras are accessed using nvarguscamerasrc which is specific to the Nvidia Jetson family. You should change this in lib/helpers.py if this is incorrect for your hardware setup.

You can choose which algorithm is used via the -m command line switch:

python main.py -m <algorithm>

options:

-m stereobm
-m stereosgbm
-m aanet

StereoBM is the default if this option is omitted.

Note on AANet

AANet is an optionally supported algorithm, and as such you don't need PyTorch installed if you don't plan to use it.

If you do want it, you'll want to download a pre-trained model for it. These can be downloaded from here, then placed into ./models. Make sure to update settings.conf to the name of the model you wish to use.

Output

For now, output is the generated disparity map and is shown in a new window. By default, the left hand frame the map corresponds to is shown too.

Configuration

All configuration is to be done via a config file, named settings.conf. I've made sure to write comments in the default configuration file to give an understanding of what each parameter does.

This file needs to live next to main.py, and will be automatically loaded.

Considerations

On the Nvidia Jetson, OpenCV is installed by default with Python bindings. However, you may wish to use a virtual environment for Python. I used an arm64 version of Miniforge3.

License

BSD 2-clause.

This software is freely available, but isn't very useful outside a bench testing scenario.

About

Python utility to experiment with StereoBM and StereoSGBM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages