来自网络摄像头流的 Raspberry Pi 3 Python 和 OpenCV 人脸识别

2023-12-04

我尝试使用树莓派 3 型和摄像头模块通过 WiFi 网络传输视频,但发现与我在网上找到的其他示例存在一些不一致之处。我试图获得该视频中执行的第三次测试的结果:https://www.youtube.com/watch?v=sYGdge3T30o

我可以看到数据通过网络传输并进入fifo264在创建的文件中,我还有一个正在运行的 python 脚本,该脚本会在视频源无法再被处理之前运行几分钟。

OS X 机器上显示的视频最终崩溃。我不确定我的问题是否存在于我如何生成和发送视频(从 Raspberry Pi 端),或者是否存在于我如何使用 python 使用视频并处理它。

我正在尝试确定可能导致我的问题的平台差异,这个问题的重点是mkfifo and netcat权限以及这些程序跨平台行为方式之间可能存在的差异。

此 bash 脚本在 OS X 10.12.6 上使用。我正在尝试在端口 777 上侦听正在创建并发送到这台计算机的提要。

#!/bin/bash

if [ -p fifo264 ]
then
    rm fifo264
fi
mkfifo fifo264 
nc -l -v 777 > fifo264

当上面的脚本执行时./makeFifo.sh管道fifo264在工作目录中创建,并继承用户的用户权限。

sudo ./makeFifo.sh结果是ls -l as

prw-r--r-- 1 root staff 0 Feb 4 12:12 fifo264

AND

./makeFifo.sh结果是ls -l as

prw-r--r-- 1 user staff 0 Feb 4 12:12 fifo264

我还更改了 bash 脚本以提供-m 0777 with mkfifo result mkfifo -m 0777 fifo264。管道已使用适当的权限创建,但 netcat 无法建立开放777/tcp open multiling-http。我在跑nmap -sS -O localhost去测试。如果我使用机器的 IP 地址,结果是相同的。

如果我不使用 bash 脚本创建管道并从命令行执行 netcat 来侦听端口 777,我可以通过输入以下命令让 netcat 在 OS X 10.12.6 上创建开放的 777 端口sudo nc -l -v 777 > fifo264.

这导致创建一个开放的777/tcp open multiling-http但不创建管道。ls -l输出:

-rw-r--r-- 1 user staff 0 Feb 4 12:26 fifo264注意缺失的p来自权限字符串。

如果我用以下命令创建管道mkfifo fifo264从命令行,然后继续执行sudo nc -l -v 777 > fifo264,管道已创建,但 netcat 不会侦听端口 777。

将数据发送到非管道文件会产生任何延迟问题吗?这会对我用来显示提要的以下 python 脚本产生影响吗?我在 OS X 上使用 openCV 3.4 和 Python 3.6.4(我正在尝试处理视频源的机器)。videoFeed.py在下面:

import cv2
import subprocess as sp
import numpy

FFMPEG_BIN = "ffmpeg"
command = [ FFMPEG_BIN,
        '-i', 'fifo264',             # fifo is the named pipe
        '-pix_fmt', 'bgr24',      # opencv requires bgr24 pixel format.
        '-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:
        cv2.imshow('Video', image)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    pipe.stdout.flush()

cv2.destroyAllWindows()

从运行 RASPBIAN STRETCH WITH DESKTOP 的 RaspberryPi Model 3 B(2017 年 11 月)开始,我使用以下 bash 脚本来传输视频streamVideo.sh.

#!/bin/bash

raspivid -vf -n -w 640 -h 480 -o - -t 0 -b 1200000 | nc -v 10.0.0.3 777

到目前为止我已经能够完成的工作总结如下:

在 OS X 机器上,我发出sudo nc -l -v 777 > fifo264从终端执行以下 nmap 扫描:

Host is up (0.00015s latency).
Not shown: 993 closed ports
PORT     STATE SERVICE
80/tcp   open  http
445/tcp  open  microsoft-ds
548/tcp  open  afp
777/tcp  open  multiling-http

然后从 RaspberryPi 开始streamVideo.sh: Connection to 10.0.0.3 777 port [tcp/moira-update] succeeded!

在 OS X 机器上,我启动 python 脚本来访问 fifo264 feed。

python3 videoFeed.py

如果相机聚焦在帧中没有任何移动的静止物体上,它将流向fifo264喂养。如果我开始videoFeed.py几秒钟后,Python 脚本将从头开始显示视频源,但质量还不错,但有明显的延迟。

如果我开始videoFeed.py执行后立即streamVideo.sh来自 RaspberryPI 的脚本,延迟不存在,但图像质量很糟糕。这张截图是我在镜头前移动手时拍摄的。

enter image description here

您将在下面找到完整的输出videoFeed.py尝试使用视频源的 python 脚本。

ffmpeg version N-78264-g9079e99-tessus Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
  configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --as=yasm --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-version3 --disable-ffplay --disable-indev=qtkit --disable-indev=x11grab_xcb
  libavutil      55. 15.100 / 55. 15.100
  libavcodec     57. 22.102 / 57. 22.102
  libavformat    57. 23.100 / 57. 23.100
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 27.100 /  6. 27.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, h264, from 'fifo264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p, 640x480, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Output #0, image2pipe, to 'pipe:':
  Metadata:
    encoder         : Lavf57.23.100
    Stream #0:0: Video: rawvideo (BGR[24] / 0x18524742), bgr24, 640x480, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.22.102 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
[h264 @ 0x7f813c831800] error while decoding MB 6 6, bytestream -5
[h264 @ 0x7f813c831800] concealing 1003 DC, 1003 AC, 1003 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 30 20, bytestream -2884320.0kbits/s speed=1.43x    
[h264 @ 0x7f813c873200] concealing 419 DC, 419 AC, 419 MV errors in P frame
[NULL @ 0x7f813c808000] missing picture in access unit with size 919
[h264 @ 0x7f813c866000] no frame!
[h264 @ 0x7f813c824600] error while decoding MB 7 15, bytestream -7
[h264 @ 0x7f813c824600] concealing 642 DC, 642 AC, 642 MV errors in P frame
Error while decoding stream #0:0: Invalid data found when processing input.0kbits/s dup=2 drop=0 speed=1.42x    
[h264 @ 0x7f813c858e00] error while decoding MB 39 17, bytestream -6
[h264 @ 0x7f813c858e00] concealing 530 DC, 530 AC, 530 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 17 28, bytestream -6
[h264 @ 0x7f813c821600] concealing 112 DC, 112 AC, 112 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 31 21, bytestream -5
[h264 @ 0x7f813c880400] concealing 378 DC, 378 AC, 378 MV errors in P frame
[h264 @ 0x7f813c83ea00] error while decoding MB 38 18, bytestream -5
[h264 @ 0x7f813c83ea00] concealing 491 DC, 491 AC, 491 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 20 24, bytestream -5184320.0kbits/s dup=7 drop=0 speed=1.43x    
[h264 @ 0x7f813c880400] concealing 269 DC, 269 AC, 269 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 29 27, bytestream -6
[h264 @ 0x7f813c84bc00] concealing 140 DC, 140 AC, 140 MV errors in P frame
[h264 @ 0x7f813c83ea00] error while decoding MB 36 0, bytestream -10
[h264 @ 0x7f813c83ea00] concealing 1200 DC, 1200 AC, 1200 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 15 7, bytestream -9=184320.0kbits/s dup=9 drop=0 speed=1.42x    
[h264 @ 0x7f813c873200] concealing 954 DC, 954 AC, 954 MV errors in P frame
[h264 @ 0x7f813c824600] error while decoding MB 39 0, bytestream -25
[h264 @ 0x7f813c824600] concealing 1200 DC, 1200 AC, 1200 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 34 24, bytestream -6
[h264 @ 0x7f813c84bc00] concealing 255 DC, 255 AC, 255 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 32 21, bytestream -6184320.0kbits/s dup=15 drop=0 speed=1.44x    
[h264 @ 0x7f813c821600] concealing 377 DC, 377 AC, 377 MV errors in P frame
[h264 @ 0x7f813c858e00] error while decoding MB 28 22, bytestream -6
[h264 @ 0x7f813c858e00] concealing 341 DC, 341 AC, 341 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 4 29, bytestream -8
[h264 @ 0x7f813c880400] concealing 85 DC, 85 AC, 85 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 7 18, bytestream -6=184320.0kbits/s dup=17 drop=0 speed=1.44x    
[h264 @ 0x7f813c873200] concealing 522 DC, 522 AC, 522 MV errors in P frame
[h264 @ 0x7f813c866000] error while decoding MB 31 24, bytestream -10
[h264 @ 0x7f813c866000] concealing 258 DC, 258 AC, 258 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 23 28, bytestream -30
[h264 @ 0x7f813c84bc00] concealing 106 DC, 106 AC, 106 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 15 29, bytestream -9184320.0kbits/s dup=21 drop=0 speed=1.44x    
[h264 @ 0x7f813c880400] concealing 74 DC, 74 AC, 74 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 26 26, bytestream -5
[h264 @ 0x7f813c84bc00] concealing 183 DC, 183 AC, 183 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 37 14, bytestream -5
[h264 @ 0x7f813c880400] concealing 652 DC, 652 AC, 652 MV errors in P frame
[h264 @ 0x7f813c831800] error while decoding MB 36 24, bytestream -6
[h264 @ 0x7f813c831800] concealing 253 DC, 253 AC, 253 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 25 26, bytestream -5184320.0kbits/s dup=23 drop=0 speed=1.44x    
[h264 @ 0x7f813c880400] concealing 184 DC, 184 AC, 184 MV errors in P frame
[h264 @ 0x7f813c824600] error while decoding MB 37 2, bytestream -6
[h264 @ 0x7f813c824600] concealing 1132 DC, 1132 AC, 1132 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 33 23, bytestream -7
[h264 @ 0x7f813c84bc00] concealing 296 DC, 296 AC, 296 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 32 16, bytestream -5184320.0kbits/s dup=26 drop=0 speed=1.44x    
[h264 @ 0x7f813c821600] concealing 577 DC, 577 AC, 577 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 1 26, bytestream -6
[h264 @ 0x7f813c880400] concealing 208 DC, 208 AC, 208 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 32 12, bytestream -6184320.0kbits/s dup=28 drop=0 speed=1.43x    
[h264 @ 0x7f813c84bc00] concealing 737 DC, 737 AC, 737 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 27 26, bytestream -8
[h264 @ 0x7f813c880400] concealing 182 DC, 182 AC, 182 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 27 27, bytestream -5
[h264 @ 0x7f813c84bc00] concealing 142 DC, 142 AC, 142 MV errors in P frame
[h264 @ 0x7f813c831800] error while decoding MB 23 20, bytestream -7
[h264 @ 0x7f813c831800] concealing 426 DC, 426 AC, 426 MV errors in P frame
[h264 @ 0x7f813c858e00] error while decoding MB 29 26, bytestream -5184320.0kbits/s dup=31 drop=0 speed=1.43x    
[h264 @ 0x7f813c858e00] concealing 180 DC, 180 AC, 180 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 26 26, bytestream -5
[h264 @ 0x7f813c821600] concealing 183 DC, 183 AC, 183 MV errors in P frame
[h264 @ 0x7f813c858e00] error while decoding MB 27 27, bytestream -9
[h264 @ 0x7f813c858e00] concealing 142 DC, 142 AC, 142 MV errors in P frame
[h264 @ 0x7f813c824600] error while decoding MB 30 4, bytestream -8
[h264 @ 0x7f813c824600] concealing 1059 DC, 1059 AC, 1059 MV errors in P frame
[h264 @ 0x7f813c858e00] error while decoding MB 9 22, bytestream -5=184320.0kbits/s dup=33 drop=0 speed=1.42x    
[h264 @ 0x7f813c858e00] concealing 360 DC, 360 AC, 360 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 25 13, bytestream -12
[h264 @ 0x7f813c873200] concealing 704 DC, 704 AC, 704 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 14 1, bytestream -9
[h264 @ 0x7f813c880400] concealing 1195 DC, 1195 AC, 1195 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 29 23, bytestream -9
[h264 @ 0x7f813c821600] concealing 300 DC, 300 AC, 300 MV errors in P frame
[h264 @ 0x7f813c824600] error while decoding MB 30 25, bytestream -10
[h264 @ 0x7f813c824600] concealing 219 DC, 219 AC, 219 MV errors in P frame
[h264 @ 0x7f813c831800] error while decoding MB 27 27, bytestream -8
[h264 @ 0x7f813c831800] concealing 142 DC, 142 AC, 142 MV errors in P frame
[h264 @ 0x7f813c83ea00] error while decoding MB 13 23, bytestream -6184320.0kbits/s dup=34 drop=0 speed=1.42x    
[h264 @ 0x7f813c83ea00] concealing 316 DC, 316 AC, 316 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 37 12, bytestream -5
[h264 @ 0x7f813c84bc00] concealing 732 DC, 732 AC, 732 MV errors in P frame
[h264 @ 0x7f813c866000] error while decoding MB 27 2, bytestream -6
[h264 @ 0x7f813c866000] concealing 1142 DC, 1142 AC, 1142 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 22 25, bytestream -10
[h264 @ 0x7f813c873200] concealing 227 DC, 227 AC, 227 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 5 15, bytestream -6
[h264 @ 0x7f813c880400] concealing 644 DC, 644 AC, 644 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 27 13, bytestream -8
[h264 @ 0x7f813c84bc00] concealing 702 DC, 702 AC, 702 MV errors in P frame
[h264 @ 0x7f813c858e00] error while decoding MB 33 15, bytestream -12
[h264 @ 0x7f813c858e00] concealing 616 DC, 616 AC, 616 MV errors in P frame
[h264 @ 0x7f813c866000] error while decoding MB 39 16, bytestream -5
[h264 @ 0x7f813c866000] concealing 570 DC, 570 AC, 570 MV errors in P frame
[h264 @ 0x7f813c831800] error while decoding MB 27 29, bytestream -8
[h264 @ 0x7f813c831800] concealing 62 DC, 62 AC, 62 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 35 29, bytestream -5184320.0kbits/s dup=38 drop=0 speed=1.42x    
[h264 @ 0x7f813c873200] concealing 54 DC, 54 AC, 54 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 32 14, bytestream -14
[h264 @ 0x7f813c821600] concealing 657 DC, 657 AC, 657 MV errors in P frame
[h264 @ 0x7f813c824600] error while decoding MB 29 22, bytestream -7
[h264 @ 0x7f813c824600] concealing 340 DC, 340 AC, 340 MV errors in P frame
[h264 @ 0x7f813c831800] error while decoding MB 8 13, bytestream -7
[h264 @ 0x7f813c831800] concealing 721 DC, 721 AC, 721 MV errors in P frame
[NULL @ 0x7f813c808000] missing picture in access unit with size 1448
[h264 @ 0x7f813c83ea00] no frame!
[h264 @ 0x7f813c84bc00] error while decoding MB 9 16, bytestream -19
[h264 @ 0x7f813c84bc00] concealing 600 DC, 600 AC, 600 MV errors in P frame
[h264 @ 0x7f813c858e00] error while decoding MB 24 18, bytestream -16
[h264 @ 0x7f813c858e00] concealing 505 DC, 505 AC, 505 MV errors in P frame
Error while decoding stream #0:0: Invalid data found when processing input
[h264 @ 0x7f813c866000] error while decoding MB 22 13, bytestream -5
[h264 @ 0x7f813c866000] concealing 707 DC, 707 AC, 707 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 11 29, bytestream -6
[h264 @ 0x7f813c880400] concealing 78 DC, 78 AC, 78 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 38 14, bytestream -6
[h264 @ 0x7f813c821600] concealing 651 DC, 651 AC, 651 MV errors in P frame
[h264 @ 0x7f813c824600] error while decoding MB 6 17, bytestream -6
[h264 @ 0x7f813c824600] concealing 563 DC, 563 AC, 563 MV errors in P frame
[h264 @ 0x7f813c83ea00] error while decoding MB 19 27, bytestream -5
[h264 @ 0x7f813c83ea00] concealing 150 DC, 150 AC, 150 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 18 17, bytestream -9
[h264 @ 0x7f813c84bc00] concealing 551 DC, 551 AC, 551 MV errors in P frame
[h264 @ 0x7f813c858e00] error while decoding MB 38 9, bytestream -16
[h264 @ 0x7f813c858e00] concealing 851 DC, 851 AC, 851 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 8 19, bytestream -7=184320.0kbits/s dup=41 drop=0 speed=1.42x    
[h264 @ 0x7f813c880400] concealing 481 DC, 481 AC, 481 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 24 21, bytestream -14
[h264 @ 0x7f813c821600] concealing 385 DC, 385 AC, 385 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 26 23, bytestream -5
[h264 @ 0x7f813c873200] concealing 303 DC, 303 AC, 303 MV errors in P frame
[h264 @ 0x7f813c83ea00] error while decoding MB 31 26, bytestream -25
[h264 @ 0x7f813c83ea00] concealing 178 DC, 178 AC, 178 MV errors in P frame
[h264 @ 0x7f813c866000] error while decoding MB 25 28, bytestream -6
[h264 @ 0x7f813c866000] concealing 104 DC, 104 AC, 104 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 23 29, bytestream -1284320.0kbits/s dup=44 drop=0 speed=1.42x    
[h264 @ 0x7f813c821600] concealing 66 DC, 66 AC, 66 MV errors in P frame
[h264 @ 0x7f813c831800] error while decoding MB 23 20, bytestream -19
[h264 @ 0x7f813c831800] concealing 426 DC, 426 AC, 426 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 27 26, bytestream -10
[h264 @ 0x7f813c84bc00] concealing 182 DC, 182 AC, 182 MV errors in P frame
[h264 @ 0x7f813c858e00] error while decoding MB 31 26, bytestream -10
[h264 @ 0x7f813c858e00] concealing 178 DC, 178 AC, 178 MV errors in P frame
[h264 @ 0x7f813c866000] error while decoding MB 8 25, bytestream -8
[h264 @ 0x7f813c866000] concealing 241 DC, 241 AC, 241 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 39 27, bytestream -8
[h264 @ 0x7f813c873200] concealing 130 DC, 130 AC, 130 MV errors in P frame
[h264 @ 0x7f813c83ea00] error while decoding MB 26 13, bytestream -10
[h264 @ 0x7f813c83ea00] concealing 703 DC, 703 AC, 703 MV errors in P frame
[h264 @ 0x7f813c866000] error while decoding MB 5 23, bytestream -6
[h264 @ 0x7f813c866000] concealing 324 DC, 324 AC, 324 MV errors in P frame
[h264 @ 0x7f813c880400] error while decoding MB 39 4, bytestream -9=184320.0kbits/s dup=47 drop=0 speed=1.41x    
[h264 @ 0x7f813c880400] concealing 1050 DC, 1050 AC, 1050 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 27 27, bytestream -5
[h264 @ 0x7f813c821600] concealing 142 DC, 142 AC, 142 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 18 3, bytestream -7
[h264 @ 0x7f813c84bc00] concealing 1111 DC, 1111 AC, 1111 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 39 19, bytestream -8
[h264 @ 0x7f813c873200] concealing 450 DC, 450 AC, 450 MV errors in P frame
[h264 @ 0x7f813c866000] error while decoding MB 28 23, bytestream -6
[h264 @ 0x7f813c866000] concealing 301 DC, 301 AC, 301 MV errors in P frame
[h264 @ 0x7f813c824600] error while decoding MB 35 7, bytestream -5=184320.0kbits/s dup=51 drop=0 speed=1.41x    
[h264 @ 0x7f813c824600] concealing 934 DC, 934 AC, 934 MV errors in P frame
[h264 @ 0x7f813c83ea00] error while decoding MB 19 29, bytestream -7
[h264 @ 0x7f813c83ea00] concealing 70 DC, 70 AC, 70 MV errors in P frame
[h264 @ 0x7f813c873200] error while decoding MB 37 16, bytestream -6
[h264 @ 0x7f813c873200] concealing 572 DC, 572 AC, 572 MV errors in P frame
[h264 @ 0x7f813c831800] error while decoding MB 16 12, bytestream -5
[h264 @ 0x7f813c831800] concealing 753 DC, 753 AC, 753 MV errors in P frame
[h264 @ 0x7f813c866000] error while decoding MB 29 13, bytestream -6
[h264 @ 0x7f813c866000] concealing 700 DC, 700 AC, 700 MV errors in P frame
[h264 @ 0x7f813c821600] error while decoding MB 31 8, bytestream -6=184320.0kbits/s dup=55 drop=0 speed=1.42x    
[h264 @ 0x7f813c821600] concealing 898 DC, 898 AC, 898 MV errors in P frame
[h264 @ 0x7f813c84bc00] error while decoding MB 11 22, bytestream -6
[h264 @ 0x7f813c84bc00] concealing 358 DC, 358 AC, 358 MV errors in P frame
frame=  400 fps= 35 q=-0.0 Lsize=  360000kB time=00:00:16.00 bitrate=184320.0kbits/s dup=56 drop=0 speed=1.41x    
video:360000kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
Traceback (most recent call last):
  File "videoFeed.py", line 19, in <module>
    image = image.reshape((480,640,3))          # Notice how height is specified first and then width
ValueError: cannot reshape array of size 0 into shape (480,640,3)

我在某处读到,如果您在管道开始接收数据后不立即开始读取数据,则可能会出现问题,但如果有人能指出潜在的问题,那将会有所帮助。

Update

我可以使用 netcat 获得高质量的摄像机源,同时将输出传输到 mplayer:

sudo nc -l 777 | mplayer -fps 200 -demuxer h264es -

所以我只能假设这与我处理饲料的方式有关,而不是与管道的构造方式有关。

更多测试

使用以下脚本我可以从 fifo264 管道读取视频,但它也会终止。

import cv2
import sys

video_capture = cv2.VideoCapture(r'fifo264')
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640);
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480);

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()
    if ret == False:
        pass

    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

从 Raspberry PI 进行流式传输:

#!/bin/bash

raspivid -ih -vs -vf -n -w 640 -h 480 -o - -t 0 -b 2000000 | nc -v 10.0.0.3 777

错误和产生的输出:

[h264 @ 0x7fb25005d400] error while decoding MB 22 28, bytestream -8
[h264 @ 0x7fb250068c00] error while decoding MB 8 24, bytestream -9
[h264 @ 0x7fb25005d400] error while decoding MB 2 18, bytestream -5
[h264 @ 0x7fb250060400] error while decoding MB 23 11, bytestream -7
[h264 @ 0x7fb250073000] error while decoding MB 22 18, bytestream -11
[h264 @ 0x7fb250073600] error while decoding MB 36 9, bytestream -5
[h264 @ 0x7fb250067a00] error while decoding MB 29 23, bytestream -8
[NULL @ 0x7fb251155a00] missing picture in access unit with size 1448
[h264 @ 0x7fb251155400] Got unexpected packet size after a partial decode
[h264 @ 0x7fb251155400] Got unexpected packet size after a partial decode
[h264 @ 0x7fb251155400] Got unexpected packet size after a partial decode
[NULL @ 0x7fb251155a00] missing picture in access unit with size 1448
[h264 @ 0x7fb251155400] Got unexpected packet size after a partial decode
[h264 @ 0x7fb25005d400] error while decoding MB 35 2, bytestream -6
[NULL @ 0x7fb251155a00] missing picture in access unit with size 1200
[h264 @ 0x7fb25005d400] No start code is found.
[h264 @ 0x7fb25005d400] Error splitting the input into NAL units.
OpenCV(3.4.0-dev) Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /Users/jamie/opencv/modules/highgui/src/window.cpp, line 356
Traceback (most recent call last):
  File "video3.py", line 14, in <module>
    cv2.imshow('Video', frame)
cv2.error: OpenCV(3.4.0-dev) /Users/jamie/opencv/modules/highgui/src/window.cpp:356: error: (-215) size.width>0 && size.height>0 in function imshow

归根结底,这不是管道、平台或权限的结果。在 Raspberry Pi 上生成并通过管道传输到 python 脚本的视频未得到正确处理。

我最终适应了这个picamera蟒蛇食谱

在 Raspberry Pi 上:(createStream.py)

import io
import socket
import struct
import time
import picamera

# Connect a client socket to my_server:8000 (change my_server to the
# hostname of your server)
client_socket = socket.socket()
client_socket.connect(('10.0.0.3', 777))

# Make a file-like object out of the connection
connection = client_socket.makefile('wb')
try:
    with picamera.PiCamera() as camera:
        camera.resolution = (1024, 768)
        # Start a preview and let the camera warm up for 2 seconds
        camera.start_preview()
        time.sleep(2)

        # Note the start time and construct a stream to hold image data
        # temporarily (we could write it directly to connection but in this
        # case we want to find out the size of each capture first to keep
        # our protocol simple)
        start = time.time()
        stream = io.BytesIO()
        for foo in camera.capture_continuous(stream, 'jpeg', use_video_port=True):
            # Write the length of the capture to the stream and flush to
            # ensure it actually gets sent
            connection.write(struct.pack('<L', stream.tell()))
            connection.flush()

            # Rewind the stream and send the image data over the wire
            stream.seek(0)
            connection.write(stream.read())

            # Reset the stream for the next capture
            stream.seek(0)
            stream.truncate()
    # Write a length of zero to the stream to signal we're done
    connection.write(struct.pack('<L', 0))
finally:
    connection.close()
    client_socket.close()

在处理流的机器上:(processStream.py)

import io
import socket
import struct
import cv2
import numpy as np

# Start a socket listening for connections on 0.0.0.0:8000 (0.0.0.0 means
# all interfaces)
server_socket = socket.socket()
server_socket.bind(('0.0.0.0', 777))
server_socket.listen(0)

# Accept a single connection and make a file-like object out of it
connection = server_socket.accept()[0].makefile('rb')
try:
    while True:
        # Read the length of the image as a 32-bit unsigned int. If the
        # length is zero, quit the loop
        image_len = struct.unpack('<L', connection.read(struct.calcsize('<L')))[0]
        if not image_len:
            break
        # Construct a stream to hold the image data and read the image
        # data from the connection
        image_stream = io.BytesIO()
        image_stream.write(connection.read(image_len))
        # Rewind the stream, open it as an image with opencv and do some
        # processing on it
        image_stream.seek(0)
        image = Image.open(image_stream)

        data = np.fromstring(image_stream.getvalue(), dtype=np.uint8)
        imagedisp = cv2.imdecode(data, 1)

        cv2.imshow("Frame",imagedisp)
        cv2.waitKey(1)  #imshow will not output an image if you do not use waitKey
        cv2.destroyAllWindows() #cleanup windows 
finally:
    connection.close()
    server_socket.close()

该解决方案与我在原始问题中引用的视频具有相似的结果。较大的分辨率帧会增加提要的延迟,但这对于我的应用程序来说是可以容忍的。

首先需要运行processStream.py,然后在Raspberry Pi上执行createStream.py

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

来自网络摄像头流的 Raspberry Pi 3 Python 和 OpenCV 人脸识别 的相关文章

  • 将 saxon 与 python 结合使用

    我需要使用 python 处理 XSLT 目前我正在使用仅支持 XSLT 1 的 lxml 现在我需要处理 XSLT 2 有没有办法将 saxon XSLT 处理器与 python 一起使用 有两种可能的方法 设置一个 HTTP 服务 接受
  • OpenCV Python cv2.mixChannels()

    我试图将其从 C 转换为 Python 但它给出了不同的色调结果 In C Transform it to HSV cvtColor src hsv CV BGR2HSV Use only the Hue value hue create
  • 如何在 Python 中检索 for 循环中的剩余项目?

    我有一个简单的 for 循环迭代项目列表 在某些时候 我知道它会破裂 我该如何退回剩余的物品 for i in a b c d e f g try some func i except return remaining items if s
  • 如何从网页中嵌入的 Tableau 图表中抓取工具提示值

    我试图弄清楚是否有一种方法以及如何使用 python 从网页中的 Tableau 嵌入图形中抓取工具提示值 以下是当用户将鼠标悬停在条形上时带有工具提示的图表示例 我从要从中抓取的原始网页中获取了此网址 https covid19 colo
  • 测试 python Counter 是否包含在另一个 Counter 中

    如何测试是否是pythonCounter https docs python org 2 library collections html collections Counter is 包含在另一个中使用以下定义 柜台a包含在计数器中b当且
  • 基于代理的模拟:性能问题:Python vs NetLogo & Repast

    我正在 Python 3 中复制一小段 Sugarscape 代理模拟模型 我发现我的代码的性能比 NetLogo 慢约 3 倍 这可能是我的代码的问题 还是Python的固有限制 显然 这只是代码的一个片段 但 Python 却花费了三分
  • Python 函数可以从作用域之外赋予新属性吗?

    我不知道你可以这样做 def tom print tom s locals locals def dick z print z name z name z guest Harry print z guest z guest print di
  • 如何使用 OpencV 从 Firebase 读取图像?

    有没有使用 OpenCV 从 Firebase 读取图像的想法 或者我必须先下载图片 然后从本地文件夹执行 cv imread 功能 有什么办法我可以使用cv imread link of picture from firebase 您可以
  • AWS EMR Spark Python 日志记录

    我正在 AWS EMR 上运行一个非常简单的 Spark 作业 但似乎无法从我的脚本中获取任何日志输出 我尝试过打印到 stderr from pyspark import SparkContext import sys if name m
  • 如何在Python中获取葡萄牙语字符?

    我正在研究葡萄牙语 角色看起来很奇怪 我怎样才能解决这个问题 代码 import feedparser import random Vou definir os feeds feeds conf feedurl http pplware s
  • 在f字符串中转义字符[重复]

    这个问题在这里已经有答案了 我遇到了以下问题f string gt gt gt a hello how to print hello gt gt gt f a a gt gt gt f a File
  • 使用 \r 并打印一些文本后如何清除控制台中的一行?

    对于我当前的项目 有一些代码很慢并且我无法使其更快 为了获得一些关于已完成 必须完成多少的反馈 我创建了一个进度片段 您可以在下面看到 当你看到最后一行时 sys stdout write r100 80 n I use 80覆盖最终剩余的
  • Pandas:merge_asof() 对多行求和/不重复

    我正在处理两个数据集 每个数据集具有不同的关联日期 我想合并它们 但因为日期不完全匹配 我相信merge asof 是最好的方法 然而 有两件事发生merge asof 不理想的 数字重复 数字丢失 以下代码是一个示例 df a pd Da
  • 每个 X 具有多个 Y 值的 Python 散点图

    我正在尝试使用 Python 创建一个散点图 其中包含两个 X 类别 cat1 cat2 每个类别都有多个 Y 值 如果每个 X 值的 Y 值的数量相同 我可以使用以下代码使其工作 import numpy as np import mat
  • 对年龄列进行分组/分类

    我有一个数据框说df有一个柱子 Ages gt gt gt df Age 0 22 1 38 2 26 3 35 4 35 5 1 6 54 我想对这个年龄段进行分组并创建一个像这样的新专栏 If age gt 0 age lt 2 the
  • 解释 Python 中的数字范围

    在 Pylons Web 应用程序中 我需要获取一个字符串 例如 关于如何做到这一点有什么建议吗 我是 Python 新手 我还没有找到任何可以帮助解决此类问题的东西 该列表将是 1 2 3 45 46 48 49 50 51 77 使用
  • Conda SafetyError:文件大小不正确

    使用创建 Conda 环境时conda create n env name python 3 6 我收到以下警告 Preparing transaction done Verifying transaction SafetyError Th
  • 发送用户注册密码,django-allauth

    我在 django 应用程序上使用 django alluth 进行身份验证 注册 我需要创建一个自定义注册表单 其中只有一个字段 电子邮件 密码将在服务器上生成 这是我创建的表格 from django import forms from
  • 从列表指向字典变量

    假设你有一个清单 a 3 4 1 我想用这些信息来指向字典 b 3 4 1 现在 我需要的是一个常规 看到该值后 在 b 的位置内读写一个值 我不喜欢复制变量 我想直接改变变量b的内容 假设b是一个嵌套字典 你可以这样做 reduce di
  • 如何使用 Pycharm 安装 tkinter? [复制]

    这个问题在这里已经有答案了 I used sudo apt get install python3 6 tk而且效果很好 如果我在终端中打开 python Tkinter 就可以工作 但我无法将其安装在我的 Pycharm 项目上 pip

随机推荐

  • 编写存储过程来获取 Jqgrid 分页数据的困难

    我正在使用以下 SQL 过程来获取用于我的 Web 应用程序中 JqGrid 分页的数据 ALTER PROCEDURE dbo NewStoredProc skip int pageSize int OrderBy Varchar 20
  • 检测快速按两次电源按钮

    是否可以检测用户是否快速按下电源按钮两次 Apple 使用这种方式在带有 Face ID 的新款 iPhone X 上确认 Appstore 购买 有可用的API吗 希望在类似情况下使用它通过 Face ID 进行身份验证 不会 系统本身控
  • 将 YAML 与变量一起使用

    YAML 文件中可以使用变量吗 例如 theme name default css path compiled themes theme name layout path themes theme name 在这个例子中 如何theme n
  • Mac OS X 上 sqlite4java Jar 出现 UnsatisfiedLinkError

    我在 Java 应用程序中使用 sqlite4java 库 当我在 Eclipse 中运行它时它工作得很好 但是当我构建可运行的 JAR 并尝试在 Mac OS X 上运行它时 出现以下错误 Error Could not load dat
  • C# DLL 配置文件

    我试图将 app config 文件添加到我的 DLL 中 但所有尝试都失败了 据 音乐创世纪 报道 将配置信息放入 DLL 中 这应该不是问题 所以显然我做错了什么 以下代码应从 DLL 返回我的 ConnectionString ret
  • 使用 VBA 方法通过 Bing API 获取距离

    我试图通过 VBA 创建一个方法 当我使用此方法时 它显示 NAME 有时 value Public Function DISTANCE start As String dest As String key As String Dim fi
  • Objective-C UITableView 单元格图像

    所以我有一个UI表格视图Facebook 好友和一个单元格 我想将图像添加到其中 当我尝试以下代码时 cell imageView image UIImage imageWithData NSData dataWithContentsOfU
  • 从数据库或属性获取 Spring Security 拦截 url

    希望这非常简单 存在 并且我忽略了我眼皮底下的一些东西 我知道我可以通过注释限制访问 Secured ROLE ADMIN 或通过配置
  • UIButton标题消失

    我有一个 ViewController 里面有一个 UIButton 当我点击时 按钮上的文字消失了 我为所有状态添加了所有 setTitle 但它继续消失 任何想法 这是我的代码的一部分 interface AddCardViewCont
  • 重塑表格以将行转换为列

    我尝试搜索帖子 但只找到了 SQL Server Access 的解决方案 我需要 MySQL 5 X 中的解决方案 我有一个包含 3 列的表 称为历史记录 hostid itemname itemvalue 如果我做一个选择 select
  • 如何在 mysql C++ 连接器中设置超时

    我正在使用 C 连接器连接到 MySQL 服务器 当服务器离线或处于睡眠状态时 语句执行方法需要一段时间才能检测连接问题 是否有方法或变量来控制客户端的等待超时时间 Regards德瓦拉 古达 您可以使用mysql options设置客户端
  • Swift Spritekit 我检测到碰撞,但它多次读取碰撞

    AppImage我有一堵由 4 个不同颜色的矩形组成的墙 要穿过这堵墙 球的颜色必须与墙上的矩形的颜色相匹配 球将穿过墙壁 新的墙壁将会出现 然而 当我检测到这种碰撞时 我得到了多个碰撞读数 我已经通过打印死或活来测试这一点 并且它会多次打
  • Idea 中的 Tomcat。战争爆发:服务器未连接。部署不可用

    我正在尝试这个tutoial 我创建了新项目并运行它 TomCat 启动了 但之后什么也没发生 我可以手动在浏览器中打开http localhost 8080并查看 TomCat 主页 这意味着服务器可以启动 但是我无法打开index js
  • ajax成功后jQuery继续循环执行

    我有一个循环中的 jQuery ajax 调用 但是我不希望同时进行这些 ajax 调用 我需要先完成第一个 ajax 调用 然后再进行下一个调用 for var i 0 i lt options length i jQuery ajax
  • 在 python 中使用 enumerate() 时从列表中删除元素[重复]

    这个问题在这里已经有答案了 Object 是一个解码后的 json 对象 其中包含一个名为 items 的列表 obj json loads response body as unicode for index item in enumer
  • 如何使用 GAE 创建自动完成功能?

    我使用 jQuery UI自动完成小部件 我还有 GAE 数据存储 class Person db Model key name contains person id in format lastname firstname middlen
  • 如何将 JRE 捆绑到 Java 应用程序的 EXE 中? Launch4j 提示“运行时丢失或损坏。”

    我对 Java 编程很陌生 但总体上熟悉一切的工作原理 我希望能够将 jar 文件和 jre 放入 Windows 可执行文件 exe 中 这样当我分发它时 客户端不需要安装 JRE 我应该使用什么程序 我有 launch4j 它似乎完全符
  • WindowChrome - 无法单击标题栏中的按钮

    我的 WPF 应用程序有一个自定义 WindowChrome 样式 从此处摘取 http www bdevuyst com wpf custom title bar and taskbar 代码在这里
  • pygobject 中的拖放无响应

    我试图让拖放在 pygobject 中正常工作 但它很慢而且反应迟钝 90 的时间我必须挥动我正在拖动的项目才能成功放下它 任何人都可以看看我是否做得不正确或者这是 pygobject 的错误 这是我的代码 from gi reposito
  • 来自网络摄像头流的 Raspberry Pi 3 Python 和 OpenCV 人脸识别

    我尝试使用树莓派 3 型和摄像头模块通过 WiFi 网络传输视频 但发现与我在网上找到的其他示例存在一些不一致之处 我试图获得该视频中执行的第三次测试的结果 https www youtube com watch v sYGdge3T30o