Spaces:
Sleeping
Sleeping
v1
Browse files- .dockerignore +3 -0
- .gitignore +2 -0
- Dockerfile +19 -0
- requirements.txt +40 -0
- src/__init__.py +0 -0
- src/image_detection.py +36 -0
- src/main.py +16 -0
.dockerignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.venv
|
2 |
+
__pycache__
|
3 |
+
README.md
|
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.venv
|
2 |
+
__pycache__
|
Dockerfile
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.12
|
2 |
+
|
3 |
+
RUN apt-get update && \
|
4 |
+
apt-get install -y \
|
5 |
+
tesseract-ocr \
|
6 |
+
libtesseract-dev \
|
7 |
+
libgl1
|
8 |
+
|
9 |
+
|
10 |
+
WORKDIR /app
|
11 |
+
|
12 |
+
COPY requirements.txt .
|
13 |
+
RUN pip install -r requirements.txt
|
14 |
+
|
15 |
+
COPY src/ .
|
16 |
+
|
17 |
+
EXPOSE 8501
|
18 |
+
|
19 |
+
CMD ["streamlit", "run", "main.py"]
|
requirements.txt
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==5.5.0
|
2 |
+
attrs==25.3.0
|
3 |
+
blinker==1.9.0
|
4 |
+
cachetools==5.5.2
|
5 |
+
certifi==2025.1.31
|
6 |
+
charset-normalizer==3.4.1
|
7 |
+
click==8.1.8
|
8 |
+
gitdb==4.0.12
|
9 |
+
GitPython==3.1.44
|
10 |
+
idna==3.10
|
11 |
+
imutils==0.5.4
|
12 |
+
Jinja2==3.1.6
|
13 |
+
jsonschema==4.23.0
|
14 |
+
jsonschema-specifications==2024.10.1
|
15 |
+
MarkupSafe==3.0.2
|
16 |
+
narwhals==1.31.0
|
17 |
+
numpy==2.2.4
|
18 |
+
opencv-python==4.11.0.86
|
19 |
+
packaging==24.2
|
20 |
+
pandas==2.2.3
|
21 |
+
pillow==11.1.0
|
22 |
+
protobuf==5.29.3
|
23 |
+
pyarrow==19.0.1
|
24 |
+
pydeck==0.9.1
|
25 |
+
pytesseract==0.3.13
|
26 |
+
python-dateutil==2.9.0.post0
|
27 |
+
pytz==2025.1
|
28 |
+
referencing==0.36.2
|
29 |
+
requests==2.32.3
|
30 |
+
rpds-py==0.23.1
|
31 |
+
six==1.17.0
|
32 |
+
smmap==5.0.2
|
33 |
+
streamlit==1.43.2
|
34 |
+
tenacity==9.0.0
|
35 |
+
toml==0.10.2
|
36 |
+
tornado==6.4.2
|
37 |
+
typing_extensions==4.12.2
|
38 |
+
tzdata==2025.1
|
39 |
+
urllib3==2.3.0
|
40 |
+
watchdog==6.0.0
|
src/__init__.py
ADDED
File without changes
|
src/image_detection.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import cv2
|
3 |
+
import pytesseract
|
4 |
+
|
5 |
+
def extract_number_plate_text(image):
|
6 |
+
# Convert PIL image to OpenCV format
|
7 |
+
image = np.array(image)
|
8 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
9 |
+
|
10 |
+
# Apply preprocessing
|
11 |
+
filtered = cv2.bilateralFilter(gray, 11, 17, 17) # Noise reduction
|
12 |
+
edged = cv2.Canny(filtered, 30, 200) # Edge detection
|
13 |
+
|
14 |
+
# Find contours
|
15 |
+
contours, _ = cv2.findContours(edged, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
16 |
+
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10]
|
17 |
+
|
18 |
+
plate_text = "No plate detected"
|
19 |
+
|
20 |
+
# Loop over contours to find the number plate
|
21 |
+
for contour in contours:
|
22 |
+
perimeter = cv2.arcLength(contour, True)
|
23 |
+
approx = cv2.approxPolyDP(contour, 0.02 * perimeter, True)
|
24 |
+
|
25 |
+
if len(approx) == 4: # Possible number plate
|
26 |
+
x, y, w, h = cv2.boundingRect(approx)
|
27 |
+
plate_region = gray[y:y+h, x:x+w]
|
28 |
+
|
29 |
+
# Preprocessing for OCR
|
30 |
+
plate_region = cv2.threshold(plate_region, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
|
31 |
+
|
32 |
+
# Extract text using Tesseract
|
33 |
+
plate_text = pytesseract.image_to_string(plate_region, config="--psm 8").strip()
|
34 |
+
break
|
35 |
+
|
36 |
+
return plate_text
|
src/main.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from image_detection import extract_number_plate_text
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
st.title("License Plate Recognition App 🚗")
|
6 |
+
|
7 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
8 |
+
|
9 |
+
|
10 |
+
if uploaded_file:
|
11 |
+
image = Image.open(uploaded_file)
|
12 |
+
st.image(image, caption="Uploaded image", use_container_width=True)
|
13 |
+
|
14 |
+
plate_text = extract_number_plate_text(image)
|
15 |
+
st.subheader("Extracted Number Plate: ")
|
16 |
+
st.write(plate_text)
|