mvp-anpr-system

Automatic Number Plate Recognition (ANPR) System

This project implements an Automatic Number Plate Recognition (ANPR) system using YOLO for object detection and Tesseract for Optical Character Recognition (OCR). The system processes video frames in real-time, detects number plates, and performs OCR to extract the text from the detected plates.

Colab Notebook

Features

Requirements

Installation

Usage

Run the main script to start the real-time ANPR system:

python main.py

The system will open the default cam and start processing video frames. Press q to exit the application.

Code Overview


def main_realtime(model_path="yolov5s.pt"):
    model = initialize_model(model_path)
    cap = cv2.VideoCapture(0)  # Open default webcam

    if not cap.isOpened():
        print("Error: Unable to access the camera.")
        return

    while True:
        ret, frame = cap.read()
        if not ret:
            print("Error: Unable to read frame from camera.")
            break

        rgb_frame = preprocess_frame(frame)
        detections = perform_detection(model, rgb_frame)
        frame_with_boxes = draw_bounding_boxes(frame, detections)

        for detection in detections:
            x0, y0, x1, y1, confidence, class_id = detection
            if confidence > 0.25:  # Ensure only confident detections are processed
                number_plate_text = perform_ocr_on_box(frame, (x0, y0, x1, y1))
                cv2.putText(frame_with_boxes, f"Plate: {number_plate_text}", (int(x0), int(y0) - 30),
                            cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)

        cv2.imshow('ANPR Realtime', frame_with_boxes)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main_realtime()

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Acknowledgments