Skip to content

Commit

Permalink
Merge pull request #1066 from ashis2004/99999
Browse files Browse the repository at this point in the history
railway_person_detection added
  • Loading branch information
invigorzz313 authored Aug 10, 2024
2 parents 8275047 + 63e77de commit 53fe6c6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions railway_person_detection/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yolov8m.pt
41 changes: 41 additions & 0 deletions railway_person_detection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Railway Person Detection using YOLOv8

This project aims to detect people in railway environments using YOLOv8, a state-of-the-art object detection model. The system can be deployed for real-time monitoring of railway stations, platforms, or tracks to ensure safety and security.

## Requirements

- Python 3.x
- OpenCV
- PyTorch
- Ultralytics YOLO library
- Pre-trained YOLOv8 model weights (`yolov8m.pt`)
- GPU (optional, for faster inference)

## Installation

1. Clone this repository:
```bash
git clone https://github.com/TAHIR0110/ThereForYou.git
cd THEREFORYOU
cd railway_person_detection
```

2. Install dependencies:
```bash
pip install -r requirements.txt
```


## Usage

Run the `railway_person_detection.py` script to start detecting people in railway environments. You can specify various command-line arguments to customize the detection process:

- `-s, --source`: Specify the video source (default is webcam, provide the path to a video file for offline detection).
- `-x`: X-coordinate of the bounding box.
- `-y`: Y-coordinate of the bounding box.
- `--height`: Height of the bounding box.
- `--width`: Width of the bounding box.

Example usage:
```bash
python railway_person_detection.py --source 0 -x 100 -y 100 --height 200 --width 200
46 changes: 46 additions & 0 deletions railway_person_detection/railway_person_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from ultralytics import YOLO
import cv2
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-s","--source",default=0)
parser.add_argument("-x", default=0)
parser.add_argument("-y", default=0)
parser.add_argument("--height",default=0)
parser.add_argument("--width",default=0)


args = parser.parse_args()


cap = cv2.VideoCapture(args.source)

model= YOLO("yolov8m.pt")



while (cap.isOpened()):



suc,frame = cap.read()
if(args.x == 0 and args.y == 0 and args.height == 0 and args.width == 0):
print("User did not mentioned the values for the bounding box, by default, analyzing the whole image")
else:

frame = frame[args.y:args.y + args.height, args.x:args.x+args.width]


if not suc:
print("video sequence ended.")
break

result = model.predict(source=frame,classes=[0])

if result[0].boxes.xyxy is not None:
print("alert Person Detected in the Frame.")

else:
print("clear for now.")


2 changes: 2 additions & 0 deletions railway_person_detection/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ultralytics
opencv-python

0 comments on commit 53fe6c6

Please sign in to comment.