ESP32-CAM Object Tracking

Lightweight embedded computer vision system built on ESP32-CAM using FreeRTOS and custom image processing for object segmentation built to answer: How much CV capability can fit on a $10 microcontroller?

Project start: Dec 30, 2025

Status: Complete — potential future updates

ESP32
Computer Vision
Embedded C
FreeRTOS
Real-Time Processing
WiFi Streaming
ESP32-CAM Object Tracking

Project Overview

This project explores lightweight computer vision on the ESP32-CAM MCU, a platform with severe memory and compute constraints compared to any conventional CV setup. Frames are processed directly on-device using sobel edge detection and binary segmentation, with no offloading to a host machine.

The core question driving the project: could a $10 microcontroller meaningfully detect and track objects in real time? The answer required careful tradeoffs across resolution, algorithm complexity, and RTOS task design.

Computer Vision Overview Diagram

System Architecture

Hardware

ESP32-CAM with OV3660 image sensor. Frames are captured in grayscale QQVGA (160x120) for processing efficiency. PSRAM is used for frame buffering while SRAM handles active processing tasks.

Firmware

FreeRTOS tasks are split between image capture and image processing using queues for inter-task communication. This separation prevents blocking and keeps frame capture consistent regardless of processing load.

Computer Vision Pipeline

The CV pipeline uses a lightweight Sobel-style edge detection kernel optimized for embedded execution, avoiding the floating-point overhead of standard implementations. Edge pixels are thresholded into a binary map which feeds into object segmentation and centroid tracking.

Computer Vision Pipeline Diagram

Real-Time Processing Optimizations

Task Scheduling

Separate CPU cores handle frame acquisition, buffering, and processing using FreeRTOS task pinning, minimizing CPU overload and avoiding pipeline stalls between capture and analysis stages.

Memory Optimization

Grayscale-only, low-resolution image formats reduce per-frame memory footprint significantly. This was critical to keep processing within PSRAM and SRAM constraints while maintaining a usable frame rate.

WiFi Streaming

Recieved 160x120 frame on PC webserver:

Computer Vision Pipeline Diagram

Processed frames are streamed over WiFi to a Python server running on a host PC, using the ESP32's built-in WiFi capabilities. This allowed real-time visual debugging without adding display hardware to the constrained embedded platform. Streaming should be disabled to allow for maximum image processing speed.

Debugging & Challenges

Object Centroid Accuracy

Initial centroid calculations were significantly inaccurate due to gaps in the edge detection output causing fragmented contours. This was resolved after systematic review and parameter tuning of the image processing pipeline.

Edge Detection Sensitivity

Threshold tuning proved difficult due to lighting variation and sensor noise. The issue is minimized in constant-brightness environments but remains an open problem. adaptive thresholding is a planned future improvement.

Performance Summary

Parameter Value
Resolution160 × 120 (QQVGA)
Pixel FormatGrayscale
Processing MethodSobel Edge Detection + Segmentation
RTOSFreeRTOS (dual-core task split)
StreamingWiFi → Python host server

Planned Improvements

  • Connected-component labeling for cleaner object segmentation
  • Bounding box and centroid extraction for multi-object scenes
  • Multi-object tracking with persistent IDs
  • Adaptive thresholding to handle variable lighting
  • Kalman filter or similar motion smoothing

Resources