32 #define MAX_HIST_Y 255
35 #ifndef BEBOP_AE_AWB_VERBOSE
36 #define BEBOP_AE_AWB_VERBOSE 0
40 #define PRINT(string,...) fprintf(stderr, "[bebop_ae_awb->%s()] " string,__FUNCTION__ , ##__VA_ARGS__)
42 #if BEBOP_AE_AWB_VERBOSE
44 #define VERBOSE_PRINT PRINT
46 #define VERBOSE_PRINT(...)
50 #ifndef BEBOP_AE_AWB_NICE
51 #define BEBOP_AE_AWB_NICE 5
54 #ifndef BEBOP_AUTO_EXPOSURE
55 #define BEBOP_AUTO_EXPOSURE true
59 #ifndef BEBOP_AE_EXPOSURE_GAIN
60 #define BEBOP_AE_EXPOSURE_GAIN 0.8
65 #ifndef BEBOP_AE_MIDDLE_INDEX
66 #define BEBOP_AE_MIDDLE_INDEX 160
71 #ifndef BEBOP_AE_DARK_IGNORE
72 #define BEBOP_AE_DARK_IGNORE 0.4
77 #ifndef BEBOP_AE_BRIGHT_IGNORE
78 #define BEBOP_AE_BRIGHT_IGNORE 0.2
83 #ifndef BEBOP_AE_DARK_BINS
84 #define BEBOP_AE_DARK_BINS 80
89 #ifndef BEBOP_AE_BRIGHT_BINS
90 #define BEBOP_AE_BRIGHT_BINS 20
94 #ifndef BEBOP_AUTO_WHITE_BALANCE
95 #define BEBOP_AUTO_WHITE_BALANCE true
99 #ifndef BEBOP_AWB_MIN_GAINS
100 #define BEBOP_AWB_MIN_GAINS 1.0
102 PRINT_CONFIG_VAR(BEBOP_AE_MIN_GAINS)
105 #ifndef BEBOP_AWB_MAX_GAINS
106 #define BEBOP_AWB_MAX_GAINS 63.5
111 #ifndef BEBOP_AWB_GAIN
112 #define BEBOP_AWB_GAIN 0.5
117 #ifndef BEBOP_AWB_GAIN_SCHEDULING
118 #define BEBOP_AWB_GAIN_SCHEDULING false
123 #ifndef BEBOP_AWB_GAIN_SCHEDULING_TARGET
124 #define BEBOP_AWB_GAIN_SCHEDULING_TARGET 10.0
129 #ifndef BEBOP_AWB_GAIN_SCHEDULING_TOLERANCE
130 #define BEBOP_AWB_GAIN_SCHEDULING_TOLERANCE 7.5
135 #ifndef BEBOP_AWB_GAIN_SCHEDULING_STEP
136 #define BEBOP_AWB_GAIN_SCHEDULING_STEP 0.02
141 #ifndef BEBOP_AWB_MIN_GREY_PIXELS
142 #define BEBOP_AWB_MIN_GREY_PIXELS 1000
156 float dt = (img->pprz_ts - prev_time) * 1e-6f;
158 prev_time = img->pprz_ts;
175 static float prev_real_exposure = 0.f;
176 static uint8_t prev_exposure_stuck = 0;
188 if (dark_index > MAX_HIST_Y) {
192 if (bright_index < MIN_HIST_Y || bright_index > MAX_HIST_Y) {
193 bright_index = dark_index;
198 cdf[bright_index - 1] - cdf[dark_index] +
199 (1.f - ae_set.
bright_ignore) * (cdf[MAX_HIST_Y - 1] - cdf[bright_index - 1]))
205 while (current_pixels < median_pixels && ae_current_ind < MAX_HIST_Y) {
207 if (ae_current_ind <= dark_index) {
210 }
else if (ae_current_ind >= bright_index) {
219 float ae_current_level = (float)ae_current_ind;
222 ae_current_level -= (current_pixels - median_pixels) / (
float)yuv_stats.
ae_histogram_Y[ae_current_ind];
231 float adjustment = 1.f;
232 if (ae_current_level > 1e-5) {
234 Bound(adjustment, 1 / 16.f, 16.f);
244 prev_exposure_stuck++;
253 prev_exposure_stuck = 0;
static struct image_t * update_ae_awb(struct image_t *img)
void mt9f002_set_exposure(struct mt9f002_t *mt)
Set the exposure configuration Depends on the blanking (and therefore the FPS)
#define BEBOP_AE_MIDDLE_INDEX
float gain_scheduling_step
float gain_scheduling_tolerance
#define BEBOP_AWB_MIN_GAINS
#define BEBOP_AWB_MAX_GAINS
#define BEBOP_AE_AWB_NICE
#define BEBOP_AUTO_EXPOSURE
int isp_get_statistics_yuv(struct isp_yuv_stats_t *yuv_stats)
float gain_blue
Gain for the Blue pixels [1., 63.50].
uint32_t awb_nb_grey_pixels
#define BEBOP_AWB_GAIN_SCHEDULING_TARGET
void bebop_ae_awb_init(void)
#define BEBOP_AE_DARK_IGNORE
#define BEBOP_AE_BRIGHT_BINS
#define BEBOP_AE_AWB_VERBOSE
float gain_green1
Gain for the GreenR pixels [1., 63.50].
Computer vision framework for onboard processing.
#define VERBOSE_PRINT(...)
#define BEBOP_AWB_GAIN_SCHEDULING
void mt9f002_set_gains(struct mt9f002_t *mt)
Sets the GreenR, Blue, Red and GreenB gains.
#define BEBOP_AWB_GAIN_SCHEDULING_TOLERANCE
#define BEBOP_AWB_GAIN_SCHEDULING_STEP
struct video_listener * cv_add_to_device_async(struct video_config_t *device, cv_function func, int nice_level, uint16_t fps)
float gain_red
Gain for the Red pixels [1., 63.50].
#define BEBOP_AWB_MIN_GREY_PIXELS
#define BEBOP_AUTO_WHITE_BALANCE
#define BEBOP_AE_DARK_BINS
#define BEBOP_AE_EXPOSURE_GAIN
float gain_green2
Gain for the GreenB pixels [1., 63.50].
Initialization and configuration of the MT9F002 CMOS Chip.
float real_exposure
Real exposure time in ms.
float gain_scheduling_target
void mt9f002_reset_exposure(struct mt9f002_t *mt)
struct awb_setting_t awb_set
void mt9f002_reset_color(struct mt9f002_t *mt)
uint32_t ae_histogram_Y[256]
#define BEBOP_AE_BRIGHT_IGNORE
float target_exposure
Target exposure time in ms.
struct ae_setting_t ae_set