Added pyramid level slider to settings.

This commit is contained in:
hrvoje
2016-03-30 21:15:08 +02:00
parent c33e454fdf
commit 047586eca5
5 changed files with 21 additions and 18 deletions
+4 -1
View File
@@ -51,7 +51,7 @@
<dl_setting var="opticflow.method" min="0" step="1" max="1" module="computer_vision/opticflow_module" shortname="method" values="LK_Fast9|EdgeFlow" param="METHOD"/> <dl_setting var="opticflow.method" min="0" step="1" max="1" module="computer_vision/opticflow_module" shortname="method" values="LK_Fast9|EdgeFlow" param="METHOD"/>
<dl_setting var="opticflow.window_size" module="computer_vision/opticflow_module" min="0" step="1" max="20" shortname="window_size" param="OPTICFLOW_WINDOW_SIZE"/> <dl_setting var="opticflow.window_size" module="computer_vision/opticflow_module" min="0" step="1" max="20" shortname="window_size" param="OPTICFLOW_WINDOW_SIZE"/>
<dl_setting var="opticflow.search_distance" module="computer_vision/opticflow_module" min="0" step="1" max="50" shortname="search_distance" param="SEARCH_DISTANCE"/> <dl_setting var="opticflow.search_distance" module="computer_vision/opticflow_module" min="0" step="1" max="50" shortname="search_distance" param="SEARCH_DISTANCE"/>
<dl_setting var="opticflow.subpixel_factor" module="computer_vision/opticflow_module" min="0" step="1" max="100" shortname="subpixel_factor" param="OPTICFLOW_SUBPIXEL_FACTOR"/> <dl_setting var="opticflow.subpixel_factor" module="computer_vision/opticflow_module" min="0" step="10" max="1000" shortname="subpixel_factor" param="OPTICFLOW_SUBPIXEL_FACTOR"/>
<dl_setting var="opticflow.derotation" min="0" step="1" max="1" module="computer_vision/opticflow_module" values="OFF|ON" shortname="derotation" param="OPTICFLOW_DEROTATION"/> <dl_setting var="opticflow.derotation" min="0" step="1" max="1" module="computer_vision/opticflow_module" values="OFF|ON" shortname="derotation" param="OPTICFLOW_DEROTATION"/>
<!-- Specifically for Lucas Kanade and FAST9 --> <!-- Specifically for Lucas Kanade and FAST9 -->
@@ -62,6 +62,9 @@
<dl_setting var="opticflow.fast9_adaptive" module="computer_vision/opticflow_module" min="0" step="1" max="1" values="TRUE|FALSE" shortname="fast9_adaptive" param="OPTICFLOW_FAST9_ADAPTIVE"/> <dl_setting var="opticflow.fast9_adaptive" module="computer_vision/opticflow_module" min="0" step="1" max="1" values="TRUE|FALSE" shortname="fast9_adaptive" param="OPTICFLOW_FAST9_ADAPTIVE"/>
<dl_setting var="opticflow.fast9_threshold" module="computer_vision/opticflow_module" min="0" step="1" max="255" shortname="fast9_threshold" param="OPTICFLOW_FAST9_THRESHOLD"/> <dl_setting var="opticflow.fast9_threshold" module="computer_vision/opticflow_module" min="0" step="1" max="255" shortname="fast9_threshold" param="OPTICFLOW_FAST9_THRESHOLD"/>
<dl_setting var="opticflow.fast9_min_distance" module="computer_vision/opticflow_module" min="0" step="1" max="500" shortname="fast9_min_distance" param="OPTICFLOW_FAST9_MIN_DISTANCE"/> <dl_setting var="opticflow.fast9_min_distance" module="computer_vision/opticflow_module" min="0" step="1" max="500" shortname="fast9_min_distance" param="OPTICFLOW_FAST9_MIN_DISTANCE"/>
<!-- Changes pyramid level of lucas kanade optical flow. -->
<dl_setting var="opticflow.pyramid_level" module="computer_vision/opticflow_module" min="0" step="1" max="10" shortname="pyramid_level" param="OPTICFLOW_PYRAMID_LEVEL"/>
</dl_settings> </dl_settings>
</dl_settings> </dl_settings>
</settings> </settings>
@@ -62,7 +62,7 @@
*/ */
struct flow_t *opticFlowLK(struct image_t *new_img, struct image_t *old_img, struct point_t *points, 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 *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); step_threshold = step_threshold * (subpixel_factor / 100);
// Allocate memory for image pyramids // Allocate memory for image pyramids
struct image_t *pyramid_old = 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_lvl + 1)); struct image_t *pyramid_new = malloc(sizeof(struct image_t) * (pyramid_level + 1));
// Build pyramid levels // Build pyramid levels
pyramid_build(old_img, pyramid_old, pyramid_lvl, border_size); pyramid_build(old_img, pyramid_old, pyramid_level, border_size);
pyramid_build(new_img, pyramid_new, pyramid_lvl, border_size); pyramid_build(new_img, pyramid_new, pyramid_level, border_size);
// Create the window images // Create the window images
struct image_t window_I, window_J, window_DX, window_DY, window_diff; 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); image_create(&window_diff, patch_size, patch_size, IMAGE_GRADIENT);
// Iterate through pyramid levels // 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; uint16_t points_orig = *points_cnt;
*points_cnt = 0; *points_cnt = 0;
uint16_t new_p = 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++) { for (uint16_t i = 0; i < max_points && i < points_orig; i++) {
uint16_t p = i * skip_points; 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 // 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.x = (points[p].x * subpixel_factor) >> pyramid_level;
vectors[new_p].pos.y = (points[p].y * subpixel_factor) >> pyramid_lvl; vectors[new_p].pos.y = (points[p].y * subpixel_factor) >> pyramid_level;
vectors[new_p].flow_x = 0; vectors[new_p].flow_x = 0;
vectors[new_p].flow_y = 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_DY);
image_free(&window_diff); 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_old[i]);
image_free(&pyramid_new[i]); image_free(&pyramid_new[i]);
} }
@@ -36,6 +36,6 @@
struct flow_t *opticFlowLK(struct image_t *new_img, struct image_t *old_img, struct point_t *points, 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 *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 */ #endif /* OPTIC_FLOW_INT_H */
@@ -104,10 +104,10 @@ PRINT_CONFIG_VAR(OPTICFLOW_MAX_ITERATIONS)
#endif #endif
PRINT_CONFIG_VAR(OPTICFLOW_THRESHOLD_VEC) PRINT_CONFIG_VAR(OPTICFLOW_THRESHOLD_VEC)
#ifndef OPTICFLOW_PYRAMID_LVL #ifndef OPTICFLOW_PYRAMID_LEVEL
#define OPTICFLOW_PYRAMID_LVL 3 #define OPTICFLOW_PYRAMID_LEVEL 3
#endif #endif
PRINT_CONFIG_VAR(OPTICFLOW_PYRAMID_LVL) PRINT_CONFIG_VAR(OPTICFLOW_PYRAMID_LEVEL)
#ifndef OPTICFLOW_FAST9_ADAPTIVE #ifndef OPTICFLOW_FAST9_ADAPTIVE
#define OPTICFLOW_FAST9_ADAPTIVE TRUE #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->subpixel_factor = OPTICFLOW_SUBPIXEL_FACTOR;
opticflow->max_iterations = OPTICFLOW_MAX_ITERATIONS; opticflow->max_iterations = OPTICFLOW_MAX_ITERATIONS;
opticflow->threshold_vec = OPTICFLOW_THRESHOLD_VEC; 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_adaptive = OPTICFLOW_FAST9_ADAPTIVE;
opticflow->fast9_threshold = OPTICFLOW_FAST9_THRESHOLD; 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; result->tracked_cnt = result->corner_cnt;
struct flow_t *vectors = opticFlowLK(&opticflow->img_gray, &opticflow->prev_img_gray, corners, &result->tracked_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->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 #if OPTICFLOW_DEBUG && OPTICFLOW_SHOW_FLOW
image_show_flow(img, vectors, result->tracked_cnt, opticflow->subpixel_factor); image_show_flow(img, vectors, result->tracked_cnt, opticflow->subpixel_factor);
@@ -51,7 +51,7 @@ struct opticflow_t {
uint16_t subpixel_factor; ///< The amount of subpixels per pixel 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 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 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 uint8_t max_track_corners; ///< Maximum amount of corners Lucas Kanade should track
bool_t fast9_adaptive; ///< Whether the FAST9 threshold should be adaptive bool_t fast9_adaptive; ///< Whether the FAST9 threshold should be adaptive