AI PROJECT CLASS X/XII

AI Project
AI PROJECT CLASS X/XII
October 6, 2024
AI Project
AI PROJECT CLASS X/XII
October 7, 2024
AI Project

Project 3:

AI-Based Object Detection and Counting System

Objective: Develop an AI system that can detect and count specific objects (e.g., cars, people, plants) from images or video footage.

Problem Statement
In many real-world applications, it is essential to monitor and analyze the presence of specific objects, such as vehicles, people, or equipment, within a given environment. Traditional methods of object detection often involve manual counting or rudimentary video surveillance, which can be time-consuming and prone to human error. This project aims to develop an AI-based object detection and counting system that uses computer vision and machine learning to detect, track, and count specific objects in real-time from video feeds. The solution will enhance the efficiency and accuracy of tasks such as traffic monitoring, event management, and inventory control, providing automated and reliable data collection.

Key Tools:

  • Use OpenCV for image processing.
  • Implement YOLO (You Only Look Once) or another object detection algorithm to recognize objects.
  • Train the model to recognize specific object classes based on a dataset.

Features:

  • Real-time object detection and counting from video streams (e.g., traffic monitoring, crowd counting).
  • Save the count data to a CSV or database, and generate reports.
  • Optionally, create a graphical interface to visualize object detection.

Python Code:

import cv2import torch

# Load the YOLO model (pretrained)

model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
# Initialize webcam

cap = cv2.VideoCapture(0)

# Object classes to track (example: person, car, etc.)

tracking_classes = ['person', 'car']
while True:
ret, frame = cap.read()
if not ret:
  break
# Make predictions

results = model(frame)

# Parse the predictions

objects_detected = []
for obj in results.pred[0]:
    if obj[5] in model.names:  # Only track objects within known classes
        obj_class = model.names[int(obj[5])]
        if obj_class in tracking_classes:
            x1, y1, x2, y2, conf, cls = obj
            objects_detected.append(obj_class)

            # Draw bounding box
            cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 2)
            cv2.putText(frame, f'{obj_class} {conf:.2f}', (int(x1), int(y1) - 10),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)

# Display the detected object count

for obj_class in set(objects_detected):
    print(f"{obj_class}: {objects_detected.count(obj_class)} detected")

# Show the frame

cv2.imshow('Object Detection', frame)

# Press 'q' to exit

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

ai cbse
ai cbse
This site is dedicated to provide contents, notes, questions bank,blogs,articles and other materials for AI students of CBSE.

Leave a Reply

Your email address will not be published. Required fields are marked *