-
Notifications
You must be signed in to change notification settings - Fork 55
Added Number plate detection project #48
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
Closed
iamdevdhanush
wants to merge
8
commits into
Grow-with-Open-Source:main
from
iamdevdhanush:number_plate_detection
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f94836
Added Number plate detection project
iamdevdhanush 39a6105
Update README.md
iamdevdhanush fe4e549
Update license plate detection to use webcam input
iamdevdhanush bb28267
Merge branch 'Grow-with-Open-Source:main' into number_plate_detection
iamdevdhanush d2d53ab
Delete Number-Plate-Detection/indian_license_plate.xml
iamdevdhanush 947f6b7
Delete Number-Plate-Detection/Trafic Camera.mp4
iamdevdhanush 94e5aa2
Update README.md
iamdevdhanush fe8b679
Update Numberplatedetection.py
iamdevdhanush 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,67 @@ | ||
| import cv2 | ||
| import os | ||
| import time | ||
|
|
||
| cascade_path = 'indian_license_plate.xml' | ||
| plate_cascade = cv2.CascadeClassifier(cascade_path) | ||
| if plate_cascade.empty(): | ||
| print(f"Error loading cascade from {cascade_path}") | ||
| exit() | ||
|
|
||
| os.makedirs('plates', exist_ok=True) | ||
| video_path = 'Trafic Camera.mp4' | ||
| cap = cv2.VideoCapture(video_path) | ||
| if not cap.isOpened(): | ||
| print(f"Error opening video file {video_path}") | ||
| exit() | ||
|
|
||
| plate_count = 0 | ||
| last_save_time = 0 | ||
| save_delay = 0.5 | ||
|
|
||
| while True: | ||
| ret, frame = cap.read() | ||
| if not ret: | ||
| print("End of video or cannot read frame.") | ||
| 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) | ||
| print(f"Saved plate_{plate_count}.jpg") | ||
| last_save_time = current_time | ||
|
|
||
| cv2.imshow("Number Plate Detection", frame) | ||
|
|
||
| if cv2.waitKey(1) & 0xFF == ord('q'): | ||
| print("Quit pressed, exiting.") | ||
| 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,88 @@ | ||
| # Number Plate Detection 🚘🔍 | ||
|
|
||
| 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. | ||
|
|
||
| ## 📸 Demo | ||
|
|
||
|  | ||
|
|
||
|
|
||
| ## 🧠 Features | ||
|
|
||
| - Real-time number plate detection using webcam | ||
| - Uses OpenCV's Haar Cascade Classifier | ||
| - Highlights detected number plates with rectangles | ||
| - Can be extended for OCR (Optical Character Recognition) | ||
|
|
||
| ## 🛠️ Technologies Used | ||
|
|
||
| - Python 3.x | ||
| - OpenCV | ||
| - Haar Cascade Classifier | ||
|
|
||
| ## 📁 Project Structure | ||
|
|
||
| Number-Plate-Detection/ | ||
|
|
||
| │ | ||
|
|
||
| ├── Numberplatedetection.py # Main script for plate detection | ||
|
|
||
| ├── haarcascade_russian_plate_number.xml # Haar Cascade model for number plates | ||
|
|
||
| └── README.md # Project documentation | ||
|
|
||
| ## 🚀 How to Run | ||
|
|
||
| ### 1. Clone the Repository | ||
|
|
||
| ```bash | ||
| git clone https://github.com/iamdevdhanush/Number-Plate-Detection.git | ||
| cd Number-Plate-Detection | ||
| ``` | ||
|
|
||
| 2. Install Requirements | ||
|
|
||
| ```bash | ||
| pip install opencv-python | ||
| ``` | ||
|
|
||
| 3. Run the Script | ||
|
|
||
| ```bash | ||
| python Numberplatedetection.py | ||
| ``` | ||
|
|
||
| 📦 Dependencies | ||
| ``` | ||
| opencv-python | ||
| ``` | ||
| You can install them using pip: | ||
|
|
||
| ``` | ||
| pip install -r requirements.txt | ||
| ``` | ||
|
|
||
| 📌 Notes | ||
|
|
||
| Make sure you have the correct Haar Cascade XML file (haarcascade_russian_plate_number.xml). | ||
|
|
||
| This project is a basic implementation and doesn't perform OCR. You can extend it using pytesseract for extracting plate text. | ||
|
|
||
| 🤖 Future Improvements | ||
|
|
||
| Add OCR to extract text from number plates | ||
|
|
||
| Improve accuracy with deep learning-based detection (YOLO, SSD) | ||
|
|
||
| Support detection in images and video files | ||
|
|
||
| 📄 License | ||
|
|
||
| This project is licensed under the MIT License. | ||
iamwatchdogs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 🙋♂️ Author | ||
|
|
||
| Dhanush | ||
|
|
||
| GitHub | ||
|
Binary file not shown.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have requested that you remove the required files (mp4 file and xml file) for this program to work properly. Here's a workaround that could work for your program:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @iamwatchdogs,
I’ve updated the implementation to remove any dependency on local mp4 or xml files by using OpenCV’s built-in Haar cascade and defaulting to webcam input.
I’ve also performed an interactive rebase and force-pushed the branch so the mp4 and xml files are completely removed from the commit history, and removed the license section from the README.
Please let me know if any further changes are required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @iamdevdhanush,
We have reviewed your changes. We want to remind you that reverting changes doesn't completely remove the traces of"input" files (such as mp4 or xml). These files can be recovered by reverting the "deleted" revert commits.
We want you to perform interactive rebasing for this branch to edit the initial commit (i.e.,
6f94836c) and delete the mp4 & xml file, and during the same interactive rebasing session, remove the reverting commit that you have made. After all these changes, force-push your reorganised commit history to the remote branch.We can proceed with these changes. Please feel free to ask any questions for clarification or help needed.
Tip
Here's a sample YouTube Tutorial for using interactive rebasing.