Linux上使用USB摄像头取的Jpg图片为何不能正常显示?

Viewed 48

重现步骤
参考以下URL连接了USB摄像头
https://developer.canaan-creative.com/k230/zh/dev/02_applications/tutorials/K230_Opencv%E8%B0%83%E7%94%A8UVC%E6%8C%87%E5%8D%97.html#linuxuvc
使用命令确认时可以正常输出
v4l2-ctl -d /dev/video0 --all

但使用v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=video0-output.jpg --stream-count=1命令采集到的Jpg图片和./video_cap 采集到的Jpg图片为何在Windows都看不了?会出格式不认识的错误?

期待结果和实际结果

希望能正常看到Jpg图片的内容

软硬件版本信息

开发板:01Studio CanMV K230
镜像:按照以下URL的说明编译生成
https://developer.canaan-creative.com/k230/zh/dev/02_applications/tutorials/K230_Opencv%E8%B0%83%E7%94%A8UVC%E6%8C%87%E5%8D%97.html#linuxuvc

错误日志

尝试解决过程

怀疑是YUV422格式,试过几个YUV图片工具,但还是没有正常显示

补充材料

v4l2-ctl -d /dev/video0 --all的输出内容:

[root@canaan ~ ]#v4l2-ctl -d /dev/video0 --all
Driver Info:
        Driver name      : uvcvideo
        Card type        : HD Pro Webcam C920
        Bus info         : usb-91540000.usb-otg-1
        Driver version   : 5.10.4
        Capabilities     : 0x84a00001
                Video Capture
                Metadata Capture
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps      : 0x04200001
                Video Capture
                Streaming
                Extended Pix Format
Media Driver Info:
        Driver name      : uvcvideo
        Model            : HD Pro Webcam C920
        Serial           : 52ED81DF
        Bus info         : usb-91540000.usb-otg-1
        Media version    : 5.10.4
        Hardware revision: 0x00000011 (17)
        Driver version   : 5.10.4
Interface Info:
        ID               : 0x03000002
        Type             : V4L Video
Entity Info:
        ID               : 0x00000001 (1)
        Name             : HD Pro Webcam C920
        Function         : V4L2 I/O
        Flags         : default
        Pad 0x01000007   : 0: Sink
          Link 0x0200001f: from remote pad 0x100000a of entity 'Processing 3': Data, Enabled, Immutable
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
        Width/Height      : 640/480
        Pixel Format      : 'YUYV' (YUYV 4:2:2)
        Field             : None
        Bytes per Line    : 1280
        Size Image        : 614400
        Colorspace        : sRGB
        Transfer Function : Rec. 709
        YCbCr/HSV Encoding: ITU-R 601
        Quantization      : Default (maps to Limited Range)
        Flags             :
Crop Capability Video Capture:
        Bounds      : Left 0, Top 0, Width 640, Height 480
        Default     : Left 0, Top 0, Width 640, Height 480
        Pixel Aspect: 1/1
Selection Video Capture: crop_default, Left 0, Top 0, Width 640, Height 480, Flags:
Selection Video Capture: crop_bounds, Left 0, Top 0, Width 640, Height 480, Flags:
Streaming Parameters Video Capture:
        Capabilities     : timeperframe
        Frames per second: 30.000 (30/1)
        Read buffers     : 0
                     brightness 0x00980900 (int)    : min=0 max=255 step=1 default=-8193 value=128
                       contrast 0x00980901 (int)    : min=0 max=255 step=1 default=57343 value=128
                     saturation 0x00980902 (int)    : min=0 max=255 step=1 default=57343 value=128
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                           gain 0x00980913 (int)    : min=0 max=255 step=1 default=57343 value=22
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=2 value=2
                                0: Disabled
                                1: 50 Hz
                                2: 60 Hz
      white_balance_temperature 0x0098091a (int)    : min=2000 max=6500 step=1 default=57343 value=4763 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=255 step=1 default=57343 value=128
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=57343 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=0 value=3
                                1: Manual Mode
                                3: Aperture Priority Mode
              exposure_absolute 0x009a0902 (int)    : min=3 max=2047 step=1 default=250 value=333 flags=inactive
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=1
                   pan_absolute 0x009a0908 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                  tilt_absolute 0x009a0909 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                 focus_absolute 0x009a090a (int)    : min=0 max=250 step=5 default=8189 value=0 flags=inactive
                     focus_auto 0x009a090c (bool)   : default=1 value=1
                  zoom_absolute 0x009a090d (int)    : min=100 max=500 step=1 default=57343 value=100
[root@canaan ~ ]#

v4l2-ctl取得的图片:
似乎图片格式认识不了,无法上传
.video_cap取得的图片:

1 Answers

使用以下命令,指定Pixel Format : 'MJPG' (Motion-JPEG)后,
.video_cap取得的图片可以正常显示

[root@canaan ~ ]#v4l2-ctl --device /dev/video0 --try-fmt-video width=640,height=
480,pixelformat=2
[   36.121941] usb 2-1: reset high-speed USB device number 2 using dwc2
Format Video Capture:
        Width/Height      : 640/480
        Pixel Format      : 'MJPG' (Motion-JPEG)
        Field             : None
        Bytes per Line    : 0
        Size Image        : 614400
        Colorspace        : sRGB
        Transfer Function : Rec. 709
        YCbCr/HSV Encoding: ITU-R 601
        Quantization      : Default (maps to Full Range)
        Flags             :
[root@canaan ~ ]#v

可以正常显示如下:

但v4l2-ctl --device /dev/video1 --stream-mmap --stream-to=video0-output.jpg --stream-count=1取到的图片还是会出以下错误,这个命令还需要其他的参数设定吗?

image.png