Helmet Detection
Detect whether workers or riders are wearing helmets or hard-hats in any image. Built for IoT safety-compliance systems, construction site monitoring, and smart surveillance using ESP32-CAM or Raspberry Pi.
100 scans/monthView Docs
Get Started in Minutes
Start sending IoT notifications in just a few simple steps
1
Create Account
Sign up for free, no credit card required
2
Get API Key
Generate your API key from the dashboard
3
Upload Image
POST an image to /api/v1/helmet-detection/detect
4
Get Results
Receive helmet/no-helmet detections with bounding boxes
Try API
Test the Helmet Detection directly from your browser
API Key:
cd_xxxxxxxxxxxxxxxxxxxxSafety Image
Upload Image
Upload an image for analysis. Use a clear, well-lit photo for best results.
Click or drag & drop
JPG, PNG up to 5MB
40%
Min detection confidence
Result
No result yet
Upload an image and run the test to see the annotated output
1#include "esp_camera.h"
2#include <WiFi.h>
3#include <WiFiClientSecure.h>
4
5const char* WIFI_SSID = "YOUR_WIFI_SSID";
6const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
7const char* API_KEY = "YOUR_API_KEY";
8const char* serverName = "www.circuitdigest.cloud";
9const char* serverPath = "/api/v1/helmet-detection/detect";
10const int serverPort = 443;
11
12#define TRIGGER_BTN 13
13#define PWDN_GPIO_NUM 32
14#define RESET_GPIO_NUM -1
15#define XCLK_GPIO_NUM 0
16#define SIOD_GPIO_NUM 26
17#define SIOC_GPIO_NUM 27
18#define Y9_GPIO_NUM 35
19#define Y8_GPIO_NUM 34
20#define Y7_GPIO_NUM 39
21#define Y6_GPIO_NUM 36
22#define Y5_GPIO_NUM 21
23#define Y4_GPIO_NUM 19
24#define Y3_GPIO_NUM 18
25#define Y2_GPIO_NUM 5
26#define VSYNC_GPIO_NUM 25
27#define HREF_GPIO_NUM 23
28#define PCLK_GPIO_NUM 22
29
30WiFiClientSecure client;
31unsigned long lastTrigger = 0;
32
33void initCamera() {
34 camera_config_t cfg = {};
35 cfg.ledc_channel = LEDC_CHANNEL_0; cfg.ledc_timer = LEDC_TIMER_0;
36 cfg.pin_d0 = Y2_GPIO_NUM; cfg.pin_d1 = Y3_GPIO_NUM;
37 cfg.pin_d2 = Y4_GPIO_NUM; cfg.pin_d3 = Y5_GPIO_NUM;
38 cfg.pin_d4 = Y6_GPIO_NUM; cfg.pin_d5 = Y7_GPIO_NUM;
39 cfg.pin_d6 = Y8_GPIO_NUM; cfg.pin_d7 = Y9_GPIO_NUM;
40 cfg.pin_xclk = XCLK_GPIO_NUM; cfg.pin_pclk = PCLK_GPIO_NUM;
41 cfg.pin_vsync = VSYNC_GPIO_NUM; cfg.pin_href = HREF_GPIO_NUM;
42 cfg.pin_sscb_sda = SIOD_GPIO_NUM; cfg.pin_sscb_scl = SIOC_GPIO_NUM;
43 cfg.pin_pwdn = PWDN_GPIO_NUM; cfg.pin_reset = RESET_GPIO_NUM;
44 cfg.xclk_freq_hz = 20000000;
45 cfg.pixel_format = PIXFORMAT_JPEG;
46 cfg.frame_size = FRAMESIZE_VGA;
47 cfg.jpeg_quality = 10;
48 cfg.fb_count = 1;
49
50 if (esp_camera_init(&cfg) != ESP_OK) {
51 Serial.println("Camera init failed!"); while (1) delay(1000);
52 }
53
54 sensor_t* s = esp_camera_sensor_get();
55 s->set_brightness(s, 1);
56 s->set_contrast(s, 2);
57 s->set_saturation(s, 0);
58 s->set_whitebal(s, 1);
59 s->set_exposure_ctrl(s, 1);
60 s->set_gain_ctrl(s, 1);
61 s->set_aec2(s, 1);
62 s->set_ae_level(s, 1);
63 Serial.println("Camera initialized.");
64}
65
66String sendImageToAPI(camera_fb_t* fb) {
67 Serial.println("Connecting to server...");
68 if (!client.connect(serverName, serverPort)) {
69 Serial.println("Connection failed to: " + String(serverName));
70 return "Connection failed";
71 }
72 Serial.println("Connected to server!");
73
74 String boundary = "----ESP32Boundary";
75 String head = "--" + boundary + "
76Content-Disposition: form-data; name="imageFile"; filename="snap.jpg"
77Content-Type: image/jpeg
78
79";
80 String tail = "
81--" + boundary + "--
82";
83 int contentLen = head.length() + fb->len + tail.length();
84
85 client.println("POST " + String(serverPath) + " HTTP/1.1");
86 client.println("Host: " + String(serverName));
87 client.println("X-API-Key: " + String(API_KEY));
88 client.println("Content-Type: multipart/form-data; boundary=" + boundary);
89 client.println("Content-Length: " + String(contentLen));
90 client.println("Connection: close");
91 client.println();
92 client.print(head);
93 client.write(fb->buf, fb->len);
94 client.print(tail);
95
96 Serial.println("Image sent! Waiting for response...");
97 long t = millis();
98 while (!client.available()) {
99 if (millis() - t > 15000) {
100 client.stop();
101 return "Timeout";
102 }
103 }
104
105 String response = "";
106 while (client.available()) response += (char)client.read();
107 client.stop();
108 int j = response.indexOf("
109
110");
111 return (j != -1) ? response.substring(j + 4) : response;
112}
113
114void checkHelmets() {
115 if (WiFi.status() != WL_CONNECTED) {
116 Serial.println("WiFi disconnected! Reconnecting...");
117 WiFi.begin(WIFI_SSID, WIFI_PASS);
118 int tries = 0;
119 while (WiFi.status() != WL_CONNECTED && tries < 20) {
120 delay(500); Serial.print("."); tries++;
121 }
122 if (WiFi.status() != WL_CONNECTED) {
123 Serial.println("WiFi reconnect failed!");
124 return;
125 }
126 Serial.println("WiFi reconnected!");
127 }
128
129 // Warm-up frame
130 camera_fb_t* fb = esp_camera_fb_get();
131 esp_camera_fb_return(fb);
132 delay(200);
133
134 // Real frame
135 fb = esp_camera_fb_get();
136 if (!fb) { Serial.println("Capture failed"); return; }
137 Serial.println("Photo captured! Sending to API...");
138 String result = sendImageToAPI(fb);
139 esp_camera_fb_return(fb);
140 Serial.println("Response: " + result);
141}
142
143void setup() {
144 Serial.begin(115200);
145 pinMode(TRIGGER_BTN, INPUT_PULLUP);
146 initCamera();
147 client.setInsecure();
148 WiFi.begin(WIFI_SSID, WIFI_PASS);
149 Serial.print("Connecting to WiFi");
150 while (!WiFi.isConnected()) { delay(500); Serial.print("."); }
151 Serial.println("
152Connected: " + WiFi.localIP().toString());
153}
154
155void loop() {
156 if (digitalRead(TRIGGER_BTN) == LOW && millis() - lastTrigger > 500) {
157 lastTrigger = millis();
158 Serial.println("Button pressed! Capturing image...");
159 checkHelmets();
160 }
161}Tutorials
Learn how to integrate with step-by-step guides

