在 Python 中从 RTSP 流中读取帧 [英] Read Frames from RTSP Stream in Python

查看:122
本文介绍了在 Python 中从 RTSP 流中读取帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近设置了一个 Raspberry Pi 摄像头,并且正在通过 RTSP 流式传输帧.虽然它可能不是完全必要的,但这是我使用广播视频的命令:

I have recently set up a Raspberry Pi camera and am streaming the frames over RTSP. While it may not be completely necessary, here is the command I am using the broadcast the video:

raspivid -o - -t 0 -w 1280 -h 800 |cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/output.h264}' :demux=h264

这完美地播放了视频.

我现在想做的是用 Python 解析这个流并单独读取每一帧.我想做一些用于监视目的的运动检测.

What I would now like to do is parse this stream with Python and read each frame individually. I would like to do some motion detection for surveillance purposes.

我完全不知道从哪里开始这项任务.谁能指点我一个好的教程?如果这无法通过 Python 实现,我可以使用哪些工具/语言来实现?

I am completely lost on where to start on this task. Can anyone point me to a good tutorial? If this is not achievable via Python, what tools/languages can I use to accomplish this?

推荐答案

使用depu"列出的相同方法对我来说非常有效.我只是用实际相机的RTSP URL"替换了视频文件".下面的示例适用于 AXIS IP 摄像机.(这在以前版本的 OpenCV 中暂时不起作用)适用于 OpenCV 3.4.1 Windows 10)

Using the same method listed by "depu" worked perfectly for me. I just replaced "video file" with "RTSP URL" of actual camera. Example below worked on AXIS IP Camera. (This was not working for a while in previous versions of OpenCV) Works on OpenCV 3.4.1 Windows 10)

import cv2
cap = cv2.VideoCapture("rtsp://root:pass@192.168.0.91:554/axis-media/media.amp")

while(cap.isOpened()):
    ret, frame = cap.read()
    cv2.imshow('frame', frame)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

这篇关于在 Python 中从 RTSP 流中读取帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆