Image processing using GR Kaede

The below code is an example available in the web compiler. The image library does not seem to work as expected. If anyone tried running the below code, please help how to capture image using the board and camera.

#include <Arduino.h>
#include "Image.h"
#include "SD.h"
#include "RTC.h"

Image image[3];
RTC_TIMETYPE t;
void dateTime(uint16_t* date, uint16_t* time);

void setup(){
Serial.begin(9600);
while(!Serial.available()); // wait to press key
Serial.read(); //dummy
Serial.println("start");

pinMode(SS, OUTPUT);
if(!SD.begin(SS)){
Serial.println("Card failed, or not present.");
} else {
Serial.println("Success to access SD.");
}

rtc_init();
t.year = 15;
t.mon = 9;
t.day = 2;
t.weekday = RTC_WEEK_WEDNESDAY;
t.hour = 17;
t.min = 0;
t.second = 0;
rtc_set_time(&t);


for(int i = 0; i < 2; i++){
image[i].begin();
}

SdFile::dateTimeCallback( &dateTime );

}

void loop(){

static int cnt = 0;

for(int i = 0; i < 3; i++){
Serial.print("Capturing image");
Serial.println();
image[i].captureStart();
while(!image[i].isCaptureFinished());
image[i].createGrayImage();
}
if( 0 == image[2].movingDetection(image[0].getCreatedGrayImage(), image[1].getCreatedGrayImage())){
Serial.println("finish detection");
Serial.print("Moving Number is:");
Serial.println(image[2].getMovingNumber());
Serial.print("The biggest moving is in area:");
Serial.println(image[2].getMovingArea(0));
}
image[2].createJpg();

Serial.println("Write jpg to SD:");

char fn[50];
cnt++;
sprintf (fn, "test%d.jpg", cnt);
File file = SD.open(fn, FILE_WRITE);
uint8_t* adr = image[2].getCreatedJpg();
int32_t size = image[2].getCreatedJpgSize();
for (int i = 0; i < size; i++){
file.write(*adr);
adr++;
}
file.close();

Serial.println("Done.");
}

void dateTime(uint16_t* date, uint16_t* time)
{
rtc_get_time(&t);

*date = FAT_DATE(t.year+2000, t.mon, t.day);
*time = FAT_TIME(t.hour, t.min, t.second);
}

  • In reply to Yuvaraj:

    The file format must be binary. Plz check.

  • In reply to Shrenik:

    Hi, I'm sorry bother you, but version E1.11 has a problem about SD that CS pin doesn't work. It seems not to be related with your problem, but please use latest V1.13.

  • In reply to Yuvaraj:

    Great! its working fine! It will be good if I could get a technical document on API's being used in the libraries of various I/Os and memories? Please share the link if any of you have come across API reference manual(s)?