File size: 5,515 Bytes
ff4dcb7
ba478c5
eafe0e0
 
 
 
49165e5
eafe0e0
ff4dcb7
7ee8714
ff4dcb7
 
eafe0e0
ff4dcb7
eafe0e0
ff4dcb7
eafe0e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
---
title: SafeLicensing
emoji: 🛡️
colorFrom: indigo
colorTo: blue
sdk: streamlit
sdk_version: 1.38.0
app_file: app.py
pinned: false
license: mit
---

# SafeLicensing

This project demonstrates a pipeline for detecting license plates in images using YOLOv8 and encrypting the detected regions with a Chaotic Logistic Map encryption algorithm. It provides a user-friendly interface built with Streamlit.

>[!TIP]
> You can directly test the application on the web using the following link: [![Open in Streamlit](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://share.streamlit.io/fahimfba/safelicensing/main/app.py)

## Features

- **License Plate Detection**: Uses the YOLOv8 model to detect license plates in uploaded images.
- **Chaotic Encryption**: Encrypts the detected license plate regions using a two-layer XOR-based chaotic logistic map algorithm.
- **Streamlit Web App**: A simple interface to upload images, detect license plates, encrypt them, and download the results.

## Installation

1. Clone the repository:
   ```bash
   git clone https://github.com/FahimFBA/SafeLicensing.git
   cd SafeLicensing
   ```

2. Install `ffmpeg` for video processing (Linux):
   ```bash
   sudo apt-get install ffmpeg
   ```

   or, for macOS:
   ```bash
   brew install ffmpeg
   ```

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

4. Download the YOLOv8 weights file (`best.pt`) and place it in the root directory of the project. You can train your own model or use a pre-trained one. This repository already have our model from [SEncrypt](https://github.com/IsratIJK/SEncrypt) located in [best.pt](./best.pt) file.

## Usage

1. Run the Streamlit app:
   ```bash
   streamlit run app.py
   ```

2. Open the app in your browser (typically at `http://localhost:8501`).

3. Follow the steps:
   - Upload an image or provide a URL.
   - Adjust the encryption key seed using the slider.
   - Click the "Detect & Encrypt" button to process the image.

4. Download the encrypted image directly from the app.

## Docker Usage

You can run this application using Docker. There are two options: CPU-only and GPU-enabled.

### CPU Version

1. Build the Docker image:
   ```bash
   docker build -t safelicensing .
   ```

2. Run the Docker container:
   ```bash
   docker run -d -p 8501:8501 --name safelicensing_container safelicensing
   ```

### GPU Version (for NVIDIA GPU users)

1. Ensure you have the NVIDIA Container Toolkit installed. If not, follow the [official installation guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html).

2. Build the GPU-enabled Docker image:
   ```bash
   docker build -f Dockerfile.gpu -t safelicensing-gpu .
   ```

3. Run the GPU-enabled Docker container:
   ```bash
   docker run -d -p 8501:8501 --gpus all --name safelicensing_gpu_container safelicensing-gpu
   ```

### Common Steps

4. Check if the container is running:
   ```bash
   docker ps
   ```
   You should see a container named `safelicensing_container` or `safelicensing_gpu_container` in the list.

5. View the container logs:
   ```bash
   docker logs safelicensing_container  # or safelicensing_gpu_container for GPU version
   ```
   This will show you the Streamlit startup logs and any errors if they occur.

6. Open the app in your browser by navigating to `http://localhost:8501`.

If you encounter any issues:
- Ensure that port 8501 is not being used by another application.
- Check the container logs for any error messages.
- If needed, you can stop and remove the container using:
  ```bash
  docker stop safelicensing_container  # or safelicensing_gpu_container
  docker rm safelicensing_container  # or safelicensing_gpu_container
  ```
  Then, try running the container again.

Note: The GPU version requires an NVIDIA GPU and proper drivers. If you don't have a compatible GPU, use the CPU version instead.

## Workflow

1. **License Plate Detection**:
   - The YOLOv8 model is used to detect license plates in the input image. The model has been taken from [SEncrypt](https://github.com/IsratIJK/SEncrypt).
   - Detected regions are highlighted with bounding boxes.

2. **Chaotic Logistic Map Encryption**:
   - A chaotic logistic map generates two XOR-based encryption keys.
   - Pixels in the license plate regions are shuffled and encrypted in two stages.
   - The encrypted region replaces the original plate in the image.

3. **Visualization and Download**:
   - The original, detected, and encrypted images are displayed in the app.
   - Encrypted images can be downloaded as PNG files.

## Files

- `app.py`: The main Streamlit app file.
- `requirements.txt`: Python dependencies for the project.
- `best.pt`: YOLOv8 weights file (not included, add your own).

## Key Parameters

- **Encryption Key Seed**: A slider in the app adjusts the seed value for the chaotic logistic map, affecting the encryption's randomness.

## Example Screenshots

### Original Image

![Original Image](./img/lpr-tesla-license-plate-recognition-1910x1000.jpg)

### Encrypted Image

![Encrypted Image](./img/encrypted_plate.png)

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

## Contact

For any queries, feel free to reach out:

- **Author**: Md. Fahim Bin Amin
- **GitHub**: [FahimFBA](https://github.com/FahimFBA)

- **Other Authors**: [Rafid Mehda](https://github.com/rafid29mehda), [Israt Jahan Khan](https://github.com/IsratIJK)