Library for images and video processing.
Project description
ntt
ntt is a Python module that provides simple and consistent interfaces for common image and video processing tasks. It wraps around popular Python libraries to simplify their usage and make them interchangeable, to build complex pipelines. In particular:
- Pillow – image file handling
- OpenCV – computer vision, image and video processing
- imageio – read/write images and videos
- scikit-image – scientific image processing
- NumPy – arrays and calculations
Installation
Using venv (recommended)
- Create a virtual environment:
python -m venv venv
- Activate the environment:
- On macOS/Linux:
source venv/bin/activate
- On Windows:
venv\Scripts\activate
- Install the module:
The module is available on Pypi:
pip install ntt
Or install the development version from source:
git clone
pip install -e .
Tests
import ntt
print(ntt.__version__) # Check the version
Assuming you have cloned the repository or installed the source package, you can run tests with pytest:
$ pytest tests
Samples
To download the data samples (videos, images, sounds, etc.) used in tests and examples, clone the repository and update the .env file with the path to the cloned folder:
git clone https://github.com/centralelyon/ntt-samples.git
Alternatively, you can generate fake videos samples by running the following script:
from ntt.videos.video_generation import random_video
video = random_video(320, 240, 10, 2)
Building pipelines
An interesting use of ntt is to build complex pipelines for video and image processing. For that, we also built a separate tool, the Pipeoptz library, which provides a simple way to create and manage pipelines of functions.
The image above is generated using the code below available as a gist.
import random
from ntt.frames.frame_generation import random_frame
from ntt.frames.display import display_frame
from pipeoptz import Pipeline, Node
def random_number():
num = random.randint(100, 600)
return num
pipeline = Pipeline("Simple Pipeline", "Generate a random image.")
node_gen_width = Node("GenWidth", random_number)
node_gen_height = Node("GenHeight", random_number)
node_random_frame = Node(
"random_frame", random_frame, fixed_params={"width": 10, "height": 3}
)
pipeline.add_node(node_gen_width)
pipeline.add_node(node_gen_height)
pipeline.add_node(
node_random_frame, predecessors={"width": "GenWidth", "height": "GenHeight"}
)
outputs = pipeline.run()
display_frame(outputs[1][pipeline.static_order()[-1]])
Examples
You may look at the examples folder to see how to use ntt functions. Also a look a the tests folder to see how functions are tested. And of course, the documentation at https://ntt.readthedocs.io.
Assuming you have a crop.mp4 video in a samples folder and an output
folder, here is how to use extract_first_frame function.
import os
from dotenv import load_dotenv
from ntt.frames.frame_extraction import extract_first_frame
if __name__ == "__main__":
load_dotenv()
output = extract_first_frame(
video_path_in=os.environ.get("NTT_SAMPLES_PATH"),
video_name_in="crop.mp4",
frame_path_out=os.environ.get("PATH_OUT"),
frame_name_out="crop-ex.jpg",
)
print(f"Frame successfully extracted at {output}") if output is not None else print(
"Frame extraction failed"
)
CircleCI
The project is configured to run tests on CircleCI. The configuration file is
.circleci/config.yml.
Docker
A Dockerfile is provided to quickly set up an environment with all system dependencies (OpenCV, FFmpeg, etc.) and run tests or scripts.
Build the image
docker build -t ntt .
Run tests
By default, running the container executes the pytest test suite:
# Run tests using the code inside the container
docker run --rm ntt
During development, you can mount your local directory to run tests on your current code:
# Linux / macOS / Windows PowerShell
docker run --rm -v ${PWD}:/app ntt
# Windows Command Prompt (cmd)
docker run --rm -v "%cd%:/app" ntt
Run a custom script
You can override the default command to run a specific Python script:
docker run --rm -v ${PWD}:/app ntt python tests/test_random_strings.py
Run in interactive mode
To explore the container or run multiple commands manually, start a bash shell:
docker run --rm -it -v ${PWD}:/app ntt bash
Acknowledgments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ntt-0.1.5.3.tar.gz.
File metadata
- Download URL: ntt-0.1.5.3.tar.gz
- Upload date:
- Size: 30.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68ffe18de4f1a3e2ffd219c1193993ec2d3bd59014927d3c112dfeef8638f52d
|
|
| MD5 |
90a90fa567f5dfe682db2cad82a6ff01
|
|
| BLAKE2b-256 |
9a83f327c62bf4d87f4c94021b95072c91fb428187464eab888a7a6eee245187
|
Provenance
The following attestation bundles were made for ntt-0.1.5.3.tar.gz:
Publisher:
python-publish.yml on centralelyon/ntt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ntt-0.1.5.3.tar.gz -
Subject digest:
68ffe18de4f1a3e2ffd219c1193993ec2d3bd59014927d3c112dfeef8638f52d - Sigstore transparency entry: 1037876974
- Sigstore integration time:
-
Permalink:
centralelyon/ntt@1de4c6ba7b427ad384a9b2b5b539744f7caab740 -
Branch / Tag:
refs/tags/v0.1.5.3 - Owner: https://github.com/centralelyon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@1de4c6ba7b427ad384a9b2b5b539744f7caab740 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ntt-0.1.5.3-py3-none-any.whl.
File metadata
- Download URL: ntt-0.1.5.3-py3-none-any.whl
- Upload date:
- Size: 39.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f11de585935ae13b3afc708be82ef2bcccc3cfdb1bdb433bfc8cd20ac8d9994e
|
|
| MD5 |
514294632e90eb36aecc8f1c477d4893
|
|
| BLAKE2b-256 |
be17b39eb2ef954f6d5edf0e146d8a9cc61e4b8bf58ea1011c9a426b3d772cb3
|
Provenance
The following attestation bundles were made for ntt-0.1.5.3-py3-none-any.whl:
Publisher:
python-publish.yml on centralelyon/ntt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ntt-0.1.5.3-py3-none-any.whl -
Subject digest:
f11de585935ae13b3afc708be82ef2bcccc3cfdb1bdb433bfc8cd20ac8d9994e - Sigstore transparency entry: 1037877038
- Sigstore integration time:
-
Permalink:
centralelyon/ntt@1de4c6ba7b427ad384a9b2b5b539744f7caab740 -
Branch / Tag:
refs/tags/v0.1.5.3 - Owner: https://github.com/centralelyon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@1de4c6ba7b427ad384a9b2b5b539744f7caab740 -
Trigger Event:
release
-
Statement type: