yolov8使用opencv 调用摄像头,实时目标检测、分割、关键点检测,左上角显示帧率
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv
免费下载资源
·
一、目标检测
import cv2
from ultralytics import YOLO
# 加载 YOLOv8 模型
model = YOLO('yolov8n.pt')
video_path =0 #摄像头ip地址
cap = cv2.VideoCapture(video_path)
while cap.isOpened():
status, frame = cap.read()
if not status:
break
results = model.predict(source=frame)
result = results[0]
anno_frame = result.plot()
cv2.imshow("V8", anno_frame)
# 设置延迟以减慢视频播放速度
if cv2.waitKey(30) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
二、关键点检测
import cv2
from ultralytics import YOLO
# 加载 YOLOv8 模型
model = YOLO('yolov8n-pose.pt')
video_path =0 #摄像头ip地址
cap = cv2.VideoCapture(video_path)
while cap.isOpened():
status, frame = cap.read()
if not status:
break
results = model.predict(source=frame)
result = results[0]
anno_frame = result.plot()
cv2.imshow("V8", anno_frame)
# 设置延迟以减慢视频播放速度
if cv2.waitKey(30) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
三、分割
import cv2
from ultralytics import YOLO
# 加载 YOLOv8 模型
model = YOLO('yolov8n-seg.pt')
video_path =0 #摄像头ip地址
cap = cv2.VideoCapture(video_path)
while cap.isOpened():
status, frame = cap.read()
if not status:
break
results = model.predict(source=frame)
result = results[0]
anno_frame = result.plot()
cv2.imshow("V8", anno_frame)
# 设置延迟以减慢视频播放速度
if cv2.waitKey(30) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
GitHub 加速计划 / opencv31 / opencv
77.39 K
55.71 K
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:2 个月前 )
7be5181b
Fixed KLEIDICV_SOURCE_PATH handling for external KleidiCV 1 天前
c3ca3f4f - 1 天前
更多推荐
已为社区贡献1条内容
所有评论(0)