转换YUYV 4:2:2,出了什么问题?

时间:2016-06-07 10:43:03

标签: python image v4l2

我使用v4l2在我的Raspberry Pi 2上捕获了原始的YUYV 4:2:2图像:

v4l2-ctl -d /dev/video0 -i 0 -s NTSC --set-fmt-video=width=720,height=480,pixelformat=0
v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=frame.raw --stream-count=1

现在我尝试使用以下Python脚本转换原始YUYV 4:2:2图像:

import Image
import sys

image_name = sys.argv[1]
width = int(sys.argv[2])
height = int(sys.argv[3])

f_yuyv = open(image_name, "rb")
image_out = Image.new("RGB", (width, height))
pix = image_out.load()

print "width=", width, "height=", height

for i in range(0,height):
    for j in range(0, width/2):

        y1 = ord(f_yuyv.read(1));
        u  = ord(f_yuyv.read(1));
        y2 = ord(f_yuyv.read(1));
        v  = ord(f_yuyv.read(1));

        B = 1.164 * (y1-16) + 2.018 * (u - 128)
        G = 1.164 * (y1-16) - 0.813 * (v - 128) - 0.391 * (u - 128)
        R = 1.164 * (y1-16) + 1.596 * (v - 128)
        pix[j*2, i] = int(R), int(G), int(B)

        B = 1.164 * (y2-16) + 2.018 * (u - 128)
        G = 1.164 * (y2-16) - 0.813 * (v - 128) - 0.391 * (u - 128)
        R = 1.164 * (y2-16) + 1.596 * (v - 128)
        pix[j*2+1, i] = int(R), int(G), int(B)

image_out.save("out.bmp")
image_out.show()

我得到的结果看起来有点奇怪: Result of the conversion

任何想知道问题在哪里的人

此外,这里是我用来捕捉原始YUYV 4:2:2图像的视频设备的属性:

pi@raspberrypi:~ $ v4l2-ctl --all
Driver Info (not using libv4l2):
        Driver name   : usbtv
        Card type     : usbtv
        Bus info      : usb-3f980000.usb-1.3
        Driver version: 4.4.11
        Capabilities  : 0x85200001
                Video Capture
                Read/Write
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x05200001
                Video Capture
                Read/Write
                Streaming
                Extended Pix Format
Priority: 2
Video input : 0 (Composite: ok)
Video Standard = 0x0000f900
        PAL-M/60
        NTSC-M/M-JP/443/M-KR
Format Video Capture:
        Width/Height  : 720/480
        Pixel Format  : 'YUYV'
        Field         : Interlaced
        Bytes per Line: 1440
        Size Image    : 691200
        Colorspace    : Broadcast NTSC/PAL (SMPTE170M/ITU601)
        Flags         :
Streaming Parameters Video Capture:
        Frames per second: 29.970 (30000/1001)
        Read buffers     : 2

pi@raspberrypi:~ $ v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'YUYV'
        Name        : YUYV 4:2:2

此致 丹尼尔。

1 个答案:

答案 0 :(得分:0)

您的图像是隔行扫描的,请在此处查看: https://en.wikipedia.org/wiki/Interlaced_video 这意味着获得的图像是由 2 个图像组成的。 也许您收到的是第一个而不是第二个。

更多的是猜测而不是实际答案祝你好运