From 0d38532e422a85b1140e490d8dc76d92b6712d96 Mon Sep 17 00:00:00 2001 From: Dhanush D Prabhu <=itsdevdhanush> Date: Sat, 27 Dec 2025 15:15:52 +0530 Subject: [PATCH 1/3] Add number plate detection using OpenCV --- .../Numberplatedetection.py | 61 +++++++++++++++++++ Number-Plate-Detection/README.md | 37 +++++++++++ 2 files changed, 98 insertions(+) create mode 100644 Number-Plate-Detection/Numberplatedetection.py create mode 100644 Number-Plate-Detection/README.md diff --git a/Number-Plate-Detection/Numberplatedetection.py b/Number-Plate-Detection/Numberplatedetection.py new file mode 100644 index 0000000..13d6845 --- /dev/null +++ b/Number-Plate-Detection/Numberplatedetection.py @@ -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() diff --git a/Number-Plate-Detection/README.md b/Number-Plate-Detection/README.md new file mode 100644 index 0000000..0e8441a --- /dev/null +++ b/Number-Plate-Detection/README.md @@ -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 + +![Demo Screenshot](https://github.com/user-attachments/assets/fd6d233e-a948-4015-aab3-50ec09ac9f75) + +--- + +## 🧠 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 From 3ad12ae3c1e75c632bd9ac779989e49f10f21581 Mon Sep 17 00:00:00 2001 From: Dhanush D Prabhu Date: Sun, 28 Dec 2025 10:44:42 +0530 Subject: [PATCH 2/3] Update project structure section in README.md --- Number-Plate-Detection/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Number-Plate-Detection/README.md b/Number-Plate-Detection/README.md index 0e8441a..1f57cdd 100644 --- a/Number-Plate-Detection/README.md +++ b/Number-Plate-Detection/README.md @@ -28,10 +28,11 @@ It uses classical image processing techniques and OpenCV’s **built-in Haar Cas --- + ## πŸ“ Project Structure -```text Number-Plate-Detection/ β”‚ β”œβ”€β”€ Numberplatedetection.py # Main script └── README.md # Project documentation + From 9e37441ca6942f8a19ee0684ffb53f46da3083cd Mon Sep 17 00:00:00 2001 From: Dhanush D Prabhu Date: Sun, 28 Dec 2025 11:22:22 +0530 Subject: [PATCH 3/3] Update Number-Plate-Detection/README.md Co-authored-by: Shamith Nakka --- Number-Plate-Detection/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Number-Plate-Detection/README.md b/Number-Plate-Detection/README.md index 1f57cdd..8b91d1b 100644 --- a/Number-Plate-Detection/README.md +++ b/Number-Plate-Detection/README.md @@ -31,8 +31,10 @@ It uses classical image processing techniques and OpenCV’s **built-in Haar Cas ## πŸ“ Project Structure +``` Number-Plate-Detection/ β”‚ β”œβ”€β”€ Numberplatedetection.py # Main script -└── README.md # Project documentation +└── README.md # Project documentation +```