https://github.com/nopnop2002/esp-idf-video-snapshot
Capture still images from a USB camera using ESP-IDF
https://github.com/nopnop2002/esp-idf-video-snapshot
camera esp-idf esp32 still-image usb-camera web-camera
Last synced: 7 months ago
JSON representation
Capture still images from a USB camera using ESP-IDF
- Host: GitHub
- URL: https://github.com/nopnop2002/esp-idf-video-snapshot
- Owner: nopnop2002
- License: mit
- Created: 2022-10-28T23:26:20.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-22T09:00:04.000Z (9 months ago)
- Last Synced: 2025-02-28T19:52:50.822Z (7 months ago)
- Topics: camera, esp-idf, esp32, still-image, usb-camera, web-camera
- Language: C
- Homepage:
- Size: 117 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esp-idf-video-snapshot
Capture still images from a USB camera using ESP-IDF.This example demonstrates how to:
- Capture still images from a USB camera using the USB Host UVC Driver.
__This repository uses components from version 1.0.4.__
https://components.espressif.com/components/espressif/usb_host_uvc
- View still images over WiFi using the built-in HTTP server.
- Post still images over WiFi using MQTT/HTTP.
- Supports plugging and unplugging USB cameras.This example enumerates the attached camera descriptors, negotiates the selected resolution and FPS, and starts capturing video.
I based it on [this](https://github.com/espressif/esp-idf/tree/master/examples/peripherals/usb/host/uvc) official example.
# Hardware Required
## ESP32-S2/ESP32-S3
This example requires any ESP32-S2 or ESP32-S3 with external PSRAM and exposed USB connector attached to USB camera.
ESP module without external PSRAM will fail to initialize.
I used this board.
## Stable power supply
USB cameras consume a lot of electricity.
If the power supplied to the USB port is insufficient, the camera will not operate and ESP32 resets.## USB Type-A Femail connector
USB connectors are available from AliExpress or eBay.
I used it by incorporating it into a Universal PCB.
We can buy this breakout on Ebay or AliExpress.

## USB camera with UVC support
[Here](https://www.freebsd.org/cgi/man.cgi?query=uvc&sektion=4&manpath=freebsd-release-ports) is a list of USB cameras that support UVC that work with FreeBSD.
From what I've researched, ESP-IDF has limited USB support.
For example, the Logitech C615 works with Linux, but not with ESP-IDF.
I tested with these cameras.
- Logitech C270 -> Success
- Logitech C615 -> Fail
- Logitech QuickCam Pro 9000 -> Fail
- PAPALOOK AF925 -> Fail
- Microdia(Very old model) -> Success
- Microdia MSI Starcam Racer -> Success
- Microsoft LifeCam NX6000 -> Fail
- Microsoft LifeCam Cinema -> Success
- Microsoft LifeCam Studio -> Success
- Microsoft LifeCam HD3000 -> Success
- Microsoft LifeCam HD5000 -> Success___It is very hard to find a camera that works with ESP-IDF.___
On [this](https://components.espressif.com/components/espressif/usb_host_uvc) document says that these cameras work with ESP-IDF.
- Logitech C980
- CANYON CNE-CWC2When usb support provided by ESP-IDF is updated, this issue may eliminate the problem.
Detail is [here](https://github.com/nopnop2002/esp-idf-video-streaming/issues).
# Software Required
ESP-IDF V5.0 or later.
ESP-IDF V4.4 release branch reached EOL in July 2024.# Wireing
USB camera connects via USB connector.
The USB port on the ESP32 development board does not function as a USB-HOST.
```
+---------+ +-------------+ +----------+
|ESP BOARD|==|USB CONNECTOR|==|USB CAMERA|
+---------+ +-------------+ +----------+
``````
ESP BOARD USB CONNECTOR (type A)
+--+
5V -------------> | || VCC
[GPIO19] -------------> | || D-
[GPIO20] -------------> | || D+
GND -------------> | || GND
+--+
```
# Installation
```
git clone https://github.com/nopnop2002/esp-idf-video-snapshot
cd esp-idf-video-snapshot
idf.py set-target {esp32s2/esp32s3}
idf.py menuconfig
idf.py flash monitor
```
# Configuration
## Wifi Setting

You can connect using the mDNS hostname instead of the IP address.
You can use static IP.
## Select Snapshot Trigger
You can choose one of the following as trigger.
- Trigger is the Enter key on the keyboard
For operation check
- Trigger is a GPIO toggle
Some GPIOs are used as boot straps and cannot be used as inputs.- Initial Sate is PULLDOWN
The trigger is prepared when it is turned from OFF to ON, and a picture is taken when it is turned from ON to OFF.- Initial Sate is PULLUP
The trigger is prepared when it is turned from ON to OFF, and a picture is taken when it is turned from OFF to ON.
- Trigger is TCP Socket
You can use tcp_send.py as trigger.
`python3 ./tcp_send.py`
- Trigger is UDP Socket
You can use udp_send.py as trigger.
```
python3 -m pip install -U netifaces
python3 ./udp_send.py
```
- Trigger is MQTT Subscribe
You can use mosquitto_pub as trigger.
`mosquitto_pub -h your_broker -p 1883 -t "/take/picture" -m ""`
- Trigger is HTTP Request
You can use this command as trigger.
`curl "http://esp32-camera.local:8080/take/picture"`
## Post Setting
- No post
Still images don't post anywhere.
- Post using HTTP
Still images are posted using HTTP.
You can download the HTTP server from [here](https://github.com/nopnop2002/multipart-upload-server).
Filenames can be timestamped.

- Post using MQTT
Still images are posted using MQTT.
You can download the MQTT broker from [here](https://github.com/nopnop2002/esp-idf-mqtt-broker).
You can use MQTT Subscriber using python.
https://github.com/nopnop2002/esp-idf-video-snapshot/tree/main/python-subscribe
## Camera Setting
Some cameras need to change frame size and frame format.
See [here](https://github.com/nopnop2002/esp-idf-video-streaming/issues).


# How to use
- Build and flash firmware to esp32.
- Connect the USB camera at this timing.
- For available USB cameras, device information will be displayed and video streaming will begin.
- For unavailable USB cameras, you will see an error like this.
- Execute trigger.
# View picture using Built-in WEB Server
You can view the pictures taken using the built-in WEB server.
Enter the ESP32's IP address and port number in the address bar of your browser.
You can use mDNS instead of IP address.
# References
https://github.com/nopnop2002/esp-idf-video-streaming