A high-performance (or some might say: blazingly fast) implementation of event camera utilities using Rust with Python bindings via PyO3.
This library is insipred by numerous event camera libraries such
event_utils
Python library but
reimplemented in Rust for significantly better performance.
[!Warning]
This is a super experimental project and will have frequent breaking changes. It is primary being developed as a learning project for understanding Event Camera data processing and Event-Vision algorithms.
⬇ Installation
# Using pip
# Using uv (recommended)
For development:
# Using pip
# Using uv (recommended)
Installing with visualisation tools:
# Using pip
# Using uv (recommended)
For all dependencies including development, plotting, numpy, and Jupyter support:
# Using pip
# Using uv (recommended)
Development Setup
For detailed development setup instructions, see BUILD.md.
Quick setup:
# Clone repository
# Create virtual environment
# Install for development using uv (recommended)
# Or using pip
# Install pre-commit hooks
# Run tests
🗺️ Roadmap and Current Features
- Core event data structures and manipulation
- Event data loading and saving
- Event augmentation
- Random event addition
- Correlated event addition
- Event removal
- Event transformations
- Flipping events along x and y axes
- Clipping events to bounds
- Rotating events
- Event representations
- Voxel grid representation
- Event visualisation and display
- Event-to-video reconstruction
evlib
aims to become a comprehensive toolkit for event camera data processing,
combining high-performance Rust implementations with Python bindings for ease of
use. A tracking issue can be found here
Algorithm/Feature | Description | Status |
---|---|---|
Core Event Data Structures | Basic event representation and manipulation | ✅ Implemented |
Event Augmentation | Random/correlated event addition/removal | ✅ Implemented |
Event Transformations | Flipping, rotation, clipping | ✅ Implemented |
Voxel Grid | Event-to-voxel grid conversion | ✅ Implemented |
Visualisation | Event-to-image conversion tools | ✅ Implemented |
E2VID (Basic) | Simple event-to-video reconstruction | ✅ Implemented |
OpenEB Format Support | Compatibility with OpenEB data formats | ⏳ Planned |
OpenEB HAL Integration | Hardware abstraction for cameras | ⏳ Planned |
OpenEB Streaming | Real-time event stream processing | ⏳ Planned |
E2VID (Advanced) | Neural network reconstruction | ⏳ Planned |
Vid2E Simulation | Video-to-event conversion | ⏳ Planned |
ESIM Framework | Event camera simulation | ⏳ Planned |
HyperE2VID | Advanced reconstruction with hypernetworks | ⏳ Planned |
RVT Object Detection | Event-based object detection | ⏳ Planned |
Optical Flow | Event-based optical flow estimation | ⏳ Planned |
Depth Estimation | Event-based depth estimation | ⏳ Planned |
🚀 Performance
Evlib is significantly faster than pure Python implementations, thanks to its Rust backend. The benchmark compares the Rust-backed evlib implementation against equivalent pure Python implementations of the same functions, in both single-core and multi-core scenarios.
Single-core Performance
Operation | Python Time (s) | Rust Time (s) | Speedup |
---|---|---|---|
events_to_block | 0.040431 | 0.000860 | 47.03x |
add_random_events | 0.018615 | 0.003421 | 5.44x |
flip_events_x | 0.000023 | 0.000283 | 0.08x |
Benchmark performed with 100,000 events on a single core
Multi-core vs Single-core Performance
Operation | Python (1 core) | Python (10 cores) | Rust (1 core) | Rust vs Py (1 core) | Rust vs Py (10 cores) |
---|---|---|---|---|---|
events_to_block | 0.040431 s | 0.315156 s | 0.000860 s | 47.03x | 366.58x |
add_random_events | 0.018615 s | 0.360760 s | 0.003421 s | 5.44x | 105.44x |
flip_events_x | 0.000023 s | 0.303467 s | 0.000283 s | 0.08x | 1072.67x |
Benchmark performed with 100,000 events. Note that for these specific operations and data sizes, the multi-core Python implementation is slower due to process creation overhead.
Why Rust is Faster
The significant performance gains come from several factors:
- Compiled vs Interpreted: Rust is compiled to native machine code, while Python is interpreted
- Memory Management: Rust's ownership model allows for efficient memory use without garbage collection
- Low-level Optimisations: Rust can take advantage of SIMD (Single Instruction Multiple Data) vectorisation
- Static Typing: Rust's type system enables compiler optimisations that aren't possible with Python's dynamic typing
- Zero-cost Abstractions: Rust provides high-level abstractions without runtime overhead
- Efficient Concurrency: Rust's thread safety guarantees and lack of GIL allow for better parallelisation
Run python examples/benchmark.py
to benchmark on your own system.
⮑ Module Structure
The library is organized into the following modules:
evlib.core
: Core event data structures and functionsevlib.augmentation
: Event augmentation utilitiesevlib.formats
: Data loading and savingevlib.representations
: Event representation algorithms (e.g., voxel grid)evlib.visualization
: Visualisation toolsevlib.processing
: Advanced event processing (including event-to-video reconstruction)
Basic Usage
# Create example event data
=
=
=
=
# Convert to block representation
=
# (4, 4)
Loading Event Data
# Load events from file (automatically detects format)
, , , =
# Save events to HDF5 format
# Save events to text format
Event Augmentation
# Create sample event data
=
=
=
=
# Add random events
= 20
, , , =
# Add correlated events (events near existing ones)
= 15
= 2.0 # Standard deviation for x,y coordinates
= 0.005 # Standard deviation for timestamps
, , , =
Event Transformations
# Create sample event data
=
=
=
=
# Set the sensor resolution
= # (height, width)
# Flip events along x-axis
, , , =
# Flip events along y-axis
, , , =
# Rotate events by 45 degrees
= / 4 # 45 degrees
= # Center of rotation
, , , =
# Clip events to bounds
= # [min_y, max_y, min_x, max_x]
, , , =
Event Representations (Voxel Grid)
# Create event data (1D arrays)
=
=
=
=
# Convert events to voxel grid
= 5
= # (width, height)
= # Options: "count", "polarity", "time"
# Pass parameters in correct order
=
# (5, 100, 100)
Event Visualisation
# Create directory for saved figures
# Create event data
=
=
=
=
# Draw events to image
= # (width, height)
= # Options: "red-blue", "grayscale"
# Pass parameters in correct order
=
# Save figure (optional)
Event-to-Video Reconstruction
# Create directory for saved figures
# Load events
, , , =
# Use subset of events for faster processing (optional)
= 10000
=
=
=
=
# Determine sensor resolution from events
= + 1
= + 1
# Reconstruct a single frame from events
= 5 # Number of time bins for voxel grid
=
# Display the reconstructed frame
# Save figure (optional)
# For multiple frames (reconstructing a sequence)
# Define time windows and reconstruct frames for each
=
, = ,
= 5
= /
= + *
= <=
=
=
=
=
=
# Save each frame (optional)
⚖️ License
MIT