如何同时分析和流式处理RaspberryPi视频

问题描述 投票:1回答:1

我正在使用raspivid和netcat将RaspberryPi Zero的视频流传输到我的PC:

raspivid -t 0 -n -w 320 -h 240 -hf -fps 30 -o - | nc PC_IP PORT

现在,我要逐帧分析RaspberryPi上的视频以进行对象检测。 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
1个回答
0
投票

tee命令将stdin复制到stdout,并一路复制到您提到的任何其他文件:

ProcessThatWriteSTDOUT | tee SOMEFILE | ProcessThatReadsSTDIN

或制作两份副本:

ProcessThatWriteSTDOUT | tee FILE1 FILE2 | ProcessThatReadsSTDIN

您的nectcat命令不是文件,而是一个过程。因此,您需要使您的流程看起来像一个文件-名为““流程替换”] >>,您可以这样操作:

ProcessThatWriteSTDOUT | tee >(SomeProcess) | ProcessThatReadsSTDIN

因此,要拍摄长篇故事,您需要更多类似的东西:

raspivid ... -fps 30-o - | tee >(nc PC_IP PORT) | streampipe
© www.soinside.com 2019 - 2024. All rights reserved.