Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
opticflow_calculator.h File Reference

Calculate velocity from optic flow. More...

#include "std.h"
#include "inter_thread_data.h"
#include "lib/vision/image.h"
#include "lib/v4l/v4l2.h"
+ Include dependency graph for opticflow_calculator.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  opticflow_t
 

Functions

void opticflow_calc_init (struct opticflow_t *opticflow)
 Initialize the opticflow calculator. 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...
 
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 kalman_filter_opticflow_velocity (float *velocity_x, float *velocity_y, float *acceleration_measurement, float fps, float *measurement_noise, float process_noise, bool reinitialize_kalman)
 Filter the velocity with a simple linear kalman filter, together with the accelerometers. More...
 

Detailed Description

Calculate velocity from optic flow.

Using images from a vertical camera and IMU sensor data.

Definition in file opticflow_calculator.h.


Data Structure Documentation

struct opticflow_t

Definition at line 40 of file opticflow_calculator.h.

+ Collaboration diagram for opticflow_t:
Data Fields
bool derotation Derotation switched on or off (depended on the quality of the gyroscope measurement)
float derotation_correction_factor_x Correction factor for derotation in x axis, determined from a fit from the gyros and flow rotation. (wrong FOV, camera not in center)
float derotation_correction_factor_y Correction factor for derotation in Y axis, determined from a fit from the gyros and flow rotation. (wrong FOV, camera not in center)
bool fast9_adaptive Whether the FAST9 threshold should be adaptive.
uint16_t fast9_min_distance Minimum distance in pixels between corners.
uint8_t fast9_num_regions The number of regions of interest the image is split into.
uint16_t fast9_padding Padding used in FAST9 detector.
bool fast9_region_detect Decides whether to detect fast9 corners in specific regions of interest or the whole image (only for feature management)
struct point_t * fast9_ret_corners Corners.
uint16_t fast9_rsize Amount of corners allocated.
uint8_t fast9_threshold FAST9 corner detection threshold.
bool feature_management Decides whether to keep track corners in memory for the next frame instead of re-detecting every time.
bool got_first_img If we got a image to work with.
struct image_t img_gray Current gray image frame.
bool just_switched_method Boolean to check if methods has been switched (for reinitialization)
bool kalman_filter Decide to use Kalman filter to filter velocity with accelerometers.
float kalman_filter_process_noise Process noise of the model used in the kalman filter.
uint8_t max_iterations The maximum amount of iterations the Lucas Kanade algorithm should do.
uint8_t max_track_corners Maximum amount of corners Lucas Kanade should track.
bool median_filter Decides to use a median filter on the velocity.
uint8_t method Method to use to calculate the optical flow.
struct image_t prev_img_gray Previous gray image frame.
struct FloatRates prev_rates Gyro Rates from the previous image frame.
struct timeval prev_timestamp Timestamp of the previous frame, used for FPS calculation.
uint8_t pyramid_level Number of pyramid levels used in Lucas Kanade algorithm (0 == no pyramids used)
uint16_t resolution_factor The resolution in EdgeFlow to determine the Divergence.
uint16_t search_distance Search distance for blockmatching alg.
uint16_t subpixel_factor The amount of subpixels per pixel.
uint8_t threshold_vec The threshold in x, y subpixels which the algorithm should stop.
uint16_t window_size Window size for the blockmatching algorithm (general value for all methods)

Function Documentation

void calc_edgeflow_tot ( struct opticflow_t opticflow,
struct opticflow_state_t cam_state,
struct image_t img,
struct opticflow_result_t result 
)

Run the optical flow with EDGEFLOW on a new image frame.

Parameters
[in]*opticflowThe opticalflow structure that keeps track of previous images
[in]*stateThe state of the drone
[in]*imgThe image frame to calculate the optical flow from
[out]*resultThe optical flow result

Definition at line 519 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, opticflow_t::derotation_correction_factor_x, opticflow_t::derotation_correction_factor_y, 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, opticflow_state_t::rates, edge_hist_t::rates, RES, opticflow_t::resolution_factor, opticflow_t::search_distance, opticflow_result_t::surface_roughness, timeval_diff(), opticflow_result_t::tracked_cnt, image_t::ts, update_median_filter_i(), 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void calc_fast9_lukas_kanade ( struct opticflow_t opticflow,
struct opticflow_state_t cam_state,
struct image_t img,
struct opticflow_result_t result 
)

Run the optical flow with fast9 and lukaskanade on a new image frame.

Parameters
[in]*opticflowThe opticalflow structure that keeps track of previous images
[in]*stateThe state of the drone
[in]*imgThe image frame to calculate the optical flow from
[out]*resultThe optical flow result

Definition at line 256 of file opticflow_calculator.c.

References opticflow_state_t::agl, analyze_linear_flow_field(), cmp_array(), cmp_flow(), opticflow_result_t::corner_cnt, point_t::count, opticflow_t::derotation, opticflow_t::derotation_correction_factor_x, opticflow_t::derotation_correction_factor_y, 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_num_regions, opticflow_t::fast9_padding, opticflow_t::fast9_region_detect, opticflow_t::fast9_ret_corners, opticflow_t::fast9_rsize, opticflow_t::fast9_threshold, opticflow_t::feature_management, FLOAT_RATES_ZERO, 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_create(), IMAGE_GRAYSCALE, image_show_flow(), image_show_points(), image_switch(), image_to_grayscale(), opticflow_t::img_gray, init_median_filter_i(), opticflow_t::just_switched_method, LINEAR_FIT, opticflow_t::max_iterations, opticflow_t::max_track_corners, MEDIAN_DEFAULT_SIZE, opticflow_t::median_filter, opticflow_result_t::noise_measurement, OPTICFLOW_FOV_H, OPTICFLOW_FOV_W, OPTICFLOW_FX, OPTICFLOW_FY, OPTICFLOW_MAX_TRACK_CORNERS, opticFlowLK(), FloatRates::p, flow_t::pos, 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_i(), opticflow_result_t::vel_x, opticflow_result_t::vel_y, vel_y_filt, image_t::w, opticflow_t::window_size, point_t::x, point_t::x_sub, point_t::y, and point_t::y_sub.

Referenced by opticflow_calc_frame().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void kalman_filter_opticflow_velocity ( float *  velocity_x,
float *  velocity_y,
float *  acceleration_measurement,
float  fps,
float *  measurement_noise,
float  kalman_process_noise,
bool  reinitialize_kalman 
)

Filter the velocity with a simple linear kalman filter, together with the accelerometers.

Parameters
[in]*velocity_xVelocity in x direction of body fixed coordinates
[in]*velocity_yBelocity in y direction of body fixed coordinates
[in]*acceleration_measurementMeasurements of the accelerometers
[in]fpsFrames per second
[in]*measurement_noiseExpected variance of the noise of the measurements
[in]*measurement_noiseExpected variance of the noise of the model prediction
[in]reinitialize_kalmanBoolean to reinitialize the kalman filter

Definition at line 772 of file opticflow_calculator.c.

References kalman_filter_linear_2D_float(), and model.

Referenced by opticflow_calc_frame().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void opticflow_calc_frame ( struct opticflow_t opticflow,
struct opticflow_state_t cam_state,
struct image_t img,
struct opticflow_result_t result 
)

Run the optical flow on a new image frame.

Parameters
[in]*opticflowThe opticalflow structure that keeps track of previous images
[in]*stateThe state of the drone
[in]*imgThe image frame to calculate the optical flow from
[out]*resultThe optical flow result

Definition at line 689 of file opticflow_calculator.c.

References opticflow_state_t::accel_imu_meas, ACCELS_FLOAT_OF_BFP, calc_edgeflow_tot(), calc_fast9_lukas_kanade(), float_quat_vmult(), opticflow_result_t::fps, opticflow_state_t::imu_to_body_quat, opticflow_t::just_switched_method, opticflow_t::kalman_filter, kalman_filter_opticflow_velocity(), opticflow_t::kalman_filter_process_noise, opticflow_t::method, opticflow_result_t::noise_measurement, opticflow_result_t::vel_body_x, opticflow_result_t::vel_body_y, opticflow_result_t::vel_x, opticflow_result_t::vel_y, FloatVect3::x, and FloatVect3::y.

Referenced by opticflow_module_calc().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void opticflow_calc_init ( struct opticflow_t opticflow)

Initialize the opticflow calculator.

Parameters
[out]*opticflowThe new optical flow calculator

Definition at line 219 of file opticflow_calculator.c.

References opticflow_t::derotation, opticflow_t::derotation_correction_factor_x, opticflow_t::derotation_correction_factor_y, opticflow_t::fast9_adaptive, opticflow_t::fast9_min_distance, opticflow_t::fast9_num_regions, opticflow_t::fast9_padding, opticflow_t::fast9_region_detect, opticflow_t::fast9_ret_corners, opticflow_t::fast9_rsize, opticflow_t::fast9_threshold, opticflow_t::feature_management, opticflow_t::kalman_filter, opticflow_t::kalman_filter_process_noise, opticflow_t::max_iterations, opticflow_t::max_track_corners, opticflow_t::median_filter, opticflow_t::method, OPTICFLOW_DEROTATION, OPTICFLOW_DEROTATION_CORRECTION_FACTOR_X, OPTICFLOW_DEROTATION_CORRECTION_FACTOR_Y, OPTICFLOW_FAST9_ADAPTIVE, OPTICFLOW_FAST9_MIN_DISTANCE, OPTICFLOW_FAST9_NUM_REGIONS, OPTICFLOW_FAST9_PADDING, OPTICFLOW_FAST9_REGION_DETECT, OPTICFLOW_FAST9_THRESHOLD, OPTICFLOW_FEATURE_MANAGEMENT, OPTICFLOW_KALMAN_FILTER, OPTICFLOW_KALMAN_FILTER_PROCESS_NOISE, OPTICFLOW_MAX_ITERATIONS, OPTICFLOW_MAX_TRACK_CORNERS, OPTICFLOW_MEDIAN_FILTER, OPTICFLOW_METHOD, OPTICFLOW_PYRAMID_LEVEL, OPTICFLOW_RESOLUTION_FACTOR, OPTICFLOW_SEARCH_DISTANCE, OPTICFLOW_SUBPIXEL_FACTOR, OPTICFLOW_THRESHOLD_VEC, OPTICFLOW_WINDOW_SIZE, opticflow_t::pyramid_level, opticflow_t::resolution_factor, opticflow_t::search_distance, opticflow_t::subpixel_factor, opticflow_t::threshold_vec, and opticflow_t::window_size.

Referenced by opticflow_module_init().

+ Here is the caller graph for this function: