【发布时间】:2020-01-24 18:52:31
【问题描述】:
我正在使用 raspivid 和 netcat 将视频从 RaspberryPi Zero 流式传输到我的 PC:
raspivid -t 0 -n -w 320 -h 240 -hf -fps 30 -o - | nc PC_IP PORT
现在我想在树莓派上逐帧分析这个视频来做物体检测。 Raspi 必须对对象检测做出反应,因此我必须在流式传输视频时对 Pi 进行分析。
我的想法是使用tee 命令创建一个命名管道,并在 python 程序中读取此命名管道以获取帧:
mkfifo streampipe
raspivid -t 0 -n -w 320 -h 240 -hf -fps 30-o - | tee nc PC_IP PORT | streampipe
但这不起作用,它说sh1: 1: streampipe: not found
我的 python 程序如下所示:
import subprocess as sp
import numpy
FFMPEG_BIN = "ffmpeg"
command = [ FFMPEG_BIN,
'-i', 'streampipe', # streampipe is the named pipe
'-pix_fmt', 'bgr24',
'-vcodec', 'rawvideo',
'-an','-sn', # we want to disable audio processing (there is no audio)
'-f', 'image2pipe', '-']
pipe = sp.Popen(command, stdout = sp.PIPE, bufsize=10**8)
while True:
# Capture frame-by-frame
raw_image = pipe.stdout.read(640*480*3)
# transform the byte read into a numpy array
image = numpy.fromstring(raw_image, dtype='uint8')
image = image.reshape((480,640,3)) # Notice how height is specified first and then width
if image is not None:
analyse(image)...
pipe.stdout.flush()
有人知道怎么做吗?
感谢您的回答。
【问题讨论】:
标签: python camera raspberry-pi video-streaming named-pipes