-
Notifications
You must be signed in to change notification settings - Fork 55
Add number plate detection using OpenCV (clean submission) #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iamwatchdogs
merged 3 commits into
Grow-with-Open-Source:main
from
iamdevdhanush:number_plate_detection
Dec 28, 2025
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import cv2 | ||
| import os | ||
| import time | ||
|
|
||
| cascade_path = cv2.data.haarcascades + "haarcascade_russian_plate_number.xml" | ||
| plate_cascade = cv2.CascadeClassifier(cascade_path) | ||
|
|
||
| if plate_cascade.empty(): | ||
| raise IOError("Error loading Haar cascade") | ||
|
|
||
| # Output directory | ||
| os.makedirs("plates", exist_ok=True) | ||
|
|
||
| cap = cv2.VideoCapture(0) | ||
| if not cap.isOpened(): | ||
| raise IOError("Cannot open webcam") | ||
|
|
||
| plate_count = 0 | ||
| last_save_time = 0 | ||
| save_delay = 0.5 | ||
|
|
||
| while True: | ||
| ret, frame = cap.read() | ||
| if not ret: | ||
| break | ||
|
|
||
| frame = cv2.resize(frame, (960, 540)) | ||
| gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | ||
| gray = cv2.equalizeHist(gray) | ||
| gray = cv2.bilateralFilter(gray, 11, 17, 17) | ||
|
|
||
| roi = gray[270:540, :] | ||
| plates = plate_cascade.detectMultiScale( | ||
| roi, | ||
| scaleFactor=1.05, | ||
| minNeighbors=7, | ||
| minSize=(60, 20) | ||
| ) | ||
|
|
||
| current_time = time.time() | ||
|
|
||
| for (x, y, w, h) in plates: | ||
| y += 270 | ||
| aspect_ratio = w / h | ||
|
|
||
| if 2 < aspect_ratio < 5: | ||
| cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) | ||
|
|
||
| if current_time - last_save_time > save_delay: | ||
| plate_count += 1 | ||
| plate_img = frame[y:y+h, x:x+w] | ||
| cv2.imwrite(f"plates/plate_{plate_count}.jpg", plate_img) | ||
| last_save_time = current_time | ||
|
|
||
| cv2.imshow("Number Plate Detection", frame) | ||
|
|
||
| if cv2.waitKey(1) & 0xFF == ord("q"): | ||
| break | ||
|
|
||
| cap.release() | ||
| cv2.destroyAllWindows() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Number Plate Detection 🚘🔍 | ||
|
|
||
| This project is a simple **Number Plate Detection** system built using **Python** and **OpenCV**. | ||
| It uses classical image processing techniques and OpenCV’s **built-in Haar Cascade classifier** to detect vehicle number plates in real time using a webcam. | ||
|
|
||
| --- | ||
|
|
||
| ## 📸 Demo | ||
|
|
||
|  | ||
|
|
||
| --- | ||
|
|
||
| ## 🧠 Features | ||
|
|
||
| - Real-time number plate detection using webcam | ||
| - Uses OpenCV’s built-in Haar Cascade classifier | ||
| - Draws bounding boxes around detected number plates | ||
| - Lightweight and beginner-friendly | ||
| - Can be extended for OCR (text extraction) | ||
|
|
||
| --- | ||
|
|
||
| ## 🛠️ Technologies Used | ||
|
|
||
| - Python 3.x | ||
| - OpenCV | ||
|
|
||
| --- | ||
|
|
||
| ## 📁 Project Structure | ||
|
|
||
| ```text | ||
| Number-Plate-Detection/ | ||
| │ | ||
| ├── Numberplatedetection.py # Main script | ||
| └── README.md # Project documentation | ||
iamdevdhanush marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.