uvc camera例程无法获取到图像

Moderator: ESP_Bob

esp32_account_0248
Posts: 7
Joined: Fri Jul 02, 2021 2:28 am

uvc camera例程无法获取到图像

Postby esp32_account_0248 » Thu Jan 06, 2022 10:35 am

开发板:esp32s2-Saola-v1.2
开发环境:win10 + IDFv4.4 + esp iot solution
摄像头:USB2.0 uvc免驱支持MJPEG摄像头

我根据摄像头描述符配置了usb_camera_wifi_transfer例程的参数后烧写测试,发现在通讯之后报错没有发送EOF。

运行log
  • I (816) UVC_STREAM: UVC Streaming Config Succeed
    I (866) UVC_STREAM: UVC Streaming Starting
    I (896) UVC_STREAM: Port=1 init succeed
    I (896) UVC_STREAM: Waitting USB Connection
    I (1146) UVC_STREAM: line 353 HCD_PORT_EVENT_CONNECTION
    I (1146) UVC_STREAM: Resetting Port
    I (1206) UVC_STREAM: Setting Port FIFO
    I (1206) UVC_STREAM: Getting Port Speed
    I (1206) UVC_STREAM: Port speed = 1
    I (1206) UVC_STREAM: USB Speed: full-speed
    I (1206) UVC_STREAM: Set Device Addr = 1
    I (1226) UVC_STREAM: Set Device Addr Done
    I (1226) UVC_STREAM: Set Device Configuration = 1
    I (1236) UVC_STREAM: Set Device Configuration Done
    I (1236) UVC_STREAM: SET_CUR Probe
    I (1236) UVC_STREAM: SET_CUR Probe Done
    I (1236) UVC_STREAM: GET_CUR Probe
    bmHint: 0001
    bFormatIndex: 2
    bFrameIndex: 5
    dwFrameInterval: 10000000
    wKeyFrameRate: 0
    wPFrameRate: 0
    wCompQuality: 0
    wCompWindowSize: 0
    wDelay: 0
    dwMaxVideoFrameSize: 614400
    dwMaxPayloadTransferSize: 800
    dwClockFrequency: 0
    bmFramingInfo: 0
    bPreferredVersion: 0
    bMinVersion: 0
    bMaxVersion: 0
    bInterfaceNumber: 0
    I (1276) UVC_STREAM: GET_CUR Probe Done, actual_num_bytes:64
    I (1276) UVC_STREAM: SET_CUR COMMIT
    I (1286) UVC_STREAM: SET_CUR COMMIT Done
    I (1286) UVC_STREAM: Set Device Interface = 1, Alt = 4
    I (1296) UVC_STREAM: Set Device Interface Done
    I (1296) UVC_STREAM: Sample processing task started
    I (1356) UVC_STREAM: Camera Start Streaming
    W (5346) UVC_STREAM: SWAP NO EOF 9412
    W (5846) UVC_STREAM: SWAP NO EOF 9536
    W (6336) UVC_STREAM: SWAP NO EOF 9656
我的配置:
  1.     uvc_config_t uvc_config = {
  2.         .dev_speed = USB_SPEED_FULL, //固定为 USB_SPEED_FULL
  3.         .configuration = 1, //配置描述符编号,一般为 1
  4.         .format_index = 2, // MJPEG 对应的 bFormatIndex, bFormatIndex: 0x02 (2)
  5.         .frame_width = 160, // MJPEG 横向像素,例如 320
  6.         .frame_height = 120, // MJPEG 纵向像素,例如 240
  7.         .frame_index = 5, //MJPEG 320*240 对应的 bFrameIndex, bFrameIndex: 0x05
  8.         .frame_interval = 333333, //可选的帧率 dwFrameInterval,例如 30fps
  9.         .interface = 1, // 可选的视频流接口 bInterfaceNumber,一般为 1
  10.         .interface_alt = 4, // 接口选项 bAlternateSetting, bAlternateSetting: 0x04
  11.         .isoc_ep_addr = 0x82, // 接口选项对应的 bEndpointAddress, bEndpointAddresS: 0x82 (Direction=IN EndpointID=2)
  12.         .isoc_ep_mps = 512, // 接口选项的确定的 MPS, 例如为 512
  13.         .xfer_buffer_size = 20*1024, //单帧图像大小,需要根据实际测试确定,320*240 一般小于 35KB
  14.         .xfer_buffer_a = pointer_buffer_a, // 已经申请的 buffer 指针
  15.         .xfer_buffer_b = pointer_buffer_b, // 已经申请的 buffer 指针
  16.         .frame_buffer_size = 20*1024, //单帧图像大小,需要根据实际测试确定
  17.         .frame_buffer = pointer_frame_buffer, // 已经申请的 buffer 指针
  18.     };
摄像头描述符,我是用win10的软件获取的,比较多
摄像头描述符.txt
(48.12 KiB) Downloaded 812 times
请问可能是什么问题导致的?uvc协议还在学习中不是很明白,是描述符配置的不对还是摄像头本身就不支持?或者说例程需要改动?

esp32_account_0248
Posts: 7
Joined: Fri Jul 02, 2021 2:28 am

Re: uvc camera例程无法获取到图像

Postby esp32_account_0248 » Tue Mar 22, 2022 7:30 am

看到uvc的程序更新了可以打印描述符的功能又做了下尝试,发现新的问题
运行log

Code: Select all

PS S:\Work\ESP\esp-iot-solution\examples\usb\host\usb_camera_wifi_transfer> idf.py monitor
Executing action: monitor
Serial port COM9
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Detecting chip type... ESP32-S2
Running idf_monitor in directory s:\work\esp\esp-iot-solution\examples\usb\host\usb_camera_wifi_transfer
Executing "S:\Work\ESP\TOOLS\python_env\idf4.4_py3.8_env\Scripts\python.exe S:\Work\ESP\IDF4.4\tools/idf_monitor.py -p COM9 -b 115200 --toolchain-prefix xtensa-esp32s2-elf- --target esp32s2 s:\work\esp\esp-iot-solution\examples\usb\host\usb_camera_wifi_transfer\build\uvc_mjpeg_wifi.elf -m 'S:\Work\ESP\TOOLS\python_env\idf4.4_py3.8_env\Scripts\python.exe' 'S:\Work\ESP\IDF4.4\tools\idf.py'"...
�[0;33m--- WARNING: GDB cannot open serial ports accessed as COMx�[0m
�[0;33m--- Using \\.\COM9 instead...�[0m
�[0;33m--- idf_monitor on \\.\COM9 115200 ---�[0m
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x177c
load:0x4004c000,len:0xa48
load:0x40050000,len:0x2e58
entry 0x4004c204
I (21) boot: ESP-IDF v4.4-367-gc29343eb94-dirty 2nd stage bootloader
I (21) boot: compile time 09:10:59
I (21) boot: chip revision: 0
I (26) boot.esp32s2: SPI Speed      : 80MHz
I (30) boot.esp32s2: SPI Mode       : DIO
I (35) boot.esp32s2: SPI Flash Size : 2MB
I (40) boot: Enabling RNG early entropy source...
I (45) boot: Partition Table:
I (49) boot: ## Label            Usage          Type ST Offset   Length
I (56) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (64) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (71) boot:  2 factory          factory app      00 00 00010000 00100000
I (78) boot: End of partition table
I (83) esp_image: segment 0: paddr=00010020 vaddr=3f000020 size=0abd4h ( 43988) map
I (100) esp_image: segment 1: paddr=0001abfc vaddr=3ffbf2f0 size=01d44h (  7492) load
I (102) esp_image: segment 2: paddr=0001c948 vaddr=40024000 size=036d0h ( 14032) load
I (111) esp_image: segment 3: paddr=00020020 vaddr=40080020 size=18a38h (100920) map
I (137) esp_image: segment 4: paddr=00038a60 vaddr=400276d0 size=07c14h ( 31764) load
I (145) esp_image: segment 5: paddr=0004067c vaddr=50000000 size=00010h (    16) load
I (150) boot: Loaded app from partition at offset 0x10000
I (151) boot: Disabling RNG early entropy source...
I (165) cache: Instruction cache        : size 8KB, 4Ways, cache line size 32Byte
I (165) cache: Data cache               : size 8KB, 4Ways, cache line size 32Byte
I (169) spiram: Found 16MBit SPI RAM device
I (174) spiram: SPI RAM mode: sram 40m
I (178) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (185) cpu_start: Pro cpu up.
I (599) spi�ff������f���I�5�memory test OK
D (599) efuse: In EFUSE_BLK2__DATA4_REG is used 3 bits starting with 4 bit
D (608) clk: RTC_SLOW_CLK calibration value: 5702702
I (616) cpu_start: Pro cpu start user code
I (616) cpu_start: cpu freq: 240000000
I (616) cpu_start: Application information:
I (621) cpu_start: Project name:     uvc_mjpeg_wifi
I (626) cpu_start: App version:      14d9f9b-dirty
I (632) cpu_start: Compile time:     Mar 22 2022 14:22:25
I (638) cpu_start: ELF file SHA256:  62cd7214c6e5c367...
I (644) cpu_start: ESP-IDF:          v4.4-367-gc29343eb94-dirty
D (650) memory_layout: Checking 5 reserved memory ranges:
D (656) memory_layout: Reserved memory range 0x3f500000 - 0x3ff80000
D (662) memory_layout: Reserved memory range 0x3ff9e000 - 0x3ff9e000
D (669) memory_layout: Reserved memory range 0x3ffb4000 - 0x3ffbf2e4
D (675) memory_layout: Reserved memory range 0x3ffbf2f0 - 0x3ffc1958
D (682) memory_layout: Reserved memory range 0x3ffffa10 - 0x40000000
D (688) memory_layout: Building list of available memory regions:
D (694) memory_layout: Available memory region 0x3ffc1958 - 0x3ffc4000
D (701) memory_layout: Available memory region 0x3ffc4000 - 0x3ffc8000
D (707) memory_layout: Available memory region 0x3ffc8000 - 0x3ffcc000
D (714) memory_layout: Available memory region 0x3ffcc000 - 0x3ffd0000
D (721) memory_layout: Available memory region 0x3ffd0000 - 0x3ffd4000
D (727) memory_layout: Available memory region 0x3ffd4000 - 0x3ffd8000
D (734) memory_layout: Available memory region 0x3ffd8000 - 0x3ffdc000
D (740) memory_layout: Available memory region 0x3ffdc000 - 0x3ffe0000
D (747) memory_layout: Available memory region 0x3ffe0000 - 0x3ffe4000
D (754) memory_layout: Available memory region 0x3ffe4000 - 0x3ffe8000
D (760) memory_layout: Available memory region 0x3ffe8000 - 0x3ffec000
D (767) memory_layout: Available memory region 0x3ffec000 - 0x3fff0000
D (773) memory_layout: Available memory region 0x3fff0000 - 0x3fff4000
D (780) memory_layout: Available memory region 0x3fff4000 - 0x3fff8000
D (787) memory_layout: Available memory region 0x3fff8000 - 0x3fffc000
D (793) memory_layout: Available memory region 0x3fffc000 - 0x3ffffa10
D (800) memory_layout: Available memory region 0x3ff9e000 - 0x3ffa0000
I (806) heap_init: Initializing. RAM available for dynamic allocation:
D (814) heap_init: New heap initialised at 0x3ffc1958
I (819) heap_init: At 3FFC1958 len 0003A6A8 (233 KiB): DRAM
I (825) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
D (831) heap_init: New heap initialised at 0x3ff9e000
I (836) heap_init: At 3FF9E000 len 00002000 (8 KiB): RTCRAM
I (843) spiram: Adding pool of 2048K of external SPI memory to heap allocator
D (851) FLASH_HAL: extra_dummy: 0
D (854) spi_flash: trying chip: issi
D (857) spi_flash: trying chip: gd
D (861) spi_flash: trying chip: mxic
D (865) spi_flash: trying chip: winbond
D (868) spi_flash: trying chip: boya
D (872) spi_flash: trying chip: th
D (876) spi_flash: trying chip: generic
I (879) spi_flash: detected chip: generic
I (884) spi_flash: flash io: dio
W (888) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
D (901) cpu_start: calling init function: 0x40081388
0x40081388: esp_ota_init_app_elf_sha256 at S:/Work/ESP/IDF4.4/components/app_update/esp_app_desc.c:68

D (906) intr_alloc: Connected src 73 to int 10 (cpu 0)
D (911) intr_alloc: Connected src 28 to int 2 (cpu 0)
I (916) cpu_start: Starting scheduler on PRO CPU.
D (922) heap_init: New heap initialised at 0x3fffc000
I (927) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
D (935) intr_alloc: Connected src 17 to int 3 (cpu 0)
I (940) UVC_STREAM: UVC Streaming Config Succeed
D (946) UVC_STREAM: urb alloced
D (949) UVC_STREAM: urb alloced
D (952) UVC_STREAM: urb alloced
D (955) UVC_STREAM: urb alloced
D (1008) intr_alloc: Connected src 48 to int 19 (cpu 0)
I (1008) UVC_STREAM: UVC Streaming Starting
I (1008) uvc_demo: uvc streaming successed!
I (1038) UVC_STREAM: Port=1 init succeed
I (1038) UVC_STREAM: Waitting USB Connection
I (1288) UVC_STREAM: line 358 HCD_PORT_EVENT_CONNECTION
I (1288) UVC_STREAM: Resetting Port
I (1348) UVC_STREAM: Setting Port FIFO
I (1348) UVC_STREAM: Getting Port Speed
I (1348) UVC_STREAM: Port speed = 1
I (1350) UVC_STREAM: USB Speed: full-speed
D (1355) UVC_STREAM: urb alloced
I (1358) UVC_STREAM: Set Device Addr = 1
D (1373) UVC_STREAM: Got expected pipe_handle and event
I (1373) UVC_STREAM: Set Device Addr Done
D (1373) UVC_STREAM: urb free
D (1375) UVC_STREAM: urb alloced
I (1379) UVC_STREAM: get short config desc
D (1391) UVC_STREAM: Got expected pipe_handle and event
I (1391) UVC_STREAM: get config desc, actual_num_bytes:16
I (1395) UVC_STREAM: get full config desc
D (1421) UVC_STREAM: Got expected pipe_handle and event
I (1421) UVC_STREAM: get full config desc, actual_num_bytes:459
*** Configuration descriptor ***
bLength 9
bDescriptorType 2
wTotalLength 451
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
bMaxPower 500mA
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 0
        bAlternateSetting 0
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
        bcdUVC 100
        *** Extension Unit Descriptor unsupported, skipping... ***
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x81   EP 1 IN
                bmAttributes 0x3        INT
                wMaxPacketSize 16
                bInterval 8
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 0
        bNumEndpoints 0
        bInterfaceClass 0x0
        iInterface 4
        *** Class-specific VS Interface Descriptor ***
        bNumFormats 2
        *** VS Format MJPEG Descriptor ***
        bFormatIndex 0x1
        bDefaultFrameIndex 1
        *** VS MJPEG Frame Descriptor ***
        bFrameIndex 0x1
        wWidth 320
        wHeigh 240
        dwMaxVideoFrameBufSize 230400
        FrameInterval[0] 500000
        *** VS MJPEG Frame Descriptor ***
        bFrameIndex 0x2
        wWidth 176
        wHeigh 144
        dwMaxVideoFrameBufSize 76032
        FrameInterval[0] 500000
        *** VS MJPEG Frame Descriptor ***
        bFrameIndex 0x3
        wWidth 160
        wHeigh 120
        dwMaxVideoFrameBufSize 57600
        FrameInterval[0] 500000
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 1
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x5        ISOC
                wMaxPacketSize 800
                bInterval 1
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 2
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x5        ISOC
                wMaxPacketSize 700
                bInterval 1
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 3
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x5        ISOC
                wMaxPacketSize 512
                bInterval 1
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 4
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x5        ISOC
                wMaxPacketSize 192
                bInterval 1
D (1645) UVC_STREAM: urb free
D (1648) UVC_STREAM: urb alloced
I (1651) UVC_STREAM: Set Device Configuration = 1
D (1657) UVC_STREAM: Got expected pipe_handle and event
I (1662) UVC_STREAM: Set Device Configuration Done
D (1667) UVC_STREAM: urb free
D (1670) UVC_STREAM: urb alloced
I (1674) UVC_STREAM: SET_CUR Probe
D (1679) UVC_STREAM: Got expected pipe_handle and event
I (1683) UVC_STREAM: SET_CUR Probe Done
I (1688) UVC_STREAM: GET_CUR Probe
D (1693) UVC_STREAM: Got expected pipe_handle and event
bmHint: 0001
bFormatIndex: 1
bFrameIndex: 3
dwFrameInterval: 500000
wKeyFrameRate: 0
wPFrameRate: 0
wCompQuality: 0
wCompWindowSize: 0
wDelay: 0
dwMaxVideoFrameSize: 57600
dwMaxPayloadTransferSize: 800
dwClockFrequency: 0
bmFramingInfo: 0
bPreferredVersion: 0
bMinVersion: 0
bMaxVersion: 0
bInterfaceNumber: 0
I (1725) UVC_STREAM: GET_CUR Probe Done, actual_num_bytes:34
I (1732) UVC_STREAM: SET_CUR COMMIT
D (1737) UVC_STREAM: Got expected pipe_handle and event
I (1741) UVC_STREAM: SET_CUR COMMIT Done
D (1746) UVC_STREAM: urb free
D (1749) UVC_STREAM: urb alloced
I (1752) UVC_STREAM: Set Device Interface = 1, Alt = 4
D (1758) UVC_STREAM: Got expected pipe_handle and event
I (1763) UVC_STREAM: Set Device Interface Done
D (1768) UVC_STREAM: urb free
I (1771) UVC_STREAM: Sample processing task started
I (1827) UVC_STREAM: Camera Start Streaming
D (1827) UVC_STREAM: urb context update
D (1827) UVC_STREAM: urb context update
D (1828) UVC_STREAM: urb context update
D (1832) UVC_STREAM: urb context update
W (2622) UVC_STREAM: line 677 Pipe: iso HCD_PIPE_EVENT_ERROR_OVERFLOW
uvc描述符配置

Code: Select all

#define DESCRIPTOR_CONFIGURATION_INDEX 0x01
#define DESCRIPTOR_FORMAT_MJPEG_INDEX  0x01
#define DEMO_FRAME_INDEX 0x03
#define DEMO_FRAME_WIDTH 160
#define DEMO_FRAME_HEIGHT 120
#define DEMO_FRAME_INTERVAL 500000
#define DEMO_XFER_BUFFER_SIZE (20 * 1024) 
#define DESCRIPTOR_STREAM_INTERFACE_INDEX   0x01
#define DESCRIPTOR_STREAM_ISOC_ENDPOINT_ADDR  0x82
#define DEMO_ISOC_INTERFACE_ALT 0x04
#define DEMO_ISOC_EP_MPS 192
运行报错HCD_PIPE_EVENT_ERROR_OVERFLOW,是因为MPS>512,但是我是按描述符配置的ALT=4 MPS=192,请问该如何配置MPS的大小?

ESP_Bob
Posts: 80
Joined: Fri Nov 27, 2020 12:52 pm

Re: uvc camera例程无法获取到图像

Postby ESP_Bob » Sat May 07, 2022 1:32 pm

从 ESP32S2 打印的描述符可以获取到以下信息:
1. MPS=512 对应的接口 interface_alt 为 3, 端点地址为 0x82
2. MJPEG 对应的 format_index 为 1
3. 160*120 对应的 frame_index 为 3,320*240 分辨率对应的 frame_index 为 1

请根据以上信息修改 uvc_config, Good Luck :D

Who is online

Users browsing this forum: No registered users and 64 guests