From 6c8fb1fbf948b3c4a3f800f0ad28ef99bb91fb37 Mon Sep 17 00:00:00 2001 From: Titus Date: Mon, 27 Mar 2017 12:45:19 +0200 Subject: [PATCH] moved the opticflow_calc_init call to opticflow_module.c and moved the LK related parts to the LK function --- .../opticflow/opticflow_calculator.c | 29 ++++++++----------- .../opticflow/opticflow_calculator.h | 2 +- .../computer_vision/opticflow_module.c | 1 + 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.c b/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.c index 17e624e9c0..9acb92b9a1 100644 --- a/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.c +++ b/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.c @@ -194,23 +194,9 @@ static int cmp_flow(const void *a, const void *b); /** * Initialize the opticflow calculator * @param[out] *opticflow The new optical flow calculator - * @param[in] *w The image width - * @param[in] *h The image height */ -void opticflow_calc_init(struct opticflow_t *opticflow, uint16_t w, uint16_t h) +void opticflow_calc_init(struct opticflow_t *opticflow) { - - init_median_filter(&vel_x_filt); - init_median_filter(&vel_y_filt); - - /* Create the image buffers */ - image_create(&opticflow->img_gray, w, h, IMAGE_GRAYSCALE); - image_create(&opticflow->prev_img_gray, w, h, IMAGE_GRAYSCALE); - - /* Set the previous values */ - opticflow->got_first_img = false; - FLOAT_RATES_ZERO(opticflow->prev_rates); - /* Set the default values */ opticflow->method = OPTICFLOW_METHOD; //0 = LK_fast9, 1 = Edgeflow opticflow->window_size = OPTICFLOW_WINDOW_SIZE; @@ -234,7 +220,6 @@ void opticflow_calc_init(struct opticflow_t *opticflow, uint16_t w, uint16_t h) opticflow->fast9_padding = OPTICFLOW_FAST9_PADDING; opticflow->fast9_rsize = 512; opticflow->fast9_ret_corners = malloc(sizeof(struct point_t) * opticflow->fast9_rsize); - } /** * Run the optical flow with fast9 and lukaskanade on a new image frame @@ -247,7 +232,17 @@ void calc_fast9_lukas_kanade(struct opticflow_t *opticflow, struct opticflow_sta struct opticflow_result_t *result) { if (opticflow->just_switched_method) { - opticflow_calc_init(opticflow, img->w, img->h); + // Create the image buffers + image_create(&opticflow->img_gray, img->w, img->h, IMAGE_GRAYSCALE); + image_create(&opticflow->prev_img_gray, img->w, img->h, IMAGE_GRAYSCALE); + + // Set the previous values + opticflow->got_first_img = false; + FLOAT_RATES_ZERO(opticflow->prev_rates); + + // Init median filters with zeros + init_median_filter(&vel_x_filt); + init_median_filter(&vel_y_filt); } // variables for size_divergence: diff --git a/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.h b/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.h index 10a6805670..fa46e364a0 100644 --- a/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.h +++ b/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.h @@ -72,7 +72,7 @@ struct opticflow_t { }; -void opticflow_calc_init(struct opticflow_t *opticflow, uint16_t w, uint16_t h); +void opticflow_calc_init(struct opticflow_t *opticflow); void opticflow_calc_frame(struct opticflow_t *opticflow, struct opticflow_state_t *state, struct image_t *img, struct opticflow_result_t *result); diff --git a/sw/airborne/modules/computer_vision/opticflow_module.c b/sw/airborne/modules/computer_vision/opticflow_module.c index dcfa16d6cd..4bb6b6c90b 100644 --- a/sw/airborne/modules/computer_vision/opticflow_module.c +++ b/sw/airborne/modules/computer_vision/opticflow_module.c @@ -124,6 +124,7 @@ void opticflow_module_init(void) // Initialize the opticflow calculation opticflow_got_result = false; + opticflow_calc_init(&opticflow); cv_add_to_device(&OPTICFLOW_CAMERA, opticflow_module_calc);