Hello guys, I’m currently trying to run a image classification in an arduino nano 33 ble sense, the problem is that it works perfectly with the ov7675 example but i don’t know how to make it work reading a set of images from a sd card. The images are in .bmp format and (what I understood) I need a rgb888 raw pixel buffer first, then do the resize and crop (if needed) and then make a callback function returning that buffer for the signal struct to run the inference. The problem is I don’t know how to convert from a BMP buffer to what i need. It is so easy with the esp32-camera library because it has conversions… but with arduino is not as easy
In the Arduino library that you generate from your Edge Impulse project there are a number of examples:
File> Examples>Examples from custom libaries> project_name_camera
will have an example that you can refer to for the streaming and conversion you are looking for:
/**
* @brief Setup image sensor & start streaming
*
* @retval false if initialisation failed
*/
bool ei_camera_init(void) {
if (is_initialised) return true;
if (!Cam.begin(QQVGA, RGB565, 1)) { // VGA downsampled to QQVGA (OV7675)
ei_printf("ERR: Failed to initialize camera\r\n");
return false;
}
is_initialised = true;
return true;
}
/**
* @brief Convert RGB565 raw camera buffer to RGB888
*
* @param[in] offset pixel offset of raw buffer
* @param[in] length number of pixels to convert
* @param[out] out_buf pointer to store output image
*/
int ei_camera_cutout_get_data(size_t offset, size_t length, float *out_ptr) {
size_t pixel_ix = offset * 2;
size_t bytes_left = length;
size_t out_ptr_ix = 0;
// read byte for byte
while (bytes_left != 0) {
// grab the value and convert to r/g/b
uint16_t pixel = (ei_camera_capture_out[pixel_ix] << 8) | ei_camera_capture_out[pixel_ix+1];
uint8_t r, g, b;
r = ((pixel >> 11) & 0x1f) << 3;
g = ((pixel >> 5) & 0x3f) << 2;
b = (pixel & 0x1f) << 3;
// then convert to out_ptr format
float pixel_f = (r << 16) + (g << 8) + b;
out_ptr[out_ptr_ix] = pixel_f;
// and go to the next pixel
out_ptr_ix++;
pixel_ix+=2;
bytes_left--;
}
// and done!
return 0;
}
There are also a number of questions on the Arduino forum regarding this that may help: