无法使用opencv读取我的网络摄像机视频

问题描述 投票:0回答:2

您好,我是 opencv 的初学者,我正在尝试通过 HIKVISION IP 摄像机创建实时物体检测程序。使用 RTSP 但当我运行代码时出现此错误

Ip_add 就像

rtsp://login:password@ip_address:554/streaming/channels/101

cap = cv2.VideoCapture(Ip_add, cv2.CAP_FFMPEG)

while True:
_, frame = cap.read()
frame = cv2.resize(frame, dsize=(1400, 600))

(class_ids, scores, bboxes) = model.detect(frame)

for class_id, score, bbox in zip(class_ids, scores, bboxes):
    (x, y, w, h) = bbox
    cv2.putText(frame, classes[class_id], (x, y - 10), cv2.FONT_HERSHEY_PLAIN, 2,(200, 0, 50),2)
    cv2.rectangle(frame, (x, y), (x + w, y + h), (200, 0, 50), 2)
cv2.imshow("IP Camera", frame)
if cv2.waitKey(1) == ord("q"):
    break
cap.release()
cv2.destroyAllWindows()

有人可以帮助我吗?

python opencv rtsp
2个回答
0
投票

我最终通过使用

imutils
而不是
opencv
来读取实时视频流解决了这个问题。

import cv2
import imutils
from imutils.video import VideoStream

rtsp_url = "rtsp://login:passzord@ipaddress/streaming/channels/101"
video_stream = VideoStream(rtsp_url).start()

while True:
frame = video_stream.read()
if frame is None:
    continue

frame = imutils.resize(frame,width=1200)

frame = cv2.resize(frame, dsize=(1400, 600))


cv2.imshow('Ip Camera ', frame)
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
    break

cv2.destroyAllWindows()
video_stream.stop()

0
投票

传入图像有延迟。你是怎么解决的?

© www.soinside.com 2019 - 2024. All rights reserved.