how to add functions to control picture quality for OV2640

Hi,

I want to add the following two functions to the camera setup code to control picture quality.

myCAM.OV2640_set_Light_Mode(Auto);
myCAM.OV2640_set_Light_Mode(Sunny);

I have the following code (for OV2640) that sets up the camera prior to taking an image and this works well (see below). I assume i add the two functions above after the myCAM.InitCAM(); method - do i need to add any other code? At the moment these two functions do not seem to be having any effect.

Any help is much appreciated.

uint8_t vid, pid;
uint8_t temp;

Wire.begin();

// set the SPI_CS as an output:
pinMode(SPI_CS, OUTPUT);
digitalWrite(SPI_CS, HIGH);

// initialize SPI:
//SPI.end();
SPI.begin();

//Reset the CPLD
myCAM.write_reg(0x07, 0x80);
delay(100);
myCAM.write_reg(0x07, 0x00);
delay(100);

while (1) {
//Check if the ArduCAM SPI bus is OK
myCAM.write_reg(ARDUCHIP_TEST1, 0x55);
temp = myCAM.read_reg(ARDUCHIP_TEST1);
if (temp != 0x55) {
Serial.println(F(“SPI interface Error!”));
delay(1000); continue; //or internalReset();
}
else {
Serial.println(F(“SPI interface OK.”)); break;
}
}

#if defined (OV2640_MINI_2MP_PLUS)
while (1) {
//Check if the camera module type is OV2640
myCAM.wrSensorReg8_8(0xff, 0x01);
myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);
myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
if ((vid != 0x26 ) && (( pid != 0x41 ) || ( pid != 0x42 ))) {
Serial.println(F(“Can’t find OV2640 module!”));
delay(1000); continue;
}
else {
Serial.println(F(“OV2640 detected.”)); break;
}
}
#endif

//Change to JPEG capture mode and auto mode and initialize the OV2640 module
myCAM.set_format(JPEG);
myCAM.InitCAM();
myCAM.clear_fifo_flag();
//myCAM.write_reg(ARDUCHIP_FRAMES, FRAMES_NUM

 

Hi,

Please try myCAM.OV2640_set_Light_Mode(Sunny) before capture image, and try setting the parameter to Home or Office for testing.

Hi,

Thanks for the reply.

Below is an image taken with the two methods;

myCAM.OV2640_set_Light_Mode(Sunny); myCAM.OV2640_set_Light_Mode(Auto);

As you can see, in the shaded area the picture is reasonably good but in the sunny area the picture is over exposed (i have a 1 second delay after initializing camera and before start capture to allow light levels to settle). is there a way to reduce this over exposure of the image.

Any help is much appreciated.

Cheers.

 

 

Hi,

Exposure can only change the brightness of an entire image, not just a local area.

If you want to change the global exposure time, you can use manual exposure mode.

You can refer to the following code for manual exposure Settings.

#define EXPOSURE_MS 10 //manual exposure time:0-99.928ms

uint32_t tex = EXPOSURE_MS * 1000000;
uint16_t AEC = tex / (1922*41.66);
char exposure1 = AEC & 0x3;
char exposure2 = (AEC >> 2)& 0xff;
char exposure3 = (AEC >> 10)& 0x3f;

void set_exposure(ArduCAM myCAM)
{
uint8_t temp;

myCAM.wrSensorReg8_8(0xff, 0x01);
myCAM.rdSensorReg8_8(0x13, &temp);
temp &= ~(1 << 0); //Close automatic exposure
temp &= ~(1 << 2); //Close AGC
myCAM.wrSensorReg8_8(0x13, temp);

myCAM.rdSensorReg8_8(0x04, &temp);
temp = temp & 0XFC;
myCAM.wrSensorReg8_8(0x04, temp | exposure1);

myCAM.rdSensorReg8_8(0x10, &temp);
temp = temp & 0;
myCAM.wrSensorReg8_8(0x10, temp | exposure2);

myCAM.rdSensorReg8_8(0x45, &temp);
temp = temp & 0XE0;
myCAM.wrSensorReg8_8(0x45, temp | exposure3);
}

Hi,

And thanks for the reply.

The following is my capture code to capture an image and be able to alter picture parameters such as auto, sunny and cloudy. Is this code correct? Commenting in or commenting out these parameters does not seem to alter the captured image.

Any help is much appreciated.

void captureToSD() {
//char str[16];
byte buf[256];
static int i = 0;
static int k = 0;
uint8_t temp = 0,temp_last=0;
uint32_t length = 0;
bool is_header = false;
File outFile;

//init sensor
myCAM.flush_fifo();
myCAM.clear_fifo_flag();

#if defined (OV2640_MINI_2MP_PLUS)
myCAM.OV2640_set_JPEG_size(OV2640_1600x1200);
myCAM.OV2640_set_Light_Mode(Auto);
myCAM.OV2640_set_Light_Mode(Sunny);
//myCAM.OV2640_set_Light_Mode(Cloudy);
#endif

delay(1000); //allow time for exposure to settle

//Start capture
myCAM.start_capture();
Serial.println(F(“start Capture”));

while(!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));

Serial.println(F(“Capture Done.”));
length = myCAM.read_fifo_length();
Serial.print(F(“fifo length>”));
Serial.println(length, DEC);

.

.

.

 

Hi,

The sunny and cloudy parameter setting seems to be fine, it should be noted that the setting should set before capture and after set resolution.

Please close your conditional compilation #if defined (OV2640_MINI_2MP_PLUS) try again.