Skip to content

Commit 6f94836

Browse files
committed
Added Number plate detection project
1 parent 00a6c93 commit 6f94836

File tree

4 files changed

+929
-0
lines changed

4 files changed

+929
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import cv2
2+
import os
3+
import time
4+
5+
cascade_path = 'indian_license_plate.xml'
6+
plate_cascade = cv2.CascadeClassifier(cascade_path)
7+
if plate_cascade.empty():
8+
print(f"Error loading cascade from {cascade_path}")
9+
exit()
10+
11+
os.makedirs('plates', exist_ok=True)
12+
video_path = 'Trafic Camera.mp4'
13+
cap = cv2.VideoCapture(video_path)
14+
if not cap.isOpened():
15+
print(f"Error opening video file {video_path}")
16+
exit()
17+
18+
plate_count = 0
19+
last_save_time = 0
20+
save_delay = 0.5
21+
22+
while True:
23+
ret, frame = cap.read()
24+
if not ret:
25+
print("End of video or cannot read frame.")
26+
break
27+
28+
frame = cv2.resize(frame, (960, 540))
29+
30+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
31+
32+
gray = cv2.equalizeHist(gray)
33+
34+
gray = cv2.bilateralFilter(gray, 11, 17, 17)
35+
36+
roi = gray[270:540, :]
37+
38+
plates = plate_cascade.detectMultiScale(
39+
roi,
40+
scaleFactor=1.05,
41+
minNeighbors=7,
42+
minSize=(60, 20)
43+
)
44+
45+
current_time = time.time()
46+
47+
for (x, y, w, h) in plates:
48+
y += 270
49+
50+
aspect_ratio = w / h
51+
if 2 < aspect_ratio < 5:
52+
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
53+
54+
if current_time - last_save_time > save_delay:
55+
plate_count += 1
56+
plate_img = frame[y:y+h, x:x+w]
57+
cv2.imwrite(f"plates/plate_{plate_count}.jpg", plate_img)
58+
print(f"Saved plate_{plate_count}.jpg")
59+
last_save_time = current_time
60+
61+
cv2.imshow("Number Plate Detection", frame)
62+
63+
if cv2.waitKey(1) & 0xFF == ord('q'):
64+
print("Quit pressed, exiting.")
65+
break
66+
cap.release()
67+
cv2.destroyAllWindows()

Number-Plate-Detection/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Number Plate Detection 🚘🔍
2+
3+
This project is a simple Number Plate Detection system built using **OpenCV** and **Python**. It uses image processing techniques and a pre-trained Haar Cascade classifier to detect number plates in real-time from video streams or static images.
4+
5+
## 📸 Demo
6+
7+
![Screenshot 2025-05-21 160620](https://github.com/user-attachments/assets/fd6d233e-a948-4015-aab3-50ec09ac9f75)
8+
9+
10+
## 🧠 Features
11+
12+
- Real-time number plate detection using webcam
13+
- Uses OpenCV's Haar Cascade Classifier
14+
- Highlights detected number plates with rectangles
15+
- Can be extended for OCR (Optical Character Recognition)
16+
17+
## 🛠️ Technologies Used
18+
19+
- Python 3.x
20+
- OpenCV
21+
- Haar Cascade Classifier
22+
23+
## 📁 Project Structure
24+
25+
Number-Plate-Detection/
26+
27+
28+
29+
├── Numberplatedetection.py # Main script for plate detection
30+
31+
├── haarcascade_russian_plate_number.xml # Haar Cascade model for number plates
32+
33+
└── README.md # Project documentation
34+
35+
## 🚀 How to Run
36+
37+
### 1. Clone the Repository
38+
39+
```bash
40+
git clone https://github.com/iamdevdhanush/Number-Plate-Detection.git
41+
cd Number-Plate-Detection
42+
```
43+
44+
2. Install Requirements
45+
46+
```bash
47+
pip install opencv-python
48+
```
49+
50+
3. Run the Script
51+
52+
```bash
53+
python Numberplatedetection.py
54+
```
55+
56+
📦 Dependencies
57+
```
58+
opencv-python
59+
```
60+
You can install them using pip:
61+
62+
```
63+
pip install -r requirements.txt
64+
```
65+
66+
📌 Notes
67+
68+
Make sure you have the correct Haar Cascade XML file (haarcascade_russian_plate_number.xml).
69+
70+
This project is a basic implementation and doesn't perform OCR. You can extend it using pytesseract for extracting plate text.
71+
72+
🤖 Future Improvements
73+
74+
Add OCR to extract text from number plates
75+
76+
Improve accuracy with deep learning-based detection (YOLO, SSD)
77+
78+
Support detection in images and video files
79+
80+
📄 License
81+
82+
This project is licensed under the MIT License.
83+
84+
🙋‍♂️ Author
85+
86+
Dhanush
87+
88+
GitHub
22.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)