Reputation: 1096
I have bought LinkSprite JPEG Color Camera and a LPC1768 mbed microcontroller. By "LinkSprite" camera i can take image in jpeg format and according to their provided tutorial i can transfer and see these image on desktop.But i want to process these image in "LPC1768 mbed" micro-controller.For example i want to loop through each row and column of that image to match a color. Can anyone tell me how can i receive the whole image into an 2D-array and then loop through the array to match with a color like red . Another problem when i transfer the image the data looks like. ff d8 ff e0 00 10 ...........40 c6 81 90 b9 aa ee 68 19 ff d9. I know that jpeg image starts with ff d9 and ends with ff d9. But how can i identify a pixel among those values and how can i compare a color whether it match with red color???
Code for camera to take picture and transfer the image byte by byte
int main() {
JPEGCamera camera(p9, p10); // TX, RX
LocalFileSystem local("local"); //save images on mbed
Timer timer;
timer.start();
if(camera.setPictureSize(JPEGCamera::SIZE160x120))
{
myled1 = 1;
wait(2.0);
myled1 = 0;
wait(2.0);
}
for (int i = 1; i < 3; i++) {
if (camera.isReady()) {
char filename[32];
sprintf(filename, "/local/pict%03d.jpg", i);
printf("Picture: %s \n", filename);
if (camera.takePicture(filename)) {
while (camera.isProcessing()) {
camera.processPicture();
}
myled1 = 1; //show successful picture was taken
wait(2.0);
myled1 = 0;
} else {
printf("take picture failed\n");
myled3 = 1; //show picture take failed
wait(2.0);
myled3 = 0;
}
} else {
printf("camera is not ready\n");
myled4 = 1; //show camera is not ready
wait(2.0);
myled4 = 0;
}
}
In JPEGCamera.cpp
bool JPEGCamera::processPicture() {
if (state == PROCESSING) {
bt.printf("\n\nNew Image \n\n");
if (address < imageSize) {
char data[2048];
int size = readData(data, min(sizeof(data), imageSize - address), address);
int ret = fwrite(data, size, 1, fp);
for (int i=0; i<size; i++) bt.printf("%x ",data[i]);
if (ret > 0)
address += size;
if (ret == 0 || address >= imageSize) {
stopPictures();
fclose(fp);
wait(0.1); // ????
state = ret > 0 ? READY : ERROR;
}
}
}
return state == PROCESSING || state == READY;
}
Is there any way that i can store the image bytes in an array at "processPicture" function?? Is there any way that i can simply read the stored image ???
Upvotes: 0
Views: 1017
Reputation: 400109
You're probably not ready to re-implement JPEG decompression/decoding on your own. So you need to find a library, which will build (and fit) in your embedded environment. This can be tricky, as many standard programming libraries are not engineered for embedding.
Here is a discussion thread about JPEG decoding in an embeded context. One point is that handling JPEG images is rather RAM-hungry, and your microcontroller only has 32 KB of RAM. That really isn't a whole lot, consider that a single pixel of a 24-bit image requires 3 bytes.
One option then might be a "streaming" approach, in which you decode e.g. one scanline at a time and never have to store more than (roughly) that, but I'm not sure if it's possible to decode JPEG that way, or if any libraries exist that do that. You need to do more research.
Upvotes: 1