dwkurnie
commited on
Commit
·
7261123
1
Parent(s):
92ce739
app.py
CHANGED
@@ -3,7 +3,7 @@ import cv2
|
|
3 |
from ultralytics import YOLO
|
4 |
|
5 |
# Load YOLO model
|
6 |
-
model = YOLO(
|
7 |
|
8 |
# Function to perform object detection on an image
|
9 |
def show_preds_image(image_path):
|
@@ -17,30 +17,14 @@ def show_preds_image(image_path):
|
|
17 |
(int(det[2]), int(det[3])),
|
18 |
color=(0, 0, 255),
|
19 |
thickness=2,
|
20 |
-
lineType=cv2.LINE_AA
|
21 |
)
|
22 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
23 |
|
24 |
-
|
25 |
-
# Define inputs and outputs for image interface
|
26 |
-
inputs_image = [
|
27 |
-
gr.inputs.Image(type="filepath", label="Input Image"),
|
28 |
-
]
|
29 |
-
outputs_image = [
|
30 |
-
gr.outputs.Image(type="numpy", label="Output Image"),
|
31 |
-
]
|
32 |
-
interface_image = gr.Interface(
|
33 |
-
fn=show_preds_image,
|
34 |
-
inputs=inputs_image,
|
35 |
-
outputs=outputs_image,
|
36 |
-
title="Garbage Detector (Image Input)",
|
37 |
-
)
|
38 |
-
|
39 |
-
|
40 |
# Function to perform object detection on a video stream
|
41 |
def show_preds_video(video_stream):
|
42 |
cap = cv2.VideoCapture(video_stream.name)
|
43 |
-
while
|
44 |
ret, frame = cap.read()
|
45 |
if ret:
|
46 |
frame_copy = frame.copy()
|
@@ -53,26 +37,32 @@ def show_preds_video(video_stream):
|
|
53 |
(int(det[2]), int(det[3])),
|
54 |
color=(0, 0, 255),
|
55 |
thickness=2,
|
56 |
-
lineType=cv2.LINE_AA
|
57 |
)
|
58 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
# Define inputs and outputs for video interface
|
62 |
-
inputs_video = [
|
63 |
-
gr.inputs.Video(type="webcam", label="Input Webcam"),
|
64 |
-
]
|
65 |
-
outputs_video = [
|
66 |
-
gr.outputs.Image(type="numpy", label="Output Image"),
|
67 |
-
]
|
68 |
interface_video = gr.Interface(
|
69 |
fn=show_preds_video,
|
70 |
-
inputs=
|
71 |
-
outputs=
|
72 |
-
title="
|
73 |
)
|
74 |
|
75 |
# Launch tabbed interface for both image and video inference
|
76 |
-
gr.
|
77 |
-
[interface_image, interface_video],
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
).launch()
|
|
|
3 |
from ultralytics import YOLO
|
4 |
|
5 |
# Load YOLO model
|
6 |
+
model = YOLO('best.pt')
|
7 |
|
8 |
# Function to perform object detection on an image
|
9 |
def show_preds_image(image_path):
|
|
|
17 |
(int(det[2]), int(det[3])),
|
18 |
color=(0, 0, 255),
|
19 |
thickness=2,
|
20 |
+
lineType=cv2.LINE_AA
|
21 |
)
|
22 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# Function to perform object detection on a video stream
|
25 |
def show_preds_video(video_stream):
|
26 |
cap = cv2.VideoCapture(video_stream.name)
|
27 |
+
while(cap.isOpened()):
|
28 |
ret, frame = cap.read()
|
29 |
if ret:
|
30 |
frame_copy = frame.copy()
|
|
|
37 |
(int(det[2]), int(det[3])),
|
38 |
color=(0, 0, 255),
|
39 |
thickness=2,
|
40 |
+
lineType=cv2.LINE_AA
|
41 |
)
|
42 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
43 |
|
44 |
+
# Define interfaces for image and video inference
|
45 |
+
interface_image = gr.Interface(
|
46 |
+
fn=show_preds_image,
|
47 |
+
inputs=gr.inputs.Image(type="file", label="Upload Image"),
|
48 |
+
outputs=gr.outputs.Image(type="numpy", label="Output Image"),
|
49 |
+
title="Pothole Detector (Image Input)",
|
50 |
+
)
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
interface_video = gr.Interface(
|
53 |
fn=show_preds_video,
|
54 |
+
inputs=gr.inputs.Video(type="webcam", label="Webcam Input"),
|
55 |
+
outputs=gr.outputs.Image(type="numpy", label="Output Image"),
|
56 |
+
title="Pothole Detector (Webcam Input)",
|
57 |
)
|
58 |
|
59 |
# Launch tabbed interface for both image and video inference
|
60 |
+
gr.Interface(
|
61 |
+
[interface_image, interface_video],
|
62 |
+
title="Pothole Detector",
|
63 |
+
description="Detect potholes using YOLOv8 on images and webcam streams.",
|
64 |
+
examples=[
|
65 |
+
["path/to/image.jpg"],
|
66 |
+
["path/to/video.mp4"]
|
67 |
+
]
|
68 |
).launch()
|