Skip to main content

A Python package for video annotation, object tracking, and cropping

Project description

Video Annotator

Video Annotator is a Python package designed for video annotation, object tracking, and cropping. It leverages the powerful Supervision library for seamless integration with various inference models and provides customizable annotators for bounding boxes, labels, ellipses, and other visual elements.


🚀 Features

  • Object Detection and Annotation: Add bounding boxes, labels, and shapes to objects detected in video frames.
  • Object Tracking: Track objects across frames with unique IDs.
  • Object Cropping: Extract regions of interest (ROIs) based on detected objects.
  • Highly Customizable: Fully customizable colors, styles, and text options for annotations.
  • Integration Friendly: Compatible with a variety of object detection models via the supervision library.

🛠️ Installation

To install the package, simply run:

pip install video-annotator

📖 Usage
1. Annotating Frames

from video_annotator import VideoAnnotator
import supervision as sv

# Load a detection model
model = sv.load_model("path/to/your/model")

# Initialize the annotator
annotator = VideoAnnotator(
    model=model,
    box_colors=["#FF8C00"],
    label_colors=["#00FF00"],
    label_text_color="#000000"
)

# Load a frame from a video
video_path = "path/to/video.mp4"
frame_generator = sv.get_video_frames_generator(video_path)
frame = next(frame_generator)

# Annotate the frame
annotated_frame = annotator.annotate_frame(frame, confidence_threshold=0.3)

# Display the annotated frame
sv.plot_image(annotated_frame)

2. Object Tracking
from video_annotator import AdvancedVideoTracker

# Initialize the tracker
tracker = AdvancedVideoTracker(
    model=model,
    ellipse_colors=["#FF6347"],
    label_colors=["#4682B4"],
    label_text_color="#FFFFFF",
    triangle_color="#FFD700"
)

# Annotate a single frame with tracking
annotated_frame = tracker.process_frame(
    video_path="path/to/video.mp4",
    ball_id=0,
    confidence_threshold=0.3
)

3. Collecting Crops
from video_annotator import CropCollector

# Initialize crop collector
collector = CropCollector(
    model=model,
    stride=30,
    confidence_threshold=0.3
)

# Collect crops of objects with a specific class ID
crops = collector.collect_crops(video_path="path/to/video.mp4", class_id=2)

# Save or process the crops as needed
for idx, crop in enumerate(crops):
    sv.save_image(crop, f"crop_{idx}.png")

🎨 Customization

All annotators can be customized with various parameters:

    Colors: Use HEX codes for custom colors.
    Styles: Adjust thickness, font sizes, and positions.
    Tracking Options: Set tracking parameters such as NMS thresholds.

🌟 Advanced Features

    Batch Processing: Use the frame generator for batch annotation.
    Video Export: Save annotated frames back into a video file:

from video_annotator.utils import save_annotated_video

save_annotated_video(
    video_path="path/to/input_video.mp4",
    output_path="path/to/output_video.mp4",
    annotator=annotator,
    confidence_threshold=0.3
)

📂 Project Structure

video-annotator/
│
├── video_annotator/
│   ├── __init__.py
│   ├── annotators.py   # Core classes for annotation   ├── tracker.py      # Advanced tracking logic   ├── cropper.py      # Crop collection functionality   ├── utils.py        # Utility functions (e.g., video export)
│
├── tests/              # Unit tests
├── examples/           # Example scripts
├── README.md           # Project documentation
├── setup.py            # Package setup file

📚 Dependencies

    supervision
    tqdm
    opencv-python
    pytest (for testing)

Install dependencies via:

pip install -r requirements.txt

💡 Examples

Check the examples folder for more detailed use cases:

    Annotating a single frame
    Batch processing frames
    Exporting annotated video
    Advanced object tracking

🤝 Contributing

Contributions are welcome! To contribute:

    Fork the repository.
    Create a new branch (feature/my-feature).
    Commit your changes.
    Push to the branch.
    Open a pull request.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.
🛠️ Support

If you encounter any issues, feel free to open an issue or reach out to [project email/contact].

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

video_annotator-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

video_annotator-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file video_annotator-0.1.1.tar.gz.

File metadata

  • Download URL: video_annotator-0.1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for video_annotator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5164f0ca13e952716e520217dcb212ffd62b7b9523bfc6369bcadb48b126fc70
MD5 38bc5e2b6e236b34083c7cd720079f48
BLAKE2b-256 8dd9d9990d5eec13d6e1351089fdc67eacd83e7ba131b367f919c65d031e2c14

See more details on using hashes here.

File details

Details for the file video_annotator-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for video_annotator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ef3f49d89ac01acc389368587baac1cc78c4b7acfd9d6f669f39baa7a247fb2
MD5 d4a229edd72540ac671ce34bef4a1fed
BLAKE2b-256 49986b7ca3feee2ff84dd47f1708d2c6a05ade9b9df312bdd6a559623cbca524

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page