无法使用opencv读取我的ip摄像头视频

fykwrbwg  于 2023-11-22  发布在  其他
关注(0)|答案(1)|浏览(131)

你好,我是一个初学者在opencv,我试图通过海康威视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()

字符串
有人能帮帮我吗

polkgigr

polkgigr1#

我最终解决了这个问题,使用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()

字符串

相关问题