Smart Camera ESP32
An AI-driven, real-time Sentry Turret platform leveraging asynchronous I/O and computer vision to deliver high-precision autonomous motion tracking on resource-constrained embedded hardware.
Loading...
Searching...
No Matches
camera.h
1
9#pragma once
10
11#include "esp_camera.h"
12
18namespace WroverPins
19{
21#define PWDN_GPIO_NUM -1
23#define RESET_GPIO_NUM -1
25#define XCLK_GPIO_NUM 21
27#define SIOD_GPIO_NUM 26
29#define SIOC_GPIO_NUM 27
30
31/* Parallel Data Bus (Y2-Y9) */
32#define Y9_GPIO_NUM 35
33#define Y8_GPIO_NUM 34
34#define Y7_GPIO_NUM 39
35#define Y6_GPIO_NUM 36
36#define Y5_GPIO_NUM 19
37#define Y4_GPIO_NUM 18
38#define Y3_GPIO_NUM 5
39#define Y2_GPIO_NUM 4
40
42#define VSYNC_GPIO_NUM 25
44#define HREF_GPIO_NUM 23
46#define PCLK_GPIO_NUM 22
47} // namespace WroverPins
48
49typedef struct {
50 void* buffer;
51 size_t length;
52 size_t width;
53 size_t height;
55
62class Camera
63{
64private:
65 camera_config_t _config;
66 camera_buffer_t _buffer;
67
68public:
81 Camera() : _buffer()
82 {
83 this->_config.ledc_channel = LEDC_CHANNEL_0;
84 this->_config.ledc_timer = LEDC_TIMER_0;
85 this->_config.pin_d0 = Y2_GPIO_NUM;
86 this->_config.pin_d1 = Y3_GPIO_NUM;
87 this->_config.pin_d2 = Y4_GPIO_NUM;
88 this->_config.pin_d3 = Y5_GPIO_NUM;
89 this->_config.pin_d4 = Y6_GPIO_NUM;
90 this->_config.pin_d5 = Y7_GPIO_NUM;
91 this->_config.pin_d6 = Y8_GPIO_NUM;
92 this->_config.pin_d7 = Y9_GPIO_NUM;
93 this->_config.pin_xclk = XCLK_GPIO_NUM;
94 this->_config.pin_pclk = PCLK_GPIO_NUM;
95 this->_config.pin_vsync = VSYNC_GPIO_NUM;
96 this->_config.pin_href = HREF_GPIO_NUM;
97 this->_config.pin_sccb_sda = SIOD_GPIO_NUM;
98 this->_config.pin_sccb_scl = SIOC_GPIO_NUM;
99 this->_config.pin_pwdn = PWDN_GPIO_NUM;
100 this->_config.pin_reset = RESET_GPIO_NUM;
101
102 this->_config.xclk_freq_hz = 20000000; // 20MHz: Balance between speed and signal noise
103 this->_config.pixel_format = PIXFORMAT_JPEG; // Required for MJPEG streaming
104 this->_config.frame_size = FRAMESIZE_QVGA; // 320x240
105 this->_config.jpeg_quality = 12; // 0-63 (lower is higher quality, 12 is optimal for Sentry)
106 this->_config.fb_count = 2; // Double buffering in PSRAM
107 this->_config.fb_location = CAMERA_FB_IN_PSRAM;
108 this->_config.grab_mode = CAMERA_GRAB_LATEST;
109 }
110
111 ~Camera()
112 {
113 if (this->_buffer.buffer != NULL)
114 {
115 free(this->_buffer.buffer);
116 }
117 }
118
124 bool begin();
139 void capture();
142 const camera_buffer_t& get_frame_buffer() { return this->_buffer; }
143};
Singleton-style manager for camera lifecycle and frame acquisition.
Definition camera.h:63
Camera()
Constructor: Pre-configures the sensor for optimal CV performance.
Definition camera.h:81
void capture()
Synchronously captures a frame from the sensor.
Definition camera.cpp:55
bool begin()
Initializes the hardware and mounts the sensor.
Definition camera.cpp:8
GPIO mapping specifically for the ESP32-Wrover-kit.
Definition camera.h:49