pat
Published © GPL3+

Real-Time Empty Space Detection & Counting with YOLOv8

Efficiently detect and count empty spaces in real time using YOLOv8 on Jetson Nano—optimized edge AI for smarter space management.

AdvancedFull instructions provided15 hours760
Real-Time Empty Space Detection & Counting with YOLOv8

Things used in this project

Hardware components

NVIDIA Jetson Nano Developer Kit
NVIDIA Jetson Nano Developer Kit
×1
Webcam, Logitech® HD Pro
Webcam, Logitech® HD Pro
×1
Flash Memory Card, MicroSD Card
Flash Memory Card, MicroSD Card
×1

Story

Read more

Code

Code

Python
import cv2
from ultralytics import YOLO

# Load the YOLOv8 model
model = YOLO(r'D:\My-Pretrained\empty_space.onnx')

cap = cv2.VideoCapture(0)

def count_available_spaces(results):
    available_count = 0
    for result in results:
        for label in result.boxes.cls:
            if model.names[int(label)] == "available_3":
                available_count += 1
    return available_count

# Loop through the video frames
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()

    if success:
        # Run YOLOv8 inference on the frame
        results = model(frame)

        # Count the available spaces
        available_count = count_available_spaces(results)

        # Visualize the results on the frame
        annotated_frame = results[0].plot()

        # Display the count of available spaces on the frame
        cv2.putText(annotated_frame, f"Available Spaces: {available_count}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)

        # Display the annotated frame
        cv2.imshow("YOLOv8 Inference", annotated_frame)

        # Break the loop if 'q' is pressed
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
    else:
        # Break the loop if the end of the video is reached
        break

# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

Credits

pat
13 projects • 4 followers
AI Convergence Engineering, Software Engineering, ML, deep learning, image processing, computer vision, circuit design, and Edge AI devices.
Contact

Comments

Please log in or sign up to comment.