How to Capture Images from an ESP32-CAM

You do not need a continuous video stream to experiment with computer vision. A single JPEG captured from a Wi-Fi camera is often enough to check a scene, inspect a prototype or send an image to an AI assistant.

ESP32-CAM with OV5640 sensor and USB base board
Hardware used in the Bench to Field project: ESP32-CAM with an OV5640 camera and USB base board.

Understand the camera endpoints

The Bench to Field firmware exposes three HTTP endpoints. Other firmware may use different paths or ports. In the examples below, replace 192.168.1.200 with the actual camera address.

URLPurpose
http://192.168.1.200/Browser interface
http://192.168.1.200/captureOne JPEG snapshot
http://192.168.1.200:81/streamContinuous MJPEG stream
Client
HTTP GET /capture
ESP32-CAM
Sensor + JPEG
Local file
snapshot.jpg
Snapshot workflow: the client requests one image and saves the returned JPEG.

Capture a JPEG with a browser

Connect your computer or phone to the same trusted Wi-Fi network. Open the capture URL in the address bar. If the firmware is running and reachable, the browser should display a JPEG. Save the image using the browser’s image-save command.

Refresh the URL to request another image. The time shown by a saved filename is not necessarily the exposure time, so use explicit timestamps if you need an experiment log.

Capture from the command line

On Windows PowerShell, use curl.exe explicitly to avoid confusion with aliases in older PowerShell versions:

curl.exe --fail --silent --show-error --max-time 10 -o snapshot.jpg http://192.168.1.200/capture

On Linux or macOS:

curl --fail --silent --show-error --max-time 10 -o snapshot.jpg http://192.168.1.200/capture

The options fail on HTTP errors, display error messages, limit the transfer duration and write the body to a file. A successful command alone does not guarantee the image is valid; open the file to confirm.

Capture with Python

This example uses the standard library, checks the MIME type and verifies the JPEG signature before writing the file. It is a starting point for a local experiment, not production camera software.

from urllib.request import urlopen
from pathlib import Path
from datetime import datetime

url = 'http://192.168.1.200/capture'
with urlopen(url, timeout=10) as response:
    if response.headers.get_content_type() != 'image/jpeg':
        raise ValueError('Expected image/jpeg')
    data = response.read(5_000_001)

if len(data) > 5_000_000:
    raise ValueError('Image too large')
if not (data.startswith(b'\xff\xd8') and data.endswith(b'\xff\xd9')):
    raise ValueError('Invalid or incomplete JPEG')

stamp = datetime.now().strftime('%Y%m%d_%H%M%S_%f')
path = Path(f'capture_{stamp}.jpg')
path.write_bytes(data)
print(path.resolve())

Run this script from a writable folder. The file name includes a timestamp for easy identification. The size limit is an example safeguard and can be adjusted for your configuration.

What to check when a capture fails

  • Timeout: verify the actual IP, network isolation and camera power.
  • HTTP error: check that the firmware supports /capture.
  • Invalid JPEG: check the response type, camera initialization and power stability.
  • Overexposed or blurred image: adjust lighting, focus and camera position.
  • Repeated captures fail: start with one request at a time before introducing parallel access.

Use snapshots when the task does not need motion information. The camera’s HTTP service should remain on a trusted local network; do not expose it directly to the public internet.

References

curl command-line manual · Python urllib.request.

Build the complete project

See Connect a Camera to Your AI for the hardware, firmware and free source package. These examples use the project’s local HTTP endpoints.

Leave a Comment