espressif / esp-iot-solution

Espressif IoT Library. IoT Device Drivers, Documentations And Solutions.
Apache License 2.0
1.89k stars 757 forks source link

Is there any example to capture a image from USB camera (AEGHB-15) #230

Open minux1010 opened 1 year ago

minux1010 commented 1 year ago

There is example to get the video frame from usb camera on ESP32-S2. Is there any example to get the image only from usb camera? For example, I can trigger the read image from wifi and it can send back one image only.

leeebo commented 1 year ago

@minux1010 Please checkout to usb/add_usb_solutions branch for usb examples, for usb camera please refer https://github.com/espressif/esp-iot-solution/tree/usb/add_usb_solutions/components/usb/uvc_stream

https://github.com/espressif/esp-iot-solution/tree/master/components/usb/usb_stream

dmitrij9992905 commented 1 year ago

@minux1010 do you mean still images? There are no examples regarding to the still images, there is stream initiation only. Due to USB1.1 limitations, we can't get the stream better than 640x480@15fps. But in some cases, we don't need the stream image but we need high-quality still image with the resolution as high as possible from the camera and what fits into PSRAM buffer. I'm struggling with that for weeks, and I'm modifying the uvc_stream library provided by this repo. According to the UVC specs, I can use method 2: suspend the stream, trigger still, process the image, resume the stream. But you need to probe and commit both stream and still by format and frame indexes. For now, I can't get still image better than 640x480 px (for now I'm judging by maxbuffersize got from the camera), but camera is capable to give still images 1280x1024 at frame index corresponding to MJPEG and 1600x1200 at frame index corresponding to uncompressed. Is it possible to remove the limitation on buffer size?

leeebo commented 1 year ago

There are no examples regarding to the still images, there is stream initiation only. A: Hi @dmitrij9992905 for still images capture, have you tried the usb_host_uvc, which is based on libuvc.

I can't get still image better than 640x480 px (for now I'm judging by maxbuffersize got from the camera) A: For the generic purpose driver (like uvc driver on linux), which should get maxbuffersize from the descriptor and then prepare for the same amount of RAM (there is usually enough RAM for linux platforms). And for camera vendors, fixed the maxbuffersize of MJPEG frame size to uncompressed size is the simplest and safest method. so...

for esp32sx platform, internal RAM and PSRAM may not be able to meet the maxbuffersize requirements, But for JEPG in general, it's safe to prepare a buffer with a compression ratio of 15:1.

So, for 1280x1024, I think prepare a 1280x1024x2/15=174,762 Bytes buffer is usually safe

dmitrij9992905 commented 1 year ago

Hi @leeebo have you tried the usb_host_uvc, which is based on libuvc. - yes, I tried, but still triggering makes no sense: stream suspends on some time, than I get striped image with as the SAME size as the stream, not the image size agreed on still. According to the specs, the payload has the bitmap which has the bit that points if the image is a part of still or not, but not considered in this payload in the libuvc. With libuvc I couldn't get the image better than 160x120, if more, it will be striped. As well it got striped after the moment of still triggering. As well, I tried to modify lib from Espressif. I've incorporated still image commiting, then selected frame size which respects the imagesizepattern is needed for me and camera supports, for example, 1280x1024, but I couldn't get the image better than 640x480.

As for buffer, as I need the still image with high resolution, I chose the ESP32S3R8, with 8MB PSRAM, which is sufficient for high resolution uncompressed image. Maxbuffersize to be got from the camera during probe.

j1981 commented 1 year ago

don't waste your time usb_camera_wifi_transfer example thath used uvc_stream doesn't work.After a few transmitted frames it returns W (80191) UVC_STREAM: line 378 HCD_PORT_EVENT_ERROR and the connection to the camera is terminated. After disconnect camera from usb and reconnect it again the result is a same as described above.

dmitrij9992905 commented 1 year ago

With some of cameras yes, it was, it needs to test with different cameras. Now it's needed to improve the cameras compatibility. If you try to use libuvc which uses libusb lib, there are some errors with camera handling. With uvc_stream I managed to connect to embedded USB camera with ultra wide lens with MJPEG support and I could get images

Отправлено из Mail.ru для Android воскресенье, 04 декабря 2022г., 14:05 +03:00 от j1981 @.*** :

don't waste your time usb_camera_wifi_transfer example thath used uvc_stream doesn't work.After a few transmitted frames it returns W (80191) UVC_STREAM: line 378 HCD_PORT_EVENT_ERROR and the connection to the camera is terminated. After disconnect camera from usb and reconnect it again the result is a same as described above. — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you were mentioned. Message ID: @ github . com>