diff --git a/conf/modules/cv_opticflow.xml b/conf/modules/cv_opticflow.xml index add987d92a..4d30d6727e 100644 --- a/conf/modules/cv_opticflow.xml +++ b/conf/modules/cv_opticflow.xml @@ -51,7 +51,7 @@ - + @@ -62,6 +62,9 @@ + + + diff --git a/sw/airborne/modules/computer_vision/lib/vision/lucas_kanade.c b/sw/airborne/modules/computer_vision/lib/vision/lucas_kanade.c index d546f03176..712ccafc26 100644 --- a/sw/airborne/modules/computer_vision/lib/vision/lucas_kanade.c +++ b/sw/airborne/modules/computer_vision/lib/vision/lucas_kanade.c @@ -62,7 +62,7 @@ */ struct flow_t *opticFlowLK(struct image_t *new_img, struct image_t *old_img, struct point_t *points, uint16_t *points_cnt, uint16_t half_window_size, - uint16_t subpixel_factor, uint8_t max_iterations, uint8_t step_threshold, uint8_t max_points, uint8_t pyramid_lvl) + uint16_t subpixel_factor, uint8_t max_iterations, uint8_t step_threshold, uint8_t max_points, uint8_t pyramid_level) { @@ -91,12 +91,12 @@ struct flow_t *opticFlowLK(struct image_t *new_img, struct image_t *old_img, str step_threshold = step_threshold * (subpixel_factor / 100); // Allocate memory for image pyramids - struct image_t *pyramid_old = malloc(sizeof(struct image_t) * (pyramid_lvl + 1)); - struct image_t *pyramid_new = malloc(sizeof(struct image_t) * (pyramid_lvl + 1)); + struct image_t *pyramid_old = malloc(sizeof(struct image_t) * (pyramid_level + 1)); + struct image_t *pyramid_new = malloc(sizeof(struct image_t) * (pyramid_level + 1)); // Build pyramid levels - pyramid_build(old_img, pyramid_old, pyramid_lvl, border_size); - pyramid_build(new_img, pyramid_new, pyramid_lvl, border_size); + pyramid_build(old_img, pyramid_old, pyramid_level, border_size); + pyramid_build(new_img, pyramid_new, pyramid_level, border_size); // Create the window images struct image_t window_I, window_J, window_DX, window_DY, window_diff; @@ -107,7 +107,7 @@ struct flow_t *opticFlowLK(struct image_t *new_img, struct image_t *old_img, str image_create(&window_diff, patch_size, patch_size, IMAGE_GRADIENT); // Iterate through pyramid levels - for (int8_t LVL = pyramid_lvl; LVL != -1; LVL--) { + for (int8_t LVL = pyramid_level; LVL != -1; LVL--) { uint16_t points_orig = *points_cnt; *points_cnt = 0; uint16_t new_p = 0; @@ -119,10 +119,10 @@ struct flow_t *opticFlowLK(struct image_t *new_img, struct image_t *old_img, str for (uint16_t i = 0; i < max_points && i < points_orig; i++) { uint16_t p = i * skip_points; - if (LVL == pyramid_lvl) { + if (LVL == pyramid_level) { // Convert point position on original image to a subpixel coordinate on the top pyramid level - vectors[new_p].pos.x = (points[p].x * subpixel_factor) >> pyramid_lvl; - vectors[new_p].pos.y = (points[p].y * subpixel_factor) >> pyramid_lvl; + vectors[new_p].pos.x = (points[p].x * subpixel_factor) >> pyramid_level; + vectors[new_p].pos.y = (points[p].y * subpixel_factor) >> pyramid_level; vectors[new_p].flow_x = 0; vectors[new_p].flow_y = 0; @@ -223,7 +223,7 @@ struct flow_t *opticFlowLK(struct image_t *new_img, struct image_t *old_img, str image_free(&window_DY); image_free(&window_diff); - for (int8_t i = pyramid_lvl; i != -1; i--) { + for (int8_t i = pyramid_level; i != -1; i--) { image_free(&pyramid_old[i]); image_free(&pyramid_new[i]); } diff --git a/sw/airborne/modules/computer_vision/lib/vision/lucas_kanade.h b/sw/airborne/modules/computer_vision/lib/vision/lucas_kanade.h index 86e3316cbf..1879b07ba0 100644 --- a/sw/airborne/modules/computer_vision/lib/vision/lucas_kanade.h +++ b/sw/airborne/modules/computer_vision/lib/vision/lucas_kanade.h @@ -36,6 +36,6 @@ struct flow_t *opticFlowLK(struct image_t *new_img, struct image_t *old_img, struct point_t *points, uint16_t *points_cnt, uint16_t half_window_size, - uint16_t subpixel_factor, uint8_t max_iterations, uint8_t step_threshold, uint8_t max_points, uint8_t pyramid_lvl); + uint16_t subpixel_factor, uint8_t max_iterations, uint8_t step_threshold, uint8_t max_points, uint8_t pyramid_level); #endif /* OPTIC_FLOW_INT_H */ diff --git a/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.c b/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.c index 96f3f68a21..12a2b140c7 100644 --- a/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.c +++ b/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.c @@ -104,10 +104,10 @@ PRINT_CONFIG_VAR(OPTICFLOW_MAX_ITERATIONS) #endif PRINT_CONFIG_VAR(OPTICFLOW_THRESHOLD_VEC) -#ifndef OPTICFLOW_PYRAMID_LVL -#define OPTICFLOW_PYRAMID_LVL 3 +#ifndef OPTICFLOW_PYRAMID_LEVEL +#define OPTICFLOW_PYRAMID_LEVEL 3 #endif -PRINT_CONFIG_VAR(OPTICFLOW_PYRAMID_LVL) +PRINT_CONFIG_VAR(OPTICFLOW_PYRAMID_LEVEL) #ifndef OPTICFLOW_FAST9_ADAPTIVE #define OPTICFLOW_FAST9_ADAPTIVE TRUE @@ -170,7 +170,7 @@ void opticflow_calc_init(struct opticflow_t *opticflow, uint16_t w, uint16_t h) opticflow->subpixel_factor = OPTICFLOW_SUBPIXEL_FACTOR; opticflow->max_iterations = OPTICFLOW_MAX_ITERATIONS; opticflow->threshold_vec = OPTICFLOW_THRESHOLD_VEC; - opticflow->pyramid_lvl = OPTICFLOW_PYRAMID_LVL; + opticflow->pyramid_level = OPTICFLOW_PYRAMID_LEVEL; opticflow->fast9_adaptive = OPTICFLOW_FAST9_ADAPTIVE; opticflow->fast9_threshold = OPTICFLOW_FAST9_THRESHOLD; @@ -244,7 +244,7 @@ void calc_fast9_lukas_kanade(struct opticflow_t *opticflow, struct opticflow_sta result->tracked_cnt = result->corner_cnt; struct flow_t *vectors = opticFlowLK(&opticflow->img_gray, &opticflow->prev_img_gray, corners, &result->tracked_cnt, opticflow->window_size / 2, opticflow->subpixel_factor, opticflow->max_iterations, - opticflow->threshold_vec, opticflow->max_track_corners, opticflow->pyramid_lvl); + opticflow->threshold_vec, opticflow->max_track_corners, opticflow->pyramid_level); #if OPTICFLOW_DEBUG && OPTICFLOW_SHOW_FLOW image_show_flow(img, vectors, result->tracked_cnt, opticflow->subpixel_factor); diff --git a/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.h b/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.h index 4caefadb09..7bff1f2bac 100644 --- a/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.h +++ b/sw/airborne/modules/computer_vision/opticflow/opticflow_calculator.h @@ -51,7 +51,7 @@ struct opticflow_t { uint16_t subpixel_factor; ///< The amount of subpixels per pixel uint8_t max_iterations; ///< The maximum amount of iterations the Lucas Kanade algorithm should do uint8_t threshold_vec; ///< The threshold in x, y subpixels which the algorithm should stop - uint8_t pyramid_lvl; ///< Number of pyramid levels used in Lucas Kanade algorithm (0 == no pyramids used) + uint8_t pyramid_level; ///< Number of pyramid levels used in Lucas Kanade algorithm (0 == no pyramids used) uint8_t max_track_corners; ///< Maximum amount of corners Lucas Kanade should track bool_t fast9_adaptive; ///< Whether the FAST9 threshold should be adaptive