I am fairly new to the Arduino - I am using an Arduino Leonardo. I am using the Adafruit VC0706 Camera to take a picture, and my goal is to read the image data and directly convert it into information about pixel values. Here is my code:
#include <Adafruit_VC0706.h>
Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);
void setup() {
//set up pins
pinMode(9,INPUT);
// Boot up the camera
cam.begin();
//Select picture size
cam.setImageSize(VC0706_160x120);
//Start the serial ports
Serial1.begin(38400);
Serial.begin(38400);
}
void loop()
{
//Enable reading of the serial ports
while (Serial.available())
Serial1.write(Serial.read());
while (Serial1.available())
Serial.write(Serial1.read());
//If a button is pressed, take a picture and read it
if (digitalRead(9) == HIGH)
{;
if (!cam.takePicture())
{
Serial.println("Failed to take picture");
}
else
{
Serial.println("Picture taken");
uint32_t jpglen = cam.frameLength();
Serial.print("This is a ");
Serial.print(jpglen, DEC);
Serial.println(" byte image.");
// Read all the data up to # bytes!
int wCount = 0; // For counting # of writes
while (jpglen > 0) {
// read 32 bytes at a time;
uint8_t *buffer;
uint8_t bytesToRead = min((uint32_t)32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
buffer = cam.readPicture(bytesToRead);
for (uint8_t i = 0; i < bytesToRead; i++)
{
Serial.print(wCount);
Serial.print("th byte: ");
Serial.println(buffer[i]);
wCount++;
}
jpglen -= bytesToRead;
}
Serial.println("Done reading image");
}
delay(500);
}
}
Essentially, I would like to take the image data from "buffer" and convert it into pixel data. Since I do not have an SD Card reader at the moment, I want to see if I can do this without any extra hardware. Does anyone know if there is a library I can use to perform this function?
There are many libraries to convert image types, but I doubt that .jpg encoding can be converted in the extremely limited SRAM of the Arduino Leonardo.
The ESP32 would be a much better choice, especially the ESP32-CAM which has a built in camera. The image frame buffer is directly available, if the camera is set up properly, so no conversion is needed.
When you say the image frame buffer is already available, meaning no conversion is required, does that mean that there is some "simple" function I can use to extract the rgb pixel data from the image frame buffer? Or would it just be easier to buy an ESP32/ SD card?
When using the ESP32-CAM, you can program the camera to take an image and store it in memory (in the frame buffer) in several forms, either encoded or compressed in several ways, or as raw pixel values.
Each byte of the image is directly accessible to the program capturing the image.
I see, you are referring to the ESP32-CAM instead of the Arduino.
Before I go out and buy new hardware, I want to be absolutely sure of what I can do with the technology I already have. I am assuming that if I buy an SD Card for the Arduino (which can store the jpg images from the VC0706), if I read that image from the Arduino IDE, it will return pixel values?
In addition, since I have an Arduino Uno as well, is it recommended that I use the Uno instead of the Leonardo?
There is a lot of versions around on the internet. I found this one on digikey, which can apparently be programmed with the Arduino IDE, if I'm not mistaken. Would this one work the best?