Hai,
thanks for the response. im using esp 32 wrover b development board connected to ov 2640 camera . and the following is my code that i uploaded in ardunio ide #include <WiFi.h>
#include “esp_camera.h”
#include <Emergency_Vehicle_detection_inferencing.h> // Edge Impulse model header
// — OV2640 CAMERA PINS FOR ESP32-WROVER-B —
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
#define Y2_GPIO_NUM 5
#define Y3_GPIO_NUM 18
#define Y4_GPIO_NUM 19
#define Y5_GPIO_NUM 21
#define Y6_GPIO_NUM 36
#define Y7_GPIO_NUM 39
#define Y8_GPIO_NUM 34
#define Y9_GPIO_NUM 35
camera_fb_t *fb = NULL;
uint8_t *resized_image = NULL;
// Convert RGB565 to Grayscale and resize
bool convert_rgb565_to_grayscale(camera_fb_t *fb, uint8_t *out_buf) {
if (!fb || fb->format != PIXFORMAT_RGB565) return false;
uint32_t in_w = fb->width;
uint32_t in_h = fb->height;
uint32_t out_w = EI_CLASSIFIER_INPUT_WIDTH;
uint32_t out_h = EI_CLASSIFIER_INPUT_HEIGHT;
for (uint32_t y = 0; y < out_h; y++) {
for (uint32_t x = 0; x < out_w; x++) {
uint32_t src_x = x * in_w / out_w;
uint32_t src_y = y * in_h / out_h;
uint32_t src_index = (src_y * in_w + src_x) * 2;
uint8_t byte1 = fb->buf[src_index];
uint8_t byte2 = fb->buf[src_index + 1];
uint16_t pixel = (byte2 << 8) | byte1;
uint8_t r = ((pixel >> 11) & 0x1F) << 3;
uint8_t g = ((pixel >> 5) & 0x3F) << 2;
uint8_t b = (pixel & 0x1F) << 3;
uint8_t gray = (uint8_t)(0.299f * r + 0.587f * g + 0.114f * b);
out_buf[y * out_w + x] = gray;
}
}
return true;
}
int get_signal_data(size_t offset, size_t length, float *out_ptr) {
for (size_t i = 0; i < length; i++) {
out_ptr[i] = resized_image[offset + i] / 255.0f;
}
return 0;
}
void setupCamera() {
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_RGB565;
config.frame_size = FRAMESIZE_QVGA; // 320x240
config.fb_location = CAMERA_FB_IN_PSRAM;
config.jpeg_quality = 12;
config.fb_count = 1;
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; // Helps prevent initialization issues
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf(“Camera init failed with error 0x%x\n”, err);
while (true);
}
}
void setup() {
Serial.begin(115200);
delay(1000);
setupCamera();
resized_image = (uint8_t *)malloc(EI_CLASSIFIER_INPUT_WIDTH * EI_CLASSIFIER_INPUT_HEIGHT);
if (!resized_image) {
Serial.println(“Memory allocation failed for resized image”);
while (true);
}
Serial.println(“Camera and model initialized. Point the camera at emergency vehicles.”);
}
void loop() {
fb = esp_camera_fb_get();
if (!fb) {
Serial.println(“Camera capture failed”);
delay(1000);
return;
}
if (!convert_rgb565_to_grayscale(fb, resized_image)) {
Serial.println(“Image format conversion failed”);
esp_camera_fb_return(fb);
delay(1000);
return;
}
esp_camera_fb_return(fb);
ei::signal_t signal;
signal.total_length = EI_CLASSIFIER_INPUT_WIDTH * EI_CLASSIFIER_INPUT_HEIGHT;
signal.get_data = &get_signal_data;
ei_impulse_result_t result = { 0 };
EI_IMPULSE_ERROR res = run_classifier(&signal, &result, false);
if (res != EI_IMPULSE_OK) {
Serial.println(“Inference failed”);
delay(1000);
return;
}
Serial.println(“Predictions:”);
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
Serial.print(" “);
Serial.print(result.classification[ix].label);
Serial.print(”: ");
Serial.println(result.classification[ix].value, 3);
}
delay(1000);
} and this is what the output i got
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4980
load:0x40078000,len:16612
load:0x40080400,len:3480
entry 0x400805b4
E (1060) camera: Detected camera not supported.
E (1060) camera: Camera probe failed with error 0x106(ESP_ERR_NOT_SUPPORTED)
Camera init failed with error 0x106.
and this is what the output i got in serial monitor