Image Processing

This library is to capture an image from CMOS camera OV7740, create a JPEG file, detect a moving and detect a human with option boards for GR-KAEDE. Specify #include <image.h> for use.

Image()

Description Constructor for processing an image.
Syntax Image image
Parameters None
Returns None

begin

Description Initiarizing a camera module and SDRAM.
Syntax image.begin()
Parameters None
Returns None
Note In case to create multiple instance, it is necessary only once to call.

captureStart

Description Taking a photo and capturing from a camera. Use isCaptureFinished() to confirm to finish the capturing.
Syntax image.captureStart()
Parameters None
Returns None

isCaptureFinished

Description Retun if the capturing is finished.
Syntax image.isCaptureFinished()
Parameters None
Returns true: finished to capture. false: busy to capture.

createRgb565

Description Create a RGB565 320x240 format data from captured data.
Syntax uint8_t* image.createRgb565()
Parameters None
Returns Pointer to the data

createGrayImage

Description Create a gray image data from RGB565 320x240. The gray data is necessary to detect moving and human.
Syntax uint8_t* image.createGrayImage()
Parameters None
Returns Pointer to the data

createJpg

Description Create a encoded JPEG file from RGB565 320x240 data.
Syntax uint8_t* image.createJpg()
Parameters None
Returns Pointer to the data

getCreatedRgb565

Description Get the address to the created RGB565 data.
Syntax uint8_t* image.getCreatedRgb565()
Parameters None
Returns Pointer to the data

getCreatedGrayImage

Description Get the address to the created gray data.
Syntax uint8_t* image.getCreatedGrayImage()
Parameters None
Returns Pointer to the data

getCreatedJpg

Description Get the address to the created JPEG data.
Syntax uint8_t* image.getCreatedJpg()
Parameters None
Returns Pointer to the data

getCreatedJpgSize

Description Get the size of created JPEG data.
Syntax int32_t image.getCreatedJpgSize()
Parameters None
Returns Size of data

personDetection

Description Execute to detect a human. It is necessary to finish to create gray data before executing.
Syntax bool image.personDetection()
Parameters None
Returns true: success to execute, false: fail to execute.
Note After executing this operation, the result of detecting is reflected to the created RGB565 data.

getPersonNumber

Description Return the number of human in specified area from the result of personDetection.
Syntax bool image.getPersonNumber(area)
Parameters area: from 1 to 9 as below. In case to specify 0, return the number of human in all area(default)
Returns The number of human in specified area.
Note It is up to 5 in an area. The distance to detect is optimized to 4 meter.

movingDetection

Description Execute to detect a moving. It is necessary to create 3 gray images before executing.
Syntax bool image.movingDetection(uint8_t* before_gray_image1, uint8_t* before_gray_image2)
Parameters before_gray_image1: pointer to the gray image twice before.
before_gray_image2: pointer to the gray image once before.
Returns true: success to execute, false: fail to execute.
Note After executing this operation, the result of detecting is reflected to the created RGB565 data.

getMovingNumber

Description Return the number of moving in specified area from the result of movingDetection.
Syntax bool image.getMovingNumber()
Parameters None
Returns The number of moving in specified area.

getMovingArea

Description Return the area of detected moving from the result of movingDetection.
Syntax bool image.getMovingArea(moving)
Parameters moving: specify No. of moving. 0 means the biggest moving. 1 or more is in ascending order.
Returns Area as below


Sample Program

This sample store a deteced image to SD continuously.

/*
 This sample enables to take a photo that include moving detection. 
 After taking a photo, the photo will be compressed to JPEG file and 
 then saved to SD card. 
 Hardware: GR-KAEDE, camera option and SD. Also USB cable and PC.
 note: This sample needs to install USB driver for GR-KAEDE
       The USB driver is in the project folder just you created.
       Also you need to install a terminal software like Teraterm.
*/ 

#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");

    if(!SD.begin()){
        Serial.println("Failed to access SD.");
    } else {
        Serial.println("Success to access SD.");
    }

	// RTC for time stamp in 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);

    SdFile::dateTimeCallback( &dateTime );

	// Initialize Image library
    image[0].begin();

}

void loop(){

    static int cnt = 0;

	while(cnt < 2){ //necessary at least two image in the past.
        image[cnt].captureStart();
        while(!image[cnt].isCaptureFinished());
        image[cnt].createGrayImage();
        cnt++;
	}
	
    Serial.println("Capturing image");
    image[cnt%3].captureStart();
    while(!image[cnt%3].isCaptureFinished());
    image[cnt%3].createGrayImage();
	
	// Moving detection
    if( 0 == image[cnt%3].movingDetection(image[(cnt-2)%3].getCreatedGrayImage(), image[(cnt-1)%3].getCreatedGrayImage())){
        Serial.println("finish detection");
        Serial.print("Moving Number is:");
        Serial.println(image[cnt%3].getMovingNumber());
        Serial.print("The biggest moving is in area:");
        Serial.println(image[cnt%3].getMovingArea(0));
    }
    image[cnt%3].createJpg();

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

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

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);
}

Made by Gadget Renesas Project
Contents are CC BY-SA 3.0