The Vehicle Parking Automation project is designed to streamline the parking process using Machine Learning (ML) techniques, particularly focusing on image recognition to identify car license plates. The system aims to automate the allocation of parking spots by detecting car numbers through captured images.
image_detection.ipynb
: Jupyter Notebook for image detection and OCR.detection.py
: Script for detecting license plates.detect.py
: Script for performing OCR and displaying results.mainCar.py
: Main script for managing the overall parking system.mes.py
: Supporting script for handling miscellaneous tasks.images/
: Directory containing sample images for testing.data.csv
: CSV file for logging detected license plates and their accuracy.
To efficiently allocate parking spots in a parking facility using image recognition technology.
- Detects vehicle license plates from images using OpenCV and EasyOCR.
- Automatically extracts vehicle numbers and displays them on the image.
- Assigns parking slots based on the detected vehicle number (simulated).
- Maintains a log of detected license plates and timestamps in a CSV file.
git clone https://github.com/ananas304/your-repo.git
python -m venv env
- On Windows:
.\env\Scripts\activate
- On macOS/Linux:
source env/bin/activate
pip install -r requirements.txt
easyocr
opencv-python
imutils
matplotlib
pandas
The initial step involves loading and preprocessing the image.
import cv2
from matplotlib import pyplot as plt
#Load image
image = cv2.imread('images/4.jpg')
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
#Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
plt.imshow(cv2.cvtColor(gray, cv2.COLOR_BGR2RGB))
Apply Gaussian blur and Canny edge detection to preprocess the image for contour detection.
blur = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(blur, 10, 200)
plt.imshow(cv2.cvtColor(edged, cv2.COLOR_BGR2RGB))
Find contours and identify the license plate contour.
contours, _ = cv2.findContours(edged, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:5]
n_plate_cnt = None
for c in contours:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
if len(approx) == 4:
n_plate_cnt = approx
break
if n_plate_cnt is None:
print("No contour detected")
Perform OCR on the detected license plate using EasyOCR.
from easyocr import Reader
reader = Reader(['en'])
detection = reader.readtext(license_plate)
if len(detection) == 0:
text = "Unable to detect"
else:
text = detection[0][1]
accu = f"{detection[0][2] * 100:.2f}%"
final_text = f"{text} {accu}"
Display the processed images and save the detected text to a CSV file.
if len(detection) == 0:
cv2.putText(image, "Unable to detect", (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 3)
else:
cv2.drawContours(image, [n_plate_cnt], -1, (0, 255, 0), 3)
cv2.putText(image, final_text, (x, y - 20), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 0), 3)
#Save results
raw_data = {'date': [time.asctime(time.localtime(time.time()))], 'v_number': [text]}
df = pd.DataFrame(raw_data, columns=['date', 'v_number'])
df.to_csv('data.csv', mode='a', index=False, header=False)
Define a function to process multiple images and run the detection.
def imageDetection(img_path):
# Include all the previous steps here
pass
for i in range(1, 16):
imageDetection(f'images/{i}.jpg')
- Ensure that the images in the images/ folder are named 1.jpg, 2.jpg, etc.
- Adjust the parameters in Gaussian blur and Canny edge detector as needed based on your images.
- EasyOCR: For Optical Character Recognition.
- OpenCV: For image processing.