Paparazzi UAS
v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
|
Estimate velocity from optic flow. More...
#include "std.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "opticflow_calculator.h"
#include "lib/vision/image.h"
#include "lib/vision/lucas_kanade.h"
#include "lib/vision/fast_rosten.h"
#include "lib/vision/edge_flow.h"
#include "size_divergence.h"
#include "linear_flow_fit.h"
#include "filters/median_filter.h"
Go to the source code of this file.
Macros | |
#define | OPTICFLOW_SHOW_FLOW 0 |
#define | OPTICFLOW_SHOW_CORNERS 0 |
#define | SIZE_DIV 1 |
#define | LINEAR_FIT 1 |
#define | OPTICFLOW_FOV_W 0.89360857702 |
#define | OPTICFLOW_FOV_H 0.67020643276 |
#define | OPTICFLOW_FX 343.1211 |
#define | OPTICFLOW_FY 348.5053 |
#define | OPTICFLOW_MAX_TRACK_CORNERS 25 |
#define | OPTICFLOW_WINDOW_SIZE 10 |
#define | OPTICFLOW_SEARCH_DISTANCE 20 |
#define | OPTICFLOW_SUBPIXEL_FACTOR 10 |
#define | OPTICFLOW_MAX_ITERATIONS 10 |
#define | OPTICFLOW_THRESHOLD_VEC 2 |
#define | OPTICFLOW_PYRAMID_LEVEL 0 |
#define | OPTICFLOW_FAST9_ADAPTIVE TRUE |
#define | OPTICFLOW_FAST9_THRESHOLD 20 |
#define | OPTICFLOW_FAST9_MIN_DISTANCE 10 |
#define | OPTICFLOW_FAST9_PADDING 20 |
#define | FAST9_LOW_THRESHOLD 5 |
#define | FAST9_HIGH_THRESHOLD 60 |
#define | OPTICFLOW_METHOD 0 |
#define | OPTICFLOW_DEROTATION TRUE |
#define | OPTICFLOW_MEDIAN_FILTER TRUE |
Functions | |
static uint32_t | timeval_diff (struct timeval *starttime, struct timeval *finishtime) |
Calculate the difference from start till finish. More... | |
static int | cmp_flow (const void *a, const void *b) |
Compare two flow vectors based on flow distance Used for sorting. More... | |
void | opticflow_calc_init (struct opticflow_t *opticflow, uint16_t w, uint16_t h) |
Initialize the opticflow calculator. More... | |
void | calc_fast9_lukas_kanade (struct opticflow_t *opticflow, struct opticflow_state_t *state, struct image_t *img, struct opticflow_result_t *result) |
Run the optical flow with fast9 and lukaskanade on a new image frame. More... | |
void | calc_edgeflow_tot (struct opticflow_t *opticflow, struct opticflow_state_t *state, struct image_t *img, struct opticflow_result_t *result) |
Run the optical flow with EDGEFLOW on a new image frame. More... | |
void | opticflow_calc_frame (struct opticflow_t *opticflow, struct opticflow_state_t *state, struct image_t *img, struct opticflow_result_t *result) |
Run the optical flow on a new image frame. More... | |
Variables | |
struct MedianFilterInt vel_x_filt | vel_y_filt |
Estimate velocity from optic flow.
Using images from a vertical camera and IMU sensor data.
Definition in file opticflow_calculator.c.
#define FAST9_HIGH_THRESHOLD 60 |
Definition at line 137 of file opticflow_calculator.c.
Referenced by calc_fast9_lukas_kanade().
#define FAST9_LOW_THRESHOLD 5 |
Definition at line 136 of file opticflow_calculator.c.
Referenced by calc_fast9_lukas_kanade().
#define LINEAR_FIT 1 |
Definition at line 56 of file opticflow_calculator.c.
Referenced by calc_fast9_lukas_kanade().
#define OPTICFLOW_DEROTATION TRUE |
Definition at line 149 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_FAST9_ADAPTIVE TRUE |
Definition at line 116 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_FAST9_MIN_DISTANCE 10 |
Definition at line 126 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_FAST9_PADDING 20 |
Definition at line 131 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_FAST9_THRESHOLD 20 |
Definition at line 121 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_FOV_H 0.67020643276 |
Definition at line 65 of file opticflow_calculator.c.
Referenced by calc_edgeflow_tot(), and calc_fast9_lukas_kanade().
#define OPTICFLOW_FOV_W 0.89360857702 |
Definition at line 60 of file opticflow_calculator.c.
Referenced by calc_edgeflow_tot(), and calc_fast9_lukas_kanade().
#define OPTICFLOW_FX 343.1211 |
Definition at line 70 of file opticflow_calculator.c.
Referenced by calc_fast9_lukas_kanade().
#define OPTICFLOW_FY 348.5053 |
Definition at line 75 of file opticflow_calculator.c.
Referenced by calc_fast9_lukas_kanade().
#define OPTICFLOW_MAX_ITERATIONS 10 |
Definition at line 101 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_MAX_TRACK_CORNERS 25 |
Definition at line 81 of file opticflow_calculator.c.
Referenced by calc_fast9_lukas_kanade(), and opticflow_calc_init().
#define OPTICFLOW_MEDIAN_FILTER TRUE |
Definition at line 154 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_METHOD 0 |
Definition at line 140 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_PYRAMID_LEVEL 0 |
Definition at line 111 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_SEARCH_DISTANCE 20 |
Definition at line 91 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_SHOW_CORNERS 0 |
Definition at line 49 of file opticflow_calculator.c.
#define OPTICFLOW_SHOW_FLOW 0 |
Definition at line 48 of file opticflow_calculator.c.
#define OPTICFLOW_SUBPIXEL_FACTOR 10 |
Definition at line 96 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_THRESHOLD_VEC 2 |
Definition at line 106 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define OPTICFLOW_WINDOW_SIZE 10 |
Definition at line 86 of file opticflow_calculator.c.
Referenced by opticflow_calc_init().
#define SIZE_DIV 1 |
Definition at line 53 of file opticflow_calculator.c.
Referenced by calc_fast9_lukas_kanade().
void calc_edgeflow_tot | ( | struct opticflow_t * | opticflow, |
struct opticflow_state_t * | state, | ||
struct image_t * | img, | ||
struct opticflow_result_t * | result | ||
) |
Run the optical flow with EDGEFLOW on a new image frame.
[in] | *opticflow | The opticalflow structure that keeps track of previous images |
[in] | *state | The state of the drone |
[in] | *img | The image frame to calculate the optical flow from |
[out] | *result | The optical flow result |
Definition at line 404 of file opticflow_calculator.c.
References opticflow_state_t::agl, calc_previous_frame_nr(), calculate_edge_displacement(), calculate_edge_histogram(), opticflow_result_t::corner_cnt, opticflow_t::derotation, DISP_RANGE_MAX, opticflow_result_t::div_size, edge_flow_t::div_x, edge_flow_t::div_y, opticflow_result_t::divergence, draw_edgeflow_img(), FLOAT_RATES_ZERO, opticflow_result_t::flow_der_x, opticflow_result_t::flow_der_y, opticflow_result_t::flow_x, edge_flow_t::flow_x, opticflow_result_t::flow_y, edge_flow_t::flow_y, opticflow_result_t::fps, edge_hist_t::frame_time, getAmountPeaks(), image_t::h, opticflow_t::just_switched_method, line_fit(), MAX_HORIZON, MAX_WINDOW_SIZE, opticflow_t::median_filter, opticflow_result_t::noise_measurement, OPTICFLOW_FOV_H, OPTICFLOW_FOV_W, FloatRates::p, FloatRates::q, opticflow_state_t::rates, edge_hist_t::rates, RES, opticflow_t::search_distance, opticflow_t::subpixel_factor, opticflow_result_t::surface_roughness, timeval_diff(), opticflow_result_t::tracked_cnt, image_t::ts, update_median_filter(), opticflow_result_t::vel_x, opticflow_result_t::vel_y, vel_y_filt, image_t::w, opticflow_t::window_size, edge_hist_t::x, edgeflow_displacement_t::x, edge_hist_t::y, and edgeflow_displacement_t::y.
Referenced by opticflow_calc_frame().
void calc_fast9_lukas_kanade | ( | struct opticflow_t * | opticflow, |
struct opticflow_state_t * | state, | ||
struct image_t * | img, | ||
struct opticflow_result_t * | result | ||
) |
Run the optical flow with fast9 and lukaskanade on a new image frame.
[in] | *opticflow | The opticalflow structure that keeps track of previous images |
[in] | *state | The state of the drone |
[in] | *img | The image frame to calculate the optical flow from |
[out] | *result | The optical flow result |
Definition at line 218 of file opticflow_calculator.c.
References opticflow_state_t::agl, analyze_linear_flow_field(), cmp_flow(), opticflow_result_t::corner_cnt, opticflow_t::derotation, opticflow_result_t::div_size, linear_flow_fit_info::divergence, opticflow_result_t::divergence, opticflow_t::fast9_adaptive, fast9_detect(), FAST9_HIGH_THRESHOLD, FAST9_LOW_THRESHOLD, opticflow_t::fast9_min_distance, opticflow_t::fast9_padding, opticflow_t::fast9_ret_corners, opticflow_t::fast9_rsize, opticflow_t::fast9_threshold, opticflow_result_t::flow_der_x, opticflow_result_t::flow_der_y, opticflow_result_t::flow_x, flow_t::flow_x, opticflow_result_t::flow_y, flow_t::flow_y, opticflow_result_t::fps, get_size_divergence(), opticflow_t::got_first_img, image_t::h, image_copy(), image_show_flow(), image_show_points(), image_switch(), image_to_grayscale(), opticflow_t::img_gray, opticflow_t::just_switched_method, LINEAR_FIT, opticflow_t::max_iterations, opticflow_t::max_track_corners, opticflow_t::median_filter, opticflow_result_t::noise_measurement, opticflow_calc_init(), OPTICFLOW_FOV_H, OPTICFLOW_FOV_W, OPTICFLOW_FX, OPTICFLOW_FY, OPTICFLOW_MAX_TRACK_CORNERS, opticFlowLK(), FloatRates::p, opticflow_t::prev_img_gray, opticflow_t::prev_rates, opticflow_t::prev_timestamp, opticflow_t::pyramid_level, FloatRates::q, opticflow_state_t::rates, SIZE_DIV, opticflow_t::subpixel_factor, linear_flow_fit_info::surface_roughness, opticflow_result_t::surface_roughness, opticflow_t::threshold_vec, timeval_diff(), opticflow_result_t::tracked_cnt, image_t::ts, update_median_filter(), opticflow_result_t::vel_x, opticflow_result_t::vel_y, vel_y_filt, image_t::w, and opticflow_t::window_size.
Referenced by opticflow_calc_frame().
|
static |
Compare two flow vectors based on flow distance Used for sorting.
[in] | *a | The first flow vector (should be vect flow_t) |
[in] | *b | The second flow vector (should be vect flow_t) |
Definition at line 611 of file opticflow_calculator.c.
References flow_t::flow_x, and flow_t::flow_y.
Referenced by calc_fast9_lukas_kanade().
void opticflow_calc_frame | ( | struct opticflow_t * | opticflow, |
struct opticflow_state_t * | state, | ||
struct image_t * | img, | ||
struct opticflow_result_t * | result | ||
) |
Run the optical flow on a new image frame.
[in] | *opticflow | The opticalflow structure that keeps track of previous images |
[in] | *state | The state of the drone |
[in] | *img | The image frame to calculate the optical flow from |
[out] | *result | The optical flow result |
Definition at line 567 of file opticflow_calculator.c.
References calc_edgeflow_tot(), calc_fast9_lukas_kanade(), opticflow_t::just_switched_method, and opticflow_t::method.
Referenced by opticflow_module_calc().
void opticflow_calc_init | ( | struct opticflow_t * | opticflow, |
uint16_t | w, | ||
uint16_t | h | ||
) |
Initialize the opticflow calculator.
[out] | *opticflow | The new optical flow calculator |
[in] | *w | The image width |
[in] | *h | The image height |
Definition at line 175 of file opticflow_calculator.c.
References opticflow_t::derotation, opticflow_t::fast9_adaptive, opticflow_t::fast9_min_distance, opticflow_t::fast9_padding, opticflow_t::fast9_ret_corners, opticflow_t::fast9_rsize, opticflow_t::fast9_threshold, FLOAT_RATES_ZERO, opticflow_t::got_first_img, image_create(), IMAGE_GRAYSCALE, opticflow_t::img_gray, init_median_filter(), opticflow_t::max_iterations, opticflow_t::max_track_corners, opticflow_t::median_filter, opticflow_t::method, OPTICFLOW_DEROTATION, OPTICFLOW_FAST9_ADAPTIVE, OPTICFLOW_FAST9_MIN_DISTANCE, OPTICFLOW_FAST9_PADDING, OPTICFLOW_FAST9_THRESHOLD, OPTICFLOW_MAX_ITERATIONS, OPTICFLOW_MAX_TRACK_CORNERS, OPTICFLOW_MEDIAN_FILTER, OPTICFLOW_METHOD, OPTICFLOW_PYRAMID_LEVEL, OPTICFLOW_SEARCH_DISTANCE, OPTICFLOW_SUBPIXEL_FACTOR, OPTICFLOW_THRESHOLD_VEC, OPTICFLOW_WINDOW_SIZE, opticflow_t::prev_img_gray, opticflow_t::prev_rates, opticflow_t::pyramid_level, opticflow_t::search_distance, opticflow_t::subpixel_factor, opticflow_t::threshold_vec, vel_y_filt, and opticflow_t::window_size.
Referenced by calc_fast9_lukas_kanade().
|
static |
Calculate the difference from start till finish.
[in] | *starttime | The start time to calculate the difference from |
[in] | *finishtime | The finish time to calculate the difference from |
Definition at line 596 of file opticflow_calculator.c.
Referenced by calc_edgeflow_tot(), and calc_fast9_lukas_kanade().
struct MedianFilterInt vel_x_filt vel_y_filt |
Definition at line 160 of file opticflow_calculator.c.
Referenced by calc_edgeflow_tot(), calc_fast9_lukas_kanade(), and opticflow_calc_init().