behavioranalysis_yolov8
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 1 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.6%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: farhanaugustine
- License: gpl-3.0
- Language: Python
- Default Branch: main
- Size: 37.1 KB
Statistics
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 1
Metadata Files
README.md
YoloV8_Single Animal Behavior Analysis with Open Field Example
Youtube Video Tutorial:
https://youtu.be/DydI37F5nVM
Object Detection and Tracking with YOLO and OpenCV
This script uses the YOLO (You Only Look Once) model from the Ultralytics library and OpenCV to perform object detection and tracking on a video. The detected objects are then analyzed based on their position in relation to predefined Regions of Interest (ROIs).
Dependencies
- Ultralytics YOLO
- OpenCV
- NumPy
- csv
How it works
Load the YOLO model: The YOLO model is loaded from the specified path. This model will be used to make predictions on the video frames.
Load the video: The video is loaded from the specified path using
cv2.VideoCapture(). This function returns aVideoCaptureobject which is used to read the video frames.Initialize frame counter: A frame counter is initialized to keep track of the current frame number.
Create a VideoWriter object: Two
VideoWriterobjects are created usingcv2.VideoWriter(). These objects are used to save the mask video and the video with ROIs and counts drawn on top.Define multiple ROIs: Multiple ROIs are defined as dictionaries. Each ROI has a top left and bottom right coordinate, as well as counters for entries and exits, a flag for whether the previous position was inside the ROI, frame counters for entries and exits, a counter for total frames, a counter for total distance, and a variable for the previous position.
Create a CSV file and write the header: A CSV file is created to store the frame number and the center coordinates of the detected objects.
Read frames: The script enters a loop where it reads frames from the video one by one.
Object detection: The YOLO model is used to make predictions on the current frame. If any objects are detected, their masks are processed and their centers are calculated.
ROI analysis: For each detected object, the script checks if its center is inside any of the ROIs. If the object has entered or exited an ROI, the corresponding counters are updated. The total distance traveled by the object inside the ROI is also calculated.
Draw on frame: The ROIs and the centers of the detected objects are drawn on the frame. The entry and exit counts for each ROI are also drawn on the frame.
Save frame and mask to video: The frame with the drawn ROIs and counts, as well as the mask of the detected objects, are saved to video files using the
VideoWriterobjects.Increment frame counter: The frame counter is incremented.
Write CSV data to file: After all frames have been processed, the CSV data is written to the file.
Release resources: The
VideoCaptureandVideoWriterobjects are released and any openCV windows are destroyed.Print ROI counts: The entry and exit counts, total frames spent, and average velocity for each ROI are printed.
Write ROI counts to CSV file: The entry and exit counts, total frames spent, and average velocity for each ROI are written to the CSV file.
Usage
To run the script, simply execute it with Python:
```bash python yolov8_seg.py
Owner
- Name: Farhan
- Login: farhanaugustine
- Kind: user
- Location: Maryland
- Company: University of Maryland Baltimore County
- Website: https://www.farhanaugustine.com/
- Repositories: 1
- Profile: https://github.com/farhanaugustine
Citation (CITATION.cff)
authors:
- family-names: Augustine
given-names: Farhan
orcid: "https://orcid.org/0000-0002-8348-6039"
cff-version: 1.0.0
date-released: "05-23-2024"
identifiers:
- description: "This is the collection of archived snapshots of the latest release versions of BehaviorAnalysis_YOLOv8."
type: doi
value: https://zenodo.org/doi/10.5281/zenodo.11264288
keywords:
- BehaviorAnalysis
- AnimalBehaviorResearch
- Open-FieldTestAnalysis
- T-MazeAnalysis
- ElevatedPlusMaze
- AnimalTracking
license:
- GPL-3.0
message: "If you use this software, please cite it using these metadata."
repository-code: "https://github.com/farhanaugustine/BehaviorAnalysis_YOLOv8/tree/main"
title: "BehaviorAnalysis_YOLOv8"
version: 1.0.0
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1