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

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

你好,我是一个初学者在opencv,我试图通过海康威视IP摄像机创建一个真实的时间对象检测程序。使用RTSP,但当我运行代码,我得到这个错误
Ip_add类似于rtsp://login:password@ip_address:554/streaming/channels/101

  1. cap = cv2.VideoCapture(Ip_add, cv2.CAP_FFMPEG)
  2. while True:
  3. _, frame = cap.read()
  4. frame = cv2.resize(frame, dsize=(1400, 600))
  5. (class_ids, scores, bboxes) = model.detect(frame)
  6. for class_id, score, bbox in zip(class_ids, scores, bboxes):
  7. (x, y, w, h) = bbox
  8. cv2.putText(frame, classes[class_id], (x, y - 10), cv2.FONT_HERSHEY_PLAIN, 2,(200, 0, 50),2)
  9. cv2.rectangle(frame, (x, y), (x + w, y + h), (200, 0, 50), 2)
  10. cv2.imshow("IP Camera", frame)
  11. if cv2.waitKey(1) == ord("q"):
  12. break
  13. cap.release()
  14. cv2.destroyAllWindows()

字符串
有人能帮帮我吗

polkgigr

polkgigr1#

我最终解决了这个问题,使用imutils而不是opencv来读取真实的时间视频流。

  1. import cv2
  2. import imutils
  3. from imutils.video import VideoStream
  4. rtsp_url = "rtsp://login:passzord@ipaddress/streaming/channels/101"
  5. video_stream = VideoStream(rtsp_url).start()
  6. while True:
  7. frame = video_stream.read()
  8. if frame is None:
  9. continue
  10. frame = imutils.resize(frame,width=1200)
  11. frame = cv2.resize(frame, dsize=(1400, 600))
  12. cv2.imshow('Ip Camera ', frame)
  13. key = cv2.waitKey(1) & 0xFF
  14. if key == ord('q'):
  15. break
  16. cv2.destroyAllWindows()
  17. video_stream.stop()

字符串

展开查看全部

相关问题