! Number Plate recognition web page
- OpenCV: Used for opening the camera, capturing frames, converting images to grayscale, drawing rectangles, and displaying text on images.
- Haar Cascade Classifier: Specifically,
haarcascade_russian_plate_number.xml
for detecting number plates.
- Pytesseract: Used for extracting text from the detected number plates.
- Parameter Tuning:
custom_config = r'--oem 3 --psm 1'
- OCR Engine Mode (
--oem
):0
: Legacy engine only.1
: Neural nets LSTM engine only.2
: Legacy + LSTM engines.3
: Default, based on what is available.
- Page Segmentation Mode (
--psm
):0
: Orientation and script detection (OSD) only.1
: Automatic page segmentation with OSD.2
: Automatic page segmentation, but no OSD, or OCR.3
: Fully automatic page segmentation, but no OSD.4
: Assume a single column of text of variable sizes.5
: Assume a single uniform block of vertically aligned text.6
: Assume a single uniform block of text.7
: Treat the image as a single text line.8
: Treat the image as a single word.9
: Treat the image as a single word in a circle.10
: Treat the image as a single character.11
: Sparse text. Find as much text as possible in no particular order.12
: Sparse text with OSD.13
: Raw line. Treat the image as a single text line, bypassing hacks that are Tesseract-specific.
- Parameter Tuning:
- Regular Expressions (
re
): Used to filter out non-alphanumeric characters from the recognized text.
- Flask: Used for web application framework to render templates, jsonify responses, and handle requests.
- Key functions:
render_template
,jsonify
,Response
,request
.
- Key functions:
- CSV Library: Used to append detected number plates to a CSV file for record-keeping.
- Pandas: Used for loading and displaying data on the webpage after being converted to JSON format.
- Signal: Used to send a SIGINT signal to interrupt the current Python process.
- Time: Used for controlling the frame capture timing until a number plate is recognized.
-
Camera Initialization and Frame Capture:
- The camera opens and starts capturing frames.
- Each captured frame is converted to grayscale for processing.
import cv2 cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Further processing
-
Number Plate Detection:
- The grayscale frame is sent to the recognition engine using the Haar Cascade Classifier to detect number plates.
- If a number plate is detected, a rectangle is drawn around it, and a label is put with the recognized text.
- If no number plate is detected, no label is put.
plate_cascade = cv2.CascadeClassifier('haarcascade_russian_plate_number.xml') plates = plate_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=4) for (x, y, w, h) in plates: cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 220, 0), 1) # Further processing in source file
-
Displaying on screen:
Response(generate_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
-
Saving to CSV
-
Interrupt Handling
-
Timing Control:
- The
time
module is used to pause the frame capture until a number plate is detected. =======
- The
Computer Vision Implementation with PyTesseract and Haar Cascade This repository features a computer vision project using PyTesseract and Haar Cascade to detect number regions and recognize characters. Built with Flask, it provides a web interface for user interaction. Detected numbers are stored in a CSV file with timestamps.