我正在尝试将 Yolov8 对象检测模型连接到直播。我在Python中使用Opencv。下面是代码。脚本运行,工作正常几分钟,然后给出以下错误:
[h264 @ 0000021fec1f0040] cabac decode of qscale diff failed at 33 32
[h264 @ 0000021fec1f0040] error while decoding MB 33 32, bytestream 145146
[h264 @ 0000021fec56f300] error while decoding MB 56 14, bytestream -5.
这是代码:
import cv2
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO(r'...\best.pt')
# Open the video file
video_path = "rtsp://..."
cap = cv2.VideoCapture(video_path)
# Loop through the video frames
while cap.isOpened():
success, frame = cap.read()
if success:
results = model.track(frame, persist=True)
annotated_frame = results[0].plot()
cv2.imshow("Palka", annotated_frame)
我以为这是一个编码问题,但脚本可以工作并识别这些项目,但随后会出现错误
我使用此代码解决了问题:
import cv2
from ultralytics import YOLO
model = YOLO(r'best.pt')
results = model.track(source='rtsp:...', show=True)
video_cap = cv2.VideoCapture(results)
while True:
ret, frame = video_cap.read()
model.cpu()
if not ret:
break
cv2.imshow("Frame", frame)
if cv2.waitKey(1) == ord("q"):
break
video_cap.release()
cv2.destroyAllWindows()
但是现在我无法使用此代码在屏幕上显示形状:
annotated_frame = results[0].plot()
cv2.rectangle(annotated_frame, (100, 900), (600, 700), (0, 0, 255), 2)
cv2.rectangle(annotated_frame, (1250, 710), (1800, 900), (0, 0, 255), 2)
有人知道如何解决这个问题吗?