Skip to content

OsloVision/anpr-rpi-standalone

Repository files navigation

ANPR Standalone - License Plate Recognition System

A comprehensive standalone ANPR (Automatic Number Plate Recognition) system with Streamlit web interface, featuring Norwegian vehicle registry integration and support for Hailo AI accelerators.

ANPR System

πŸš€ Features

  • 🎯 Complete ANPR Pipeline: Video capture β†’ Inference β†’ License plate reading β†’ Registry validation
  • 🌐 Web Interface: Interactive Streamlit UI with real-time processing
  • πŸ€– AI-Powered OCR: PaddleOCR HTTP API for accurate license plate text extraction
  • πŸ‡³πŸ‡΄ Norwegian Registry: Dual lookup against Norwegian vehicle registries
  • πŸ’Ύ Database Integration: SQLite database for tracking all registry checks
  • 🎬 Video Processing: Support for camera recording and batch video processing
  • ⚑ Hardware Acceleration: Optional Hailo AI accelerator support
  • πŸ”„ Fallback Support: Works with or without specialized hardware
  • 🌍 Internationalization: English and Norwegian interface
  • πŸ” Secure Configuration: Environment-based API key management

πŸ“‹ Table of Contents

πŸ›  Installation

Option 1: Pip Installation (Recommended)

# Install the package
pip install anpr-standalone

# Or install from source
git clone https://github.com/OsloVision/anpr-standalone.git
cd anpr-standalone
pip install -e .

Option 2: Manual Setup

# Clone the repository
git clone https://github.com/OsloVision/anpr-standalone.git
cd anpr-standalone

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\\Scripts\\activate

# Install dependencies
pip install -r requirements.txt

System Dependencies

For video recording functionality:

# Ubuntu/Debian
sudo apt-get install v4l-utils ffmpeg

# macOS
brew install ffmpeg

# Windows
# Download ffmpeg from https://ffmpeg.org/download.html

βš™οΈ Configuration

1. API Keys Setup

Copy the environment template and configure your API keys:

cp .env.example .env
nano .env

Add your API configuration to .env:

# Required: PaddleOCR API URL for license plate text extraction
PADDLEOCR_API_URL=http://localhost:5000

# Optional: Norwegian Vehicle Registry API key
VEHICLE_API_KEY=your-norwegian-vehicle-api-key-here

2. Model Configuration

The system supports multiple inference backends:

  • Hailo AI Accelerator (if available)
  • Demo Mode (for testing without hardware)
  • ONNX Runtime (coming soon)
  • TensorFlow (coming soon)

πŸš€ Quick Start

Start the Web Interface

# Using installed package
anpr-ui

# Or run directly
streamlit run streamlit_ui.py

Complete Workflow

  1. 🎬 Capture: Record videos using connected USB camera
  2. 🧠 Infer: Process videos to detect and extract license plates
  3. 🎨 Postprocess: Run ANPR analysis with Norwegian registry lookup

Command Line Usage

# Process a single image
python -m anpr.license_plate_reader image.jpg

# Process with registry check
python -m anpr.license_plate_reader --check-registry image.jpg

# Batch process directory
python -m anpr.license_plate_reader --batch /path/to/images/

πŸ“– Usage

Web Interface

The Streamlit web interface provides a complete 3-step workflow:

Step 1: Capture πŸ“Ή

  • Connect USB camera
  • Configure recording settings
  • Record traffic videos
  • View recent captures

Step 2: Infer 🧠

  • Load AI model (Hailo HEF or other formats)
  • Process captured videos
  • Extract license plate regions
  • Generate detection crops

Step 3: Postprocess 🎨

  • Configure API keys
  • Run ANPR on detection crops
  • Check Norwegian vehicle registries
  • Save results to database
  • Move processed crops to organized folders

API Usage

import anpr

# Initialize ANPR system
anpr_system = anpr.ANPRSystem()

# Process an image
result = anpr_system.process_image("license_plate.jpg")
print(f"License plate: {result.license_plate}")
print(f"Registry status: {result.registry_status}")

# Process a video
results = anpr_system.process_video("traffic_video.mp4")
for result in results:
    print(f"Frame {result.frame_number}: {result.license_plate}")

Database Integration

from anpr import LoanStatusDB

# Initialize database
db = LoanStatusDB("anpr_results.db")

# Query results
records = db.list_all_records()
for record in records:
    print(f"{record.numberplate}: {record.loan_status}")

# Check specific plate
result = db.get_loan_status("ABC123")
if result:
    print(f"Found: {result.loan_status}")

πŸ— Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Video Input   │───▢│   AI Inference  │───▢│   ANPR Engine   β”‚
β”‚  (Camera/File)  β”‚    β”‚ (Hailo/Demo/etc)β”‚    β”‚(PaddleOCR API)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                        β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Database      │◀───│   Registry      │◀───│   Text Extract  β”‚
β”‚   (SQLite)      β”‚    β”‚   Lookup (NO)   β”‚    β”‚   & Validate    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Package Structure

anpr-standalone/
β”œβ”€β”€ anpr/                 # Core ANPR functionality
β”‚   β”œβ”€β”€ license_plate_reader.py
β”‚   β”œβ”€β”€ loan_db_utils.py
β”‚   └── norwegian_vehicle_api.py
β”œβ”€β”€ hailo/                # Hailo AI integration
β”‚   β”œβ”€β”€ hailo_inference.py
β”‚   └── toolbox.py
β”œβ”€β”€ inference/            # Generic inference pipeline
β”‚   └── postprocessing.py
β”œβ”€β”€ utils/                # Utility functions
β”‚   β”œβ”€β”€ inference_engine.py
β”‚   └── video_utils.py
└── streamlit_ui.py       # Web interface

πŸ§ͺ Testing

Run the test suite:

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

# Run with coverage
pytest --cov=anpr tests/

# Run specific test
pytest tests/test_anpr.py::test_license_plate_reading

πŸ“Š Performance

Inference Performance

  • Hailo-8: ~30-50 FPS (640x640 input)
  • Demo Mode: ~100+ FPS (mock inference)
  • Memory Usage: ~200-500MB depending on model

ANPR Accuracy

  • License Plate Detection: 85-95% (depends on video quality)
  • Text Recognition: 90-98% (PaddleOCR PP-OCRv5)
  • Registry Matching: 95%+ (official Norwegian APIs)

πŸ”§ Configuration Reference

Environment Variables

Variable Required Description
PADDLEOCR_API_URL Yes PaddleOCR API endpoint URL (default: http://localhost:5000)
VEHICLE_API_KEY No Norwegian vehicle registry API key
VEHICLE_API_BASE_URL No Custom registry API endpoint
LOG_LEVEL No Logging level (INFO, DEBUG, WARNING)

Model Configuration

Edit config.json to customize inference parameters:

{
  "fast": {
    "score_threshold": 0.5,
    "nms_threshold": 0.4
  },
  "v5": {
    "score_threshold": 0.5,
    "nms_threshold": 0.4
  }
}

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Setup

# Clone and setup development environment
git clone https://github.com/OsloVision/anpr-standalone.git
cd anpr-standalone
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

# Run code formatting
black .
flake8 .

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Hailo for AI accelerator support
  • OpenAI for GPT-4o-mini vision capabilities
  • Norwegian Public Roads Administration for vehicle registry APIs
  • Streamlit for the excellent web framework

πŸ“ž Support

πŸ—Ί Roadmap

  • v1.1: ONNX Runtime support
  • v1.2: TensorFlow Lite backend
  • v1.3: REST API server mode
  • v1.4: Docker containers
  • v1.5: Cloud deployment guides
  • v2.0: Multi-country registry support

Built with ❀️ by OsloVision

About

Standalone Car Loan Detector

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published