Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Imagemagick 从命令行将YUY2(YUYV)转换为png_Imagemagick_Imagemagick Convert - Fatal编程技术网

Imagemagick 从命令行将YUY2(YUYV)转换为png

Imagemagick 从命令行将YUY2(YUYV)转换为png,imagemagick,imagemagick-convert,Imagemagick,Imagemagick Convert,我正在使用v4l2-ctl(1)从我的网络摄像头捕获图像,并尝试将(1)原始格式转换为png 以下是我运行的命令 # This is the format my camera outputs. $ v4l2-ctl --device /dev/video0 --list-formats-ext ioctl: VIDIOC_ENUM_FMT Type: Video Capture [1]: 'YUYV' (YUYV 4:2:2) S

我正在使用
v4l2-ctl(1)
从我的网络摄像头捕获图像,并尝试
将(1)
原始格式转换为png

以下是我运行的命令

# This is the format my camera outputs.
$ v4l2-ctl --device /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
        Type: Video Capture

        [1]: 'YUYV' (YUYV 4:2:2)
                Size: Discrete 640x480
                        Interval: Discrete 0.033s (30.000 fps)

# This is how I'm capturing an image.
$ v4l2-ctl --device /dev/video0 --set-fmt-video=width=640,height=480,pixelformat=YUYV
$ v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=frame.raw --stream-count=1

# This is how I tried to convert. (This didn't work.)
$ convert -size 640x480 -depth 8 -sampling-factor 4:2:2 -colorspace YUV yuv:frame.raw frame.png
这给了我一个绿色和粉红色的png

我还尝试用这个命令显示原始图像

$ display -size 640x480 -depth 8 -sampling-factor 4:2:2 -colorspace yuv yuv:frame.raw
那里的图像看起来更好一些,但是整个图像上有一个蓝色的滤镜

这是我的网络摄像头的一个示例图像。

我想我已经找到了解决方案,但是正确颜色的参考图像会有所帮助。最简单的方法似乎是使用
ffmpeg
将采样因子为4:2:2的原始YUYV转换为PNG,如下所示:

ffmpeg -f rawvideo -s 640x480 -pix_fmt yuyv422 -i frame.raw result.png
如果要使用ImageMagick,需要使用它的
uyvy
像素格式,但字节是交换的,因此需要在输入它们之前将它们交换到ImageMagick期望的顺序-我在这里使用
dd
及其
conv=swab
选项:

dd if=frame.raw conv=swab | convert -sampling-factor 4:2:2 -size 640x480 -depth 8 uyvy:- result.png

如果您需要以其他更复杂的方式交换和重新排序字节,可以使用
xxd
awk
非常简单:

xxd -c2 frame.raw  | awk '{print $1,substr($2,3,2),substr($2,1,2)}' | xxd -c2 -r - | convert -sampling-factor 4:2:2 -size 640x480 -depth 8 uyvy:- result.png

关键词:ImageMagick,图像处理,命令行,子采样,4:2:2,YUYV,YUY2,YUV

您可以共享YUYV文件吗。。。投递箱?谷歌硬盘?当然可以。我用下载URL更新了帖子。我的回答解决了你的问题吗?如果是这样,请考虑接受它作为您的答案-点击空心蜱/支票旁边的选票计数。如果没有,请说出什么不起作用,以便我或其他人可以进一步帮助您。谢谢