Add very basic exposure compensation
This commit is contained in:
parent
1e0daa39cc
commit
91dc86102f
|
@ -1 +1 @@
|
||||||
499
|
510
|
||||||
|
|
26
src/ov7670.c
26
src/ov7670.c
|
@ -152,9 +152,10 @@ uint8_t ImageBuffer[CAMERA_IMAGE_WIDTH * CAMERA_IMAGE_HEIGHT / 8];
|
||||||
static volatile int CurrentLine = 0;
|
static volatile int CurrentLine = 0;
|
||||||
uint8_t LineBuffer[CAMERA_IMAGE_WIDTH + 40];
|
uint8_t LineBuffer[CAMERA_IMAGE_WIDTH + 40];
|
||||||
int LineCount = 0;
|
int LineCount = 0;
|
||||||
static int FrameCount = 0;
|
static volatile int FrameCount = 0;
|
||||||
volatile int Camera_Captured = 0;
|
volatile int Camera_Captured = 0;
|
||||||
unsigned int BlackPixels = 0;
|
static unsigned int BlackPixels = 0;
|
||||||
|
static volatile int ExposureCorrection = 0;
|
||||||
|
|
||||||
static uint8_t ReadRegister(uint8_t reg)
|
static uint8_t ReadRegister(uint8_t reg)
|
||||||
{
|
{
|
||||||
|
@ -311,9 +312,11 @@ void TIM1_CC_IRQHandler(void)
|
||||||
CurrentLine = 0;
|
CurrentLine = 0;
|
||||||
FrameCount++;
|
FrameCount++;
|
||||||
|
|
||||||
|
// Correct exposure across frames
|
||||||
|
ExposureCorrection += 32 * BlackPixels / CAMERA_PIXELS - 16;
|
||||||
|
|
||||||
// Check if the last frame's exposure is reasonable
|
// Check if the last frame's exposure is reasonable
|
||||||
if(BlackPixels >= (unsigned)(CAMERA_PIXELS * CAMERA_EXPOSURE_LOW)
|
if(FrameCount >= 5)
|
||||||
&& BlackPixels <= (unsigned)(CAMERA_PIXELS * CAMERA_EXPOSURE_HIGH))
|
|
||||||
{
|
{
|
||||||
Camera_Captured = 1;
|
Camera_Captured = 1;
|
||||||
// Disable everything
|
// Disable everything
|
||||||
|
@ -370,6 +373,21 @@ void TIM3_IRQHandler(void)
|
||||||
for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++)
|
for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++)
|
||||||
{
|
{
|
||||||
int pixel = LineBuffer[i + 15] + x_error;
|
int pixel = LineBuffer[i + 15] + x_error;
|
||||||
|
if(ExposureCorrection < 0)
|
||||||
|
{
|
||||||
|
if(pixel < -ExposureCorrection)
|
||||||
|
pixel = 0;
|
||||||
|
else
|
||||||
|
pixel += ExposureCorrection;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(pixel > 255 - ExposureCorrection)
|
||||||
|
pixel = 255;
|
||||||
|
else
|
||||||
|
pixel += ExposureCorrection;
|
||||||
|
}
|
||||||
|
|
||||||
int line = CurrentLine / 2;
|
int line = CurrentLine / 2;
|
||||||
int error;
|
int error;
|
||||||
if(pixel < 127)
|
if(pixel < 127)
|
||||||
|
|
|
@ -7,11 +7,6 @@
|
||||||
#define CAMERA_IMAGE_HEIGHT 144
|
#define CAMERA_IMAGE_HEIGHT 144
|
||||||
#define CAMERA_PIXELS (CAMERA_IMAGE_WIDTH * CAMERA_IMAGE_HEIGHT)
|
#define CAMERA_PIXELS (CAMERA_IMAGE_WIDTH * CAMERA_IMAGE_HEIGHT)
|
||||||
|
|
||||||
// Maximum and minimum share of black pixels for an image to be accepted
|
|
||||||
#define CAMERA_EXPOSURE_LIMIT 0.4
|
|
||||||
#define CAMERA_EXPOSURE_LOW (0.5 - CAMERA_EXPOSURE_LIMIT)
|
|
||||||
#define CAMERA_EXPOSURE_HIGH (0.5 + CAMERA_EXPOSURE_LIMIT)
|
|
||||||
|
|
||||||
// Use 2D Floyd-Steinberg dithering. Uncomment to use simple line-wise
|
// Use 2D Floyd-Steinberg dithering. Uncomment to use simple line-wise
|
||||||
// dithering.
|
// dithering.
|
||||||
#define CAMERA_USE_2D_DITHERING
|
#define CAMERA_USE_2D_DITHERING
|
||||||
|
|
Loading…
Reference in a new issue