Python 转换YUYV 4:2:2,什么';怎么了?

Python 转换YUYV 4:2:2,什么';怎么了?,python,image,v4l2,Python,Image,V4l2,我用v4l2在我的树莓皮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

我用v4l2在我的树莓皮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()
我得到的结果看起来有点奇怪:

有人知道问题出在哪里吗?

此外,这里是我用来捕获原始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
问候,,
丹尼尔。

您的图像是隔行扫描的,请在这里查看: 这意味着获得的图像是两幅图像的合成。 也许你收到的是第一个,而不是第二个


这与其说是一个实际答案,不如说是一个猜测祝你好运

你的图像是交错的,请看这里: 这意味着获得的图像是两幅图像的合成。 也许你收到的是第一个,而不是第二个


这更多的是猜测而不是实际答案祝你好运你最终找到答案了吗?你最终找到答案了吗?如果你不确定你的答案,请留下评论。如果你不确定你的答案,请留下评论。