Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/2b-t/stereo-matching

Stereo-image depth reconstruction with different matching costs and matching algorithms in Python using Numpy and Numba
https://github.com/2b-t/stereo-matching

computer-vision docker jupyter-notebook ncc normalized-cross-correlation numba numpy python sad scipy semi-global-matching sgm ssd sum-of-squares winner-take-all wta

Last synced: about 2 months ago
JSON representation

Stereo-image depth reconstruction with different matching costs and matching algorithms in Python using Numpy and Numba

Awesome Lists containing this project

README

        

# Stereo matching

Author: [Tobit Flatscher](https://github.com/2b-t) (January 2020)

[![Dockerhub](https://github.com/2b-t/stereo-matching/actions/workflows/update-dockerhub.yml/badge.svg)](https://github.com/2b-t/stereo-matching/actions/workflows/update-dockerhub.yml) [![Tests](https://github.com/2b-t/stereo-matching/actions/workflows/run-tests.yml/badge.svg)](https://github.com/2b-t/stereo-matching/actions/workflows/run-tests.yml) [![Python 3.8.10](https://img.shields.io/badge/Python-3.8-yellow.svg?style=flat&logo=python)](https://www.python.org/downloads/release/python-3810/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Overview

Left image | Right image| Depth image
:-------------------------:|:-------------------------:|---------------------------
![Left image](data/Adirondack_left.png) | ![Right image](data/Adirondack_right.png) | ![Depth image](output/Adirondack_NCC_SGM_D70_R3_accX0,92.jpg)

This small tool is a **manual implementation of simple stereo-matching** in Python 3. Two rectified images taken from different views are combined to a **depth image** by means of two **matching algorithms**:

- a simple **winner-takes-it-all (WTA)** or
- a more sophisticated **semi-global matching (SGM)**

with several **matching costs**:

- **Sum of Absolute Differences (SAD)**,
- **Sum of Squared Differences (SSD)** or
- **Normalized Cross-Correlation (NCC)**.

The results are compared to a ground-truth using the accX accuracy measure excluding occluded pixels with a mask.

For the precise details of the involved formulas (matching cost, matching algorithms and accuracy measure) refer to [`doc/Theory.pdf`](./doc/Theory.pdf).

The repository is structured as follows:

```bash
.
├── data/ # Directory for the input images (left and right eye)
├── doc/ # Further documentation, in particular the computational approach
├── docker/ # contains a Docker container as well as a Docker-Compose configuration file
├── output/ # contains the resulting depth-image output
├── src/
│ ├── main.ipynb # The Jupyter notebook that allows a convenient access to the underlying Python functions
│ └── stereo_matching.py # The Python3 implementation of the core functions with Scipy, Scimage, Numba, Numpy and Matplotlib
├── test/ # contains parametrized unit tests for the implementations
├── .devcontainer/ # contains configuration files for containers in Visual Studio Code
└── .vscode/ # contains configuration files for Visual Studio Code
```

## 1. Download it
Either download and copy this folder manually or directly **clone this repository** by typing
```
$ git clone https://github.com/2b-t/stereo-matching.git
```

## 2. Launch it

Now you have two options for launching the code. Either you can install all libraries on your system and launch the code there or you can use the Docker container located in [`docker/`](./docker/).

### 2.1 On your system

For launching the code directly on your system make sure Scipy, Numba, Numpy and potentially also Jupyter are installed on your system by typing. If they are not installed on your system yet, install them - ideally with [Anaconda](https://www.anaconda.com/distribution/) or use the supplied Docker as described below.

#### 2.1.1 Jupyter notebook

For debugging purposes it can be pretty helpful to launch the Jupyter notebook by typing

```
$ jupyter notebook
```
Browse and open the Jupyter notebook [`src/main.ipynb`](./src/main.ipynb) and run it by pressing the play-button.

#### 2.1.2 Command line interface

Alternatively you can also edit the Python-file [`src/main.py`](./src/main.py) in your editor of choice (e.g. Visual Studio Code) and launch it from there or from the console. When launching it with `$ python3 main.py -h` it will tell you the available options that you can set.

#### 2.1.3 Library

Finally you can also use this package as a library. For this purpose have a look at [`src/main.py`](./src/main.py), [`src/main.ipynb`](./src/main.ipynb) as well as at the unit tests located in [`test/`](./test/) for a reference.

### 2.2 Run from Docker

This is discussed in detail in the document [`doc/Docker.md`](./doc/Docker.md).