Skip to content

Repository files navigation

Project Title: Object Detection and Data Storage

Overview

This project implements object detection using a YOLO model and stores the detected objects in both JSON and Excel formats. It also allows converting between these formats.

Object Detection with YOLOv8 and Results Export to JSON and Excel This project demonstrates how to perform object detection using the YOLOv8 model and export the results to both JSON and Excel formats. The detection includes the identification of objects and their respective bounding boxes, along with the detection of related sub-objects. The results are saved for each video frame.

Features Object Detection: Uses YOLOv8 model to detect objects in real-time video feed (can also process video files). Sub-object Detection: Identifies sub-objects within detected objects and associates them based on predefined relationships. Result Export: Save object detection results in JSON format. Save object detection results in Excel format. Requirements Python 3.6 or later OpenCV (opencv-python) PyTorch (torch) YOLOv8 Model from Ultralytics (ultralytics) Pandas (pandas) Install Dependencies To install the required dependencies, run the following:

pip install opencv-python torch ultralytics pandas Setup Project Structure project/ | ├──env │ ├──images | ├──src | ├──yolo-test.py #To Check The Yolo Funtionality on images | | ├──sub-object-detection | ├──main.py # Python script for processing and detection ├──Yolo-Webcam | ├──CheckCams.py #to check the webcams ├── Yolo-Weights/ │ └── yolov8l.pt # Pre-trained YOLOv8 model weights │ │────detection_results.xlsx # Excel file where results will be saved │────detection_results.json # JSON file where results will be saved └── README.md # This file Pre-trained YOLOv8 Model You need to download the pre-trained YOLOv8 model from Ultralytics or use the yolov8l.pt model weights. Place the downloaded model weights in the Yolo-Weights/ folder.

main.py Explanation Object Detection:

The script loads the YOLOv8 model from the Yolo-Weights/yolov8l.pt file. It continuously processes each frame from the video (or webcam if 0 is passed as the argument). For each object detected, it stores the object name, ID, bounding box coordinates, and any detected sub-objects. Sub-object Detection:

Based on predefined relationships (e.g., a "person" can have a "backpack" and "helmet"), the script checks if any sub-object is detected within the bounding box of the main object. Sub-objects are detected and added to the result. Result Export:

The script saves the detection results to two formats: JSON: The results are saved to detection_results.json. Excel: The results are saved to detection_results.xlsx using the pandas library. Display:

The video feed is shown with detected objects and their bounding boxes. Object labels and IDs are displayed on the frame. Press q to stop the video feed and save the results. Running the Script Clone the repository or download the project files to your local machine. Make sure to download the YOLOv8 model weights and place them in the Yolo-Weights/ folder. Run the following command to start the object detection process: python main.py The video feed will display with object detections, and when you press q, the detection results will be saved in both detection_results.json and detection_results.xlsx within the results/ folder. Example Output JSON Output (detection_results.json): [ { "frame_1": [ { "object": "person", "id": 1, "bbox": [100, 150, 250, 350], "subobject": [ { "object": "backpack", "id": 1, "bbox": [110, 160, 150, 200] }, { "object": "helmet", "id": 2, "bbox": [120, 170, 160, 210] } ] } ] }, .. ] Excel Output (detection_results.xlsx): Columns: frame_id, object, object_id, bbox, subobjects Notes If you want to process a video file instead of the webcam feed, replace cap = cv2.VideoCapture(0) with cap = cv2.VideoCapture('video_file_path') where video_file_path is the path to your video file. The script assumes that you have a webcam or video source available. If not, ensure that the path to the video file is correct. The sub-object detection is based on the predefined object_subobject_map dictionary. You can modify this mapping to match the specific objects and sub-objects you are working with.

Download Yolo before use. modify the yolo file location as in you file structure.

use "python -m venv env" command to initialize python environment to activate it use the command ".\env\Scripts\activate" it may vary depending upon the Os and the Terminal

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages