32 #define MAX_HIST_Y 255
35 #ifndef BEBOP_AE_AWB_CAMERA
36 #define BEBOP_AE_AWB_CAMERA front_camera
40 #ifndef BEBOP_AE_AWB_VERBOSE
41 #define BEBOP_AE_AWB_VERBOSE 0
45 #define PRINT(string,...) fprintf(stderr, "[bebop_ae_awb->%s()] " string,__FUNCTION__ , ##__VA_ARGS__)
47 #if BEBOP_AE_AWB_VERBOSE
49 #define VERBOSE_PRINT PRINT
51 #define VERBOSE_PRINT(...)
55 #ifndef BEBOP_AE_AWB_NICE
56 #define BEBOP_AE_AWB_NICE 5
59 #ifndef BEBOP_AUTO_EXPOSURE
60 #define BEBOP_AUTO_EXPOSURE true
64 #ifndef BEBOP_AE_EXPOSURE_GAIN
65 #define BEBOP_AE_EXPOSURE_GAIN 0.8
70 #ifndef BEBOP_AE_MIDDLE_INDEX
71 #define BEBOP_AE_MIDDLE_INDEX 180
76 #ifndef BEBOP_AE_DARK_IGNORE
77 #define BEBOP_AE_DARK_IGNORE 0.4
82 #ifndef BEBOP_AE_BRIGHT_IGNORE
83 #define BEBOP_AE_BRIGHT_IGNORE 0.2
88 #ifndef BEBOP_AE_DARK_BINS
89 #define BEBOP_AE_DARK_BINS 80
94 #ifndef BEBOP_AE_BRIGHT_BINS
95 #define BEBOP_AE_BRIGHT_BINS 20
99 #ifndef BEBOP_AUTO_WHITE_BALANCE
100 #define BEBOP_AUTO_WHITE_BALANCE true
104 #ifndef BEBOP_AWB_MIN_GAINS
105 #define BEBOP_AWB_MIN_GAINS 1.0
107 PRINT_CONFIG_VAR(BEBOP_AE_MIN_GAINS)
110 #ifndef BEBOP_AWB_MAX_GAINS
111 #define BEBOP_AWB_MAX_GAINS 63.5
116 #ifndef BEBOP_AWB_GAIN
117 #define BEBOP_AWB_GAIN 0.25
122 #ifndef BEBOP_AWB_GAIN_SCHEDULING
123 #define BEBOP_AWB_GAIN_SCHEDULING false
128 #ifndef BEBOP_AWB_GAIN_SCHEDULING_TARGET
129 #define BEBOP_AWB_GAIN_SCHEDULING_TARGET 10.0
134 #ifndef BEBOP_AWB_GAIN_SCHEDULING_TOLERANCE
135 #define BEBOP_AWB_GAIN_SCHEDULING_TOLERANCE 7.5
140 #ifndef BEBOP_AWB_GAIN_SCHEDULING_STEP
141 #define BEBOP_AWB_GAIN_SCHEDULING_STEP 0.02
146 #ifndef BEBOP_AWB_MIN_GREY_PIXELS
147 #define BEBOP_AWB_MIN_GREY_PIXELS 1000
177 float dt = (img->
pprz_ts - prev_time) * 1e-6f;
196 static float prev_real_exposure = 0.f;
197 static uint8_t prev_exposure_stuck = 0;
209 if (dark_index > MAX_HIST_Y) {
213 if (bright_index < MIN_HIST_Y || bright_index > MAX_HIST_Y) {
214 bright_index = dark_index;
219 cdf[bright_index - 1] - cdf[dark_index] +
226 while (current_pixels < median_pixels && ae_current_ind < MAX_HIST_Y) {
228 if (ae_current_ind <= dark_index) {
231 }
else if (ae_current_ind >= bright_index) {
240 float ae_current_level = (float)ae_current_ind;
243 ae_current_level -= (current_pixels - median_pixels) / (
float)yuv_stats.
ae_histogram_Y[ae_current_ind];
252 float adjustment = 1.f;
253 if (ae_current_level > 1e-5) {
255 Bound(adjustment, 1 / 16.f, 16.f);
265 prev_exposure_stuck++;
274 prev_exposure_stuck = 0;
static struct image_t * update_ae_awb(struct image_t *img)
static void bebop_awb_reset(void)
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
#define MT9F002_GAIN_GREEN2
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.5 -> 63.50].
uint32_t pprz_ts
The timestamp in us since system startup.
uint32_t awb_nb_grey_pixels
#define MT9F002_GAIN_GREEN1
#define BEBOP_AWB_GAIN_SCHEDULING_TARGET
void bebop_ae_awb_init(void)
#define BEBOP_AE_DARK_IGNORE
#define MT9F002_TARGET_EXPOSURE
Exposure of the front camera of the bebop.
#define BEBOP_AE_BRIGHT_BINS
#define BEBOP_AE_AWB_VERBOSE
float gain_green1
Gain for the GreenR pixels [1.5 -> 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.5 -> 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.5 -> 63.50].
Initialization and configuration of the MT9F002 CMOS Chip.
float real_exposure
Real exposure time in ms.
float gain_scheduling_target
static void bebop_ae_reset(void)
#define BEBOP_AE_AWB_CAMERA
struct awb_setting_t awb_set
#define MT9F002_GAIN_BLUE
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