# License Plate Recognition System

A robust and efficient real-time license plate recognition system using YOLO for plate detection and CRNN for text recognition. The system is specifically designed for Russian license plates and provides high accuracy in both detection and character recognition.

## 🚀 Features

- Real-time license plate detection and recognition
- Support for both real-time webcam input and static image batch processing
- Support for Russian license plate format
- High-accuracy YOLO-based plate detection
- Advanced CRNN-based text recognition with CTC loss
- Real-time visualization with OpenCV
- Multi-stage pipeline with separate detection and recognition components
- Built-in data augmentation for robust training
- Support for both real-time webcam input and static image processing

## 🛠️ Technical Architecture

The system consists of two main components:

1. **License Plate Detection (YOLO)**
   - Uses YOLO (You Only Look Once) for real-time object detection
   - Trained specifically for license plate detection
   - Provides bounding box coordinates for detected plates

2. **Text Recognition (CRNN)**
   - Convolutional Recurrent Neural Network architecture
   - CNN backbone for feature extraction
   - Bidirectional LSTM for sequence modeling
   - CTC loss for end-to-end training
   - Supports the specific character set used in Russian license plates

## 📊 Performance

- CRNN Text Recognition Accuracy: ~97% on validation set
- Real-time processing capability on CPU
- Support for various lighting conditions and angles through data augmentation

## 🔧 Requirements

```
numpy==1.26.3
pillow==10.2.0
opencv-python==4.10.0.84
scikit-learn==1.5.2
scipy==1.13.1
matplotlib==3.9.2
tqdm
ultralytics
torch==2.0.1
torchvision==0.15.2
```

## 💻 Installation

1. Clone the repository:
```bash
git clone https://git.itqop.pw/itqop/number-plate.git
cd number-plate
```

2. Create and activate a virtual environment (optional but recommended):
```bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
```

3. Install the required packages:
```bash
pip install -r requirements.txt
```

## 🚗 Usage

### Real-time Recognition (Webcam)

To run the system with webcam input:

```bash
python main.py
```

The application will open a window showing the webcam feed with detected license plates and their recognized text. Press 'q' or 'ESC' to exit.

### Static Image Processing

To process a batch of images:

1. Place your images in the `img` folder
2. Open `static-test.ipynb`
3. Run the static test script


The script will:
- Process all images in the specified folder
- Display results with bounding boxes and recognized text
- Show results in a matplotlib window for each image

### Training the CRNN Model

The CRNN model can be trained using the provided Jupyter notebook:

1. Open `train_crnn.ipynb`
2. Configure the training parameters if needed
3. Run all cells to start training
4. The best models will be saved based on validation loss and accuracy

## 📁 Project Structure

```
├── img/                        # Directory to store images for static tests
├── models/                     # Directory to store YOLO and CRNN weights
├── config.py                   # Configuration for character mappings and model paths
├── license_plate_recognizer.py # Main class for license plate detection and recognition
├── main.py                     # Script for real-time license plate recognition
├── model.py                    # CRNN model definition
├── requirements.txt            # Project dependencies
├── static-test.ipynb           # Notebook for testing inference on static images
├── train_crnn.ipynb            # Notebook for training the CRNN model
└── README.md                   # Project documentation
```

## 🧬 Model Architecture

### CRNN Architecture
- **CNN Layers**: Multiple convolutional layers with max pooling and batch normalization
- **RNN Layers**: Bidirectional LSTM for sequence modeling
- **Dense Layers**: Final classification layers
- **Input Size**: 32x128 grayscale images
- **Output**: Character sequence predictions

## 📝 License Plate Format

The system is designed to recognize Russian license plates with the following character set:
- Letters: A, B, E, K, M, H, O, P, C, T, Y, X
- Numbers: 0-9
- Special characters: - (hyphen)

## ⚙️ Configuration

Key parameters can be modified in `config.py`:
- `ALPHABET`: Supported characters
- `NUM_CLASSES`: Number of character classes
- `YOLO_WEIGHTS_PATH`: Path to YOLO model weights
- `CRNN_WEIGHTS_PATH`: Path to CRNN model weights

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## 📄 License

This project is licensed under the MIT License. 

You are free to use, modify, and distribute this software as per the terms of the MIT License. For detailed terms, see the `LICENSE` file included in this repository.

