-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1066 from ashis2004/99999
railway_person_detection added
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
yolov8m.pt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ultralytics | ||
opencv-python |