import cv2
import argparse
from ultralytics import YOLO
import supervision as sv
import numpy as np
from roboflow import Roboflow
ZONE_POLYGON = np.array([
[0, 0],
[0.5, 0],
[0.5, 1],
[0, 1]
])
def parse_arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="YOLOv8 live")
parser.add_argument(
"--webcam-resolution",
default=[1280, 720],
nargs=2,
type=int
)
args = parser.parse_args()
return args
def main():
rf = Roboflow(api_key="0BhfetHn2hWbSyP38mZs")
project = rf.workspace("buttpah").project("butt-pah")
version = project.version(3)
dataset = version.download("yolov8")
model = rf.
args = parse_arguments()
frame_width, frame_height = args.webcam_resolution
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, frame_width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_height)
box_annotator = sv.BoxAnnotator(
thickness=2,
text_thickness=2,
text_scale=1
)
zone_polygon = (ZONE_POLYGON * np.array(args.webcam_resolution)).astype(int)
zone = sv.PolygonZone(polygon=zone_polygon, frame_resolution_wh=args.webcam_resolution)
zone_annotator = sv.PolygonZoneAnnotator(
zone=zone,
color=sv.Color.red(),
thickness=2,
text_thickness=4,
text_scale=2
)
while True:
ret, frame = cap.read()
result = model(frame, agnostic_nms=True)[0]
detections = sv.Detections.from_yolov8(result)
labels = [
f"{model.model.names[class_id]} {confidence:0.2f}"
for _, confidence, class_id, _
in detections
]
frame = box_annotator.annotate(
scene=frame,
detections=detections,
labels=labels
)
zone.trigger(detections=detections)
frame = zone_annotator.annotate(scene=frame)
cv2.imshow("yolov8", frame)
if cv2.waitKey(30) == 27:
break
if __name__ == "__main__":
main()
this is the code for my project , im having trouble to use my custom data base which called " Butt Pah" .
this code was able to run a default model such as “yolov8” which is a part of the YOLO library.
but i dont figure out how to adjust the code to run on my custom database.
-
it seems that this code would successfuly log into roboflow and download the dataset but i dont know how to use it.
-
Project Type: Live Webcam Detection and counting
-
Operating System & Browser:
Windows 10 , Chrome -
**Project Universe Link or Workspace/Project ID:
Sign in to Roboflow **