zbar没有使用来自使用OpenCV读取的覆盆子pi的netcat视频流

时间:2017-12-26 19:42:06

标签: python opencv ffmpeg netcat zbar

我正在使用netcam将视频输入从使用netcam传输到我的电脑,并使用zbar读取输入的qr代码。 我正在使用ffmpeg:

读取命名管道
FFMPEG_BIN = "ffmpeg"
command = [ FFMPEG_BIN,
    '-i', 'fifo264',             # fifo is the named pipe
    '-pix_fmt', 'gray',      # 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)

zbar在这种情况下没有显示输出。 完整代码:

import cv2
import subprocess as sp
import numpy
import zbar
from PIL import Image


FFMPEG_BIN = "ffmpeg"
command = [ FFMPEG_BIN,
        '-i', 'fifo264',             # fifo is the named pipe
        '-pix_fmt', 'gray',      # 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(1920*1088)
    # transform the byte read into a numpy array
    image =  numpy.fromstring(raw_image, dtype='uint8')
    image = image.reshape((1088,1920))          # Notice how height is specified first and then width
    if image is not None:
        cv2.imshow('Video', image)
        image = Image.fromarray(image)
        width, height = image.size
        zbar_image = zbar.Image(width, height, 'Y800', image.tostring())

        # Scans the zbar image.
        scanner = zbar.ImageScanner()
        scanner.scan(zbar_image)

        # Prints data from image.
        for decoded in zbar_image:
            print(decoded.data)

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

cv2.destroyAllWindows()

0 个答案:

没有答案