Skip to main content

Clipper

A specialized OpenFilter component that extracts regions of interest (ROIs) from video frames using either detection metadata or predefined polygons. Supports multiple cropping modes, flexible output options, and comprehensive configuration validation.

Features

  • Multiple Cropping Modes: Polygon-based cropping, detection-based cropping, and legacy environment-based configuration
  • Flexible Output Options: Create new frames for cropped regions or modify original frames in-place
  • Topic Selection Modes: Process all topics, main only, or selected topics from a configured list
  • Configuration Validation: Prevents typos with helpful error messages and suggestions
  • Backward Compatibility: Supports legacy configuration via environment variables

Quick Start

Prerequisites

IMPORTANT! You need access to OpenFilter and the required dependencies:

# Install OpenFilter (if not already installed)
pip install openfilter

# Install the crop filter
pip install filter-crop

Installation

# Create virtual environment
virtualenv venv
source venv/bin/activate

# Install the filter
make install

Basic Usage

from openfilter import Filter

# Simple polygon cropping pipeline
filters = [
    Filter("VideoIn", {
        "sources": "file://sample_video.mp4",
        "outputs": "tcp://127.0.0.1:5550"
    }),
    Filter("FilterCrop", {
        "sources": "tcp://127.0.0.1:5550",
        "outputs": "tcp://127.0.0.1:5551",
        "polygon_points": "[[(100, 100), (400, 100), (400, 300), (100, 300)]]",
        "output_prefix": "cropped_",
        "topic_mode": "all"
    }),
    Filter("Webvis", {
        "sources": "tcp://127.0.0.1:5551",
        "outputs": "tcp://127.0.0.1:8080"
    })
]

Filter.run_multi(filters, exit_time=30.0)

Documentation

For comprehensive documentation including:

  • Complete configuration reference
  • Sample pipelines and use cases
  • Troubleshooting guides
  • API documentation

Refer to docs/overview.md

Development

Running Locally

# Run the filter locally
make run

# Navigate to http://localhost:8000 to see the output

Running in Docker

# Build the filter docker image
make build-image

# Generate docker-compose.yaml (if needed)
make compose

# Run the containerized filter
make run-image

Testing

# Run unit tests
make test

# Run specific test files
pytest tests/test_filter_crop.py -v
pytest tests/test_smoke_simple.py -v
pytest tests/test_integration_config_normalization.py -v

Configuration Examples

Basic Polygon Crop

{
    "id": "polygon_cropper",
    "sources": "tcp://127.0.0.1:5550",
    "outputs": "tcp://127.0.0.1:5551",
    "polygon_points": "[[(100, 100), (400, 100), (400, 300), (100, 300)]]",
    "output_prefix": "cropped_",
    "topic_mode": "all"
}

Detection-Based Crop

{
    "id": "detection_cropper",
    "sources": "tcp://127.0.0.1:5550",
    "outputs": "tcp://127.0.0.1:5551",
    "detection_key": "detections",
    "detection_class_field": "class",
    "detection_roi_field": "rois",
    "topic_mode": "main_only"
}

In-Place Modification

{
    "id": "inplace_cropper",
    "sources": "tcp://127.0.0.1:5550",
    "outputs": "tcp://127.0.0.1:5551",
    "polygon_points": "[[(100, 100), (400, 100), (400, 300), (100, 300)]]",
    "mutate_original_frames": true,
    "topic_mode": "main_only"
}

Multi-Camera Processing

{
    "id": "multi_camera_cropper",
    "sources": ["tcp://127.0.0.1:5550", "tcp://127.0.0.1:5551"],
    "outputs": "tcp://127.0.0.1:5552",
    "polygon_points": "[[(50, 50), (300, 50), (300, 250), (50, 250)]]",
    "topic_mode": "selected",
    "topics": ["camera1", "camera2"],
    "output_prefix": "region_"
}

Use Cases

  • Security Camera Monitoring: Extract specific regions from security camera feeds
  • Object Detection and Extraction: Extract detected objects for further analysis
  • Multi-Camera Surveillance: Process multiple camera feeds with selective region extraction
  • Content Creation and Editing: Extract specific regions for content creation

See docs/overview.md for detailed use case examples and sample pipelines.

Configuration Reference

Required Configuration

Key Type Description
sources string[] Input sources (e.g., tcp://127.0.0.1:5550)

Optional Configuration

Key Type Default Description
polygon_points string null Polygon coordinates for cropping
mutate_original_frames bool false Modify original frames instead of creating new ones
output_prefix string null Prefix for output topics
topic_mode string "all" How to handle multiple topics
topics string[] ["main"] List of topics to process when topic_mode="selected"
detection_key string "detections" Key for detection metadata
detection_class_field string "class" Field name for detection class
detection_roi_field string "rois" Field name for detection ROIs

Error Handling

The filter provides helpful error messages for common configuration mistakes:

  • Typo Prevention: Unknown config key "polygon_point". Did you mean "polygon_points"?
  • Invalid Polygon: Polygon must have at least three vertices.
  • Missing Output Prefix: output_prefix cannot be empty when mutate_original_frames is False

Release files for filter-crop 0.1.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for filter-crop 0.1.21
File Interpreter ABI Platform
filter_crop-0.1.21-py3-none-any.whl Python 3 none any Details

Release files / filter_crop-0.1.21-py3-none-any.whl

Download URL filter_crop-0.1.21-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63d7335e2c71388f93c38c6036d709f2557bf801c98117de8e0745269fe1fa13
BLAKE2b-256 checksum
How to use checksums
f610c00319b07e1bdf4b4e173b60ab64da5b34d33e165f2e0b5c97163d8db847
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release history Release notifications | RSS feed

This release

0.1.21 This release

1 release file

0.1.20

1 release file

0.1.19

1 release file

0.1.18

1 release file

0.1.17

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page