A Python tool for extracting and visualizing contours in videos.
Project description
ContourVision: Video Contour Extraction Tool ContourVision is a Python library designed for extracting and visualizing contours from video files. It allows users to process videos and obtain an output where object outlines are highlighted.
Features Converts video frames to grayscale.
Applies Otsu's method for automatic thresholding.
Finds external contours of objects in frames.
Outputs video with:
White contours on a black background.
Black contours on a white background.
Simple and easy-to-use class interface.
(Future) Draw contours directly on the original color frames.
Installation You can install ContourVision using pip.
From PyPI (Once Published) pip install contourvision
From Source (for development) Clone the repository:
git clone https://github.com/viliusbankauskas/contourvision.git
cd contourvision
Install in editable mode:
pip install -e .
Dependencies Python 3.8+
OpenCV (opencv-python >= 4.0)
NumPy (numpy >= 1.19)
These dependencies will be automatically installed if you install ContourVision via pip (as they are listed in setup.py).
Usage Example Create a Python script (e.g., process_my_video.py):
from contourvision import VideoContourExtractor import os
Define paths for your input video and desired output
input_video_file = "path/to/your/video.mp4" # REQUIRED: Change this to your video file
output_dir = "processed_videos" # A directory to store output videos
os.makedirs(output_dir, exist_ok=True) # Create the output directory if it doesn't exist
output_video_wb = os.path.join(output_dir, "result_white_on_black.avi")
output_video_bw = os.path.join(output_dir, "result_black_on_white.avi")
if not os.path.exists(input_video_file):
print(f"Error: Input video '{input_video_file}' not found.")
else:
try:
# Initialize the extractor for white contours on a black background
print(f"Processing for white on black: {input_video_file} -> {output_video_wb}")
extractor_wb = VideoContourExtractor(contour_style='white_on_black')
extractor_wb.process_video(input_video_file, output_video_wb)
print(f"White on black processing finished. Output: {output_video_wb}")
# Initialize the extractor for black contours on a white background
print(f"Processing for black on white: {input_video_file} -> {output_video_bw}")
extractor_bw = VideoContourExtractor(contour_style='black_on_white')
extractor_bw.process_video(input_video_file, output_video_bw)
print(f"Black on white processing finished. Output: {output_video_bw}")
print(f"\nAll processing done. Check outputs in '{output_dir}'.")
except Exception as e:
print(f"An error occurred during processing: {e}")
import traceback
traceback.print_exc()
Remember to replace "path/to/your/video.mp4" with the actual path to your video file.
How to Run the Included Example The project includes an example script to demonstrate its usage.
Locate a test video: Ensure you have a video file (e.g., .mp4, .avi) for testing. You can place it in the examples/input_videos/ directory for convenience, or note its absolute path.
Configure the example script:
Open examples/run_contour_detection.py.
Find the line input_path = "examples/input_videos/test.mp4"
Change this string to the correct path of your test video file.
Navigate to the project root: Open your terminal or command prompt and navigate to the main directory of the ContourVision project (the one containing setup.py and the examples folder).
Run the script:
python examples/run_contour_detection.py
Output videos will be saved in the examples/output_videos/ directory by default.
Future Enhancements Draw on Original Frame: Implement the on_original contour style to draw contours directly on the original color video frames.
More Thresholding Methods: Add support for other thresholding techniques beyond Otsu's method.
Contour Customization: Allow users to configure contour thickness, color (for on_original), and type (e.g., cv2.RETR_LIST, cv2.RETR_TREE).
Command-Line Interface (CLI): Develop a CLI using argparse or click for easier use without writing Python scripts.
Performance Optimization: Investigate potential performance improvements for processing long videos.
Error Handling: Enhance error handling and provide more informative messages.
Unit Tests: Write comprehensive unit tests for all functionalities.
Documentation: Expand documentation, possibly using tools like Sphinx or MkDocs for a dedicated documentation site.
Output Formats: Allow specifying different output video codecs and containers.
License This project is licensed under the MIT License. Please see the LICENSE file in the repository for the full license text.
Contributing Contributions are welcome!
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 contourvision-0.1.6.tar.gz.
File metadata
- Download URL: contourvision-0.1.6.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26e4fb9c017d8805587f98da1c5db8b2dcedc84edb5f306472b007a5860e5855
|
|
| MD5 |
bb2d2da057f109ede6c90613358a6bb8
|
|
| BLAKE2b-256 |
77449b6cf329e48f74cb3af78030d171b12dd95ea281a46051668a4b0666c3ed
|
File details
Details for the file contourvision-0.1.6-py3-none-any.whl.
File metadata
- Download URL: contourvision-0.1.6-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90a16d516981cb0903625f308c3c5de55442f180f54e8daa7d7b365f161d6822
|
|
| MD5 |
ec57cbe88e35cf7438bc04af1ff4ba6e
|
|
| BLAKE2b-256 |
a64dcc3ded4943f5b72d4da69712aaf6c41f35e077e9507eb1f7f93be18f3124
|