Arduino
Arduino copied to clipboard
Still looking for the correct 160x120 (QQVGA) bitmap configuration for ArduCAM mini 2MP plus
Use case: Machine Learning on small MCU without enough memory to hold a QVGA bitmap and also the input layer of model only accept small data to keep model size fit for MCU.
I was able to modify code found on the ArduCAM_Mini_2MP_Plus_VideoStreaming.ino example sketch to capture a 160x120 BMP image, and write the image to file using ArduCAM_Host_V2. I used an OV2640_MINI_2MP_PLUS with a NodeMCU (ESP8266). You'll need to make the following modifications to Arducam library files and sketch as follows:
-
In the ov2640_regs.h library registry file, make a copy of the struct sensor_reg OV2640_QVGA[] definition, and rename it OV2640_QQVGA. In the copy, change the hex pairs from {0x5a, 0x50} to {0x5a, 0x28}, and {0x5b, 0x3c} to {0x5b, 0x1e}. These decrease pixel resolution by 50%.
-
In the ArduCAM.cpp library file, replace wrSensorRegs8_8(OV2640_QVGA) with wrSensorRegs8_8(OV2640_QQVGA).
-
In the sketch, replace the bitmap header definition with: const char bmp_header[BMPIMAGEOFFSET] PROGMEM = { 0x42, 0x4D, 0x36, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00 }; This header is specific to a 160x120 image height, width, image size, and file size.
-
Again in the sketch, find the nested loop where the image is transferred to serial, and reduce the i and j loop size from 240 and 320, to 120 and 160, respectively.
Note these modifications 'hard-code' 160x120 as the default BMP resolution for demonstration purposes only. Additional coding would be necessary to change resolution similar to JPEG in the demos and ArduCAM_Host_V2 viewer. Also note the 160x120 BMP image are still inverted, but this seems to be by design.
To modify this sketch for an ESP8266, I had to change the SPI slave select pin (CS) from 7 to 16, then insert several yield() commands. Their code locations were found from the ArduCAM_REVC_Video_Streaming.ino example sketch.
Let me know if this works.