Python version of the OpenPTV library - this is a work in progress
openptv-python keeps the Python API as the main interface and combines three
execution modes behind that API:
- Pure Python: the reference implementation and the easiest path for reading, debugging, and extending the code.
- Python + Numba: several hot kernels are JIT-compiled automatically on first use, so the Python implementation still benefits from acceleration.
- Native
optvbindings: selected operations reuse the native OpenPTV implementation when theoptvpackage is available.
At the moment, automatic native delegation is implemented for image preprocessing and full-frame target recognition. The rest of the library keeps the same Python API and remains usable even when those native paths are not in use.
This work started from the https://github.com/OpenPTV/openptv/tree/pure_python branch. It's a long-standing idea to convert all the C code to Python and now it's possible with ChatGPT to save a lot of typing time.
This repo is created using a cookiecutter and the rest of the readme describes the way to work with this structure
The project currently supports Python >=3.12,<3.14.
Create the environment and install the runtime dependencies:
uv venv
source .venv/bin/activate
uv syncThis gives you the standard runtime stack: NumPy, SciPy, Numba, and YAML support.
If you also want native optv delegation when bindings are available for your
platform and Python version, install the optional extra:
uv sync --extra nativeconda create -n openptv-python -c conda-forge python=3.12
conda activate openptv-python
pip install .Optional native bindings:
pip install ".[native]"uv venv
source .venv/bin/activate
uv sync --extra devconda create -n openptv-python -c conda-forge python=3.12
conda activate openptv-python
pip install -e ".[dev]"- The default install contains the runtime dependencies only.
- The optional
nativeextra addsoptvbindings for automatic native delegation on supported platforms. - The optional
devextra adds test, docs, typing, and pre-commit tooling for contributors. - The public API stays the same regardless of which backend extras are installed.
This is the base implementation for the whole library. It is always the source
of truth for the Python API and remains the fallback behavior for code paths
that are not delegated to optv.
Numba accelerates selected computational kernels inside the Python implementation. This is automatic; there is no separate API to enable it. Expect the first call to a JIT-compiled function to be slower due to compilation, with later calls running faster.
When optv imports successfully, openptv-python automatically reuses native
implementations for:
- image preprocessing
- full-frame target recognition / segmentation
These native paths are validated against the Python implementation by parity tests, so results stay backend-independent.
| Operation | Pure Python | Python + Numba | Native optv |
|---|---|---|---|
| Image preprocessing | Yes | Yes | Yes, automatic delegation |
| Target recognition / segmentation | Yes | Yes | Yes, automatic delegation |
| Point reconstruction | Yes | Partial internal kernels | Not used by default |
| Correspondence search / stereo matching | Yes | Partial internal kernels | Not used by default |
| Tracking | Yes | Partial internal kernels | Not used by default |
| Sequence parameter I/O | Yes | No | Available in native bindings |
Not used by default means the native path exists in benchmarks or conversion
helpers, but the regular openptv-python runtime path still uses the Python
implementation unless that operation is explicitly integrated later.
Use one of the installation methods above.
uv run python - <<'PY'
import openptv_python
import numba
try:
import optv
except ImportError:
print("optv not installed; native delegation disabled")
else:
print("optv ok", optv.__version__)
print("openptv_python ok")
print("numba ok", numba.__version__)
PY>>> import openptv_pythonuv run makeStress and performance tests are part of the default suite now. If you need a faster validation pass locally, you can skip them explicitly:
OPENPTV_SKIP_STRESS_BENCHMARKS=1 uv run makeFor the best experience create a new conda environment (e.g. DEVELOP) with Python 3.12:
conda create -n openptv-python -c conda-forge python=3.12
conda activate openptv-python
Before pushing to GitHub, use the developer install above and then run the following commands:
- Update conda environment:
make conda-env-updateoruv venvandsource .venv/bin/activatefollowed byuv sync --extra dev --upgrade - If you are using pip instead of uv, install the editable developer environment:
pip install -e ".[dev]" - Sync with the latest template (optional):
make template-update - Run quality assurance checks:
make qa - Run tests:
make unit-tests - Run the static type checker:
make type-check - Build the documentation (see Sphinx tutorial):
make docs-build
Copyright 2023, OpenPTV consortium.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.