1 Star 0 Fork 0

data_factory/ONNX-YOLO-World-Open-Vocabulary-Object-Detection

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
video_object_detection.py 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
Ibai Gorordo 提交于 2024-04-07 11:47 . Initial release
import cv2
from cap_from_youtube import cap_from_youtube
from yoloworld import YOLOWorld, DetectionDrawer, read_class_embeddings
model_path = "models/yolov8x-worldv2.onnx"
embed_path = "data/video_embeddings.npz"
# Load class embeddings
class_embeddings, class_list = read_class_embeddings(embed_path)
# Initialize YOLO-World object detector
yoloworld_detector = YOLOWorld(model_path, conf_thres=0.1, iou_thres=0.5)
num_classes = yoloworld_detector.num_classes
print("Number of classes:", num_classes, "Number of classes loaded:", len(class_list))
# Initialize video
# cap = cv2.VideoCapture("input.mp4")
videoUrl = 'https://youtu.be/Atkp8mklOh0?si=MsFhQJZJDsjyQTqF'
cap = cap_from_youtube(videoUrl, resolution='720p')
start_time = 0 # skip first {start_time} seconds
cap.set(cv2.CAP_PROP_POS_FRAMES, start_time * cap.get(cv2.CAP_PROP_FPS))
# out = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), cap.get(cv2.CAP_PROP_FPS), (int(cap.get(3)), int(cap.get(4))))
# Initialize DetectionDrawer
drawer = DetectionDrawer(class_list)
cv2.namedWindow("Detected Objects", cv2.WINDOW_NORMAL)
while cap.isOpened():
# Read frame from the video
ret, frame = cap.read()
if not ret:
break
# Detect Objects
boxes, scores, class_ids = yoloworld_detector(frame, class_embeddings)
# Draw detections
combined_img = drawer(frame, boxes, scores, class_ids)
# Draw what label we are detecting
# cv2.putText(combined_img, f"Detecting: {class_list}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.imshow("Detected Objects", combined_img)
# out.write(combined_img)
# Press key q to stop
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
# out.release()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/data_factory/ONNX-YOLO-World-Open-Vocabulary-Object-Detection.git
git@gitee.com:data_factory/ONNX-YOLO-World-Open-Vocabulary-Object-Detection.git
data_factory
ONNX-YOLO-World-Open-Vocabulary-Object-Detection
ONNX-YOLO-World-Open-Vocabulary-Object-Detection
main

搜索帮助