31 #define MAX_HIST_Y 255
33 #define sgn(x) (float)((x < 0) ? -1 : (x > 0))
35 #ifndef BEBOP_AUTO_EXPOSURE
36 #define BEBOP_AUTO_EXPOSURE true
39 #ifndef BEBOP_AUTO_WHITE_BALANCE
40 #define BEBOP_AUTO_WHITE_BALANCE true
43 #define BEBOP_AWB_MIN_GAIN 2
44 #define BEBOP_AWB_MAX_GAIN 75
53 #if BEBOP_AUTO_EXPOSURE
62 uint32_t bright_pixels = cdf[MAX_HIST_Y - 1] - cdf[MAX_HIST_Y - 26];
63 uint32_t saturated_pixels = cdf[MAX_HIST_Y - 1] - cdf[MAX_HIST_Y - 6];
66 float adjustment = 1.0f;
68 if (saturated_pixels + max_saturated_pixels / 10 > max_saturated_pixels) {
70 adjustment = 1.0f - (float)saturated_pixels / yuv_stats.
nb_valid_Y;
71 adjustment *= adjustment * adjustment;
72 }
else if (bright_pixels + target_bright_pixels / 10 < target_bright_pixels) {
74 int l = MAX_HIST_Y - 1;
75 while (bright_pixels < target_bright_pixels && l > 0) {
76 bright_pixels += cdf[l];
77 bright_pixels -= cdf[l - 1];
81 adjustment = (float)MAX_HIST_Y / (l + 1);
82 }
else if (bright_pixels - target_bright_pixels / 10 > target_bright_pixels) {
84 int l = MAX_HIST_Y - 20;
85 while (bright_pixels > target_bright_pixels && l < MAX_HIST_Y) {
86 bright_pixels -= cdf[l];
87 bright_pixels += cdf[l - 1];
91 adjustment = (float)(MAX_HIST_Y - 20) / l;
92 adjustment *= adjustment;
96 Bound(adjustment, 1 / 16.0f, 4.0);
101 #if BEBOP_AUTO_WHITE_BALANCE
106 float threshold = 0.002f;
108 bool changed =
false;
110 if (fabs(avgU) > threshold) {
114 if (fabs(avgV) > threshold) {
void mt9f002_set_exposure(struct mt9f002_t *mt)
Set the exposure configuration Depends on the blanking (and therefore the FPS)
int isp_get_statistics_yuv(struct isp_yuv_stats_t *yuv_stats)
float gain_blue
Gain for the Blue pixels [1.5 -> 63.50].
uint32_t awb_nb_grey_pixels
void bebop_ae_awb_init(void)
void bebop_ae_awb_periodic(void)
void mt9f002_set_gains(struct mt9f002_t *mt)
Sets the GreenR, Blue, Red and GreenB gains.
float gain_red
Gain for the Red pixels [1.5 -> 63.50].
Initialization and configuration of the MT9F002 CMOS Chip.
float real_exposure
Real exposure time in ms.
uint32_t ae_histogram_Y[256]
float target_exposure
Target exposure time in ms.