54 #ifndef OPTICFLOW_FOV_W
55 #define OPTICFLOW_FOV_W 0.89360857702
59 #ifndef OPTICFLOW_FOV_H
60 #define OPTICFLOW_FOV_H 0.67020643276
65 #define OPTICFLOW_FX 343.1211
70 #define OPTICFLOW_FY 348.5053
75 #ifndef OPTICFLOW_MAX_TRACK_CORNERS
76 #define OPTICFLOW_MAX_TRACK_CORNERS 25
80 #ifndef OPTICFLOW_WINDOW_SIZE
81 #define OPTICFLOW_WINDOW_SIZE 10
85 #ifndef OPTICFLOW_SUBPIXEL_FACTOR
86 #define OPTICFLOW_SUBPIXEL_FACTOR 10
90 #ifndef OPTICFLOW_MAX_ITERATIONS
91 #define OPTICFLOW_MAX_ITERATIONS 10
95 #ifndef OPTICFLOW_THRESHOLD_VEC
96 #define OPTICFLOW_THRESHOLD_VEC 2
100 #ifndef OPTICFLOW_FAST9_ADAPTIVE
101 #define OPTICFLOW_FAST9_ADAPTIVE TRUE
105 #ifndef OPTICFLOW_FAST9_THRESHOLD
106 #define OPTICFLOW_FAST9_THRESHOLD 20
110 #ifndef OPTICFLOW_FAST9_MIN_DISTANCE
111 #define OPTICFLOW_FAST9_MIN_DISTANCE 10
117 static
int cmp_flow(const
void *a, const
void *b);
132 opticflow->got_first_img =
FALSE;
133 opticflow->prev_phi = 0.0;
134 opticflow->prev_theta = 0.0;
159 float size_divergence;
int n_samples;
162 float error_threshold;
int n_iterations_RANSAC, n_samples_RANSAC, success_fit;
struct linear_flow_fit_info fit_info;
196 #if OPTICFLOW_DEBUG && OPTICFLOW_SHOW_CORNERS
217 #if OPTICFLOW_DEBUG && OPTICFLOW_SHOW_FLOW
231 error_threshold = 10.0f;
232 n_iterations_RANSAC = 20;
233 n_samples_RANSAC = 5;
235 n_samples_RANSAC, img->
w, img->
h, &fit_info);
291 result->
vel_x = vel_ver;
292 result->
vel_y = - vel_hor;
319 msec = (finishtime->tv_sec - starttime->tv_sec) * 1000;
320 msec += (finishtime->tv_usec - starttime->tv_usec) / 1000;
int16_t flow_y
Flow in y direction from the camera (in subpixels)
uint16_t fast9_min_distance
Minimum distance in pixels between corners.
int16_t flow_der_y
The derotated flow calculation in the y direction (in subpixels)
float div_size
Divergence as determined with the size_divergence script.
uint8_t max_iterations
The maximum amount of iterations the Lucas Kanade algorithm should do.
struct opticflow_t opticflow
Opticflow calculations.
uint16_t window_size
Window size of the Lucas Kanade calculation (needs to be even)
void image_switch(struct image_t *a, struct image_t *b)
This will switch image *a and *b This is faster as image_copy because it doesn't copy the whole image...
void opticflow_calc_init(struct opticflow_t *opticflow, uint16_t w, uint16_t h)
Initialize the opticflow calculator.
Calculate velocity from optic flow.
void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type)
Create a new image.
#define OPTICFLOW_THRESHOLD_VEC
#define OPTICFLOW_FAST9_MIN_DISTANCE
void image_copy(struct image_t *input, struct image_t *output)
Copy an image from inut to output This will only work if the formats are the same.
#define OPTICFLOW_FAST9_ADAPTIVE
float prev_phi
Phi from the previous image frame.
void image_show_points(struct image_t *img, struct point_t *points, uint16_t points_cnt)
Show points in an image by coloring them through giving the pixels the maximum value.
static int cmp_flow(const void *a, const void *b)
Compare two flow vectors based on flow distance Used for sorting.
Calculate divergence from flow vectors by looking at line sizes beteween the points.
uint8_t threshold_vec
The threshold in x, y subpixels which the algorithm should stop.
void image_show_flow(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor)
Shows the flow from a specific point to a new point This works on YUV422 and Grayscale images...
uint8_t max_track_corners
Maximum amount of corners Lucas Kanade should track.
float agl
height above ground [m]
float get_size_divergence(struct flow_t *vectors, int count, int n_samples)
Get divergence from optical flow vectors based on line sizes between corners.
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.
struct point_t * fast9_detect(struct image_t *img, uint8_t threshold, uint16_t min_dist, uint16_t x_padding, uint16_t y_padding, uint16_t *num_corners)
Do a FAST9 corner detection.
Image helper functions like resizing, color filter, converters...
uint16_t tracked_cnt
The amount of tracked corners.
bool_t got_first_img
If we got a image to work with.
int16_t flow_x
The x direction flow in subpixels.
struct timeval prev_timestamp
Timestamp of the previous frame, used for FPS calculation.
#define OPTICFLOW_FAST9_THRESHOLD
struct image_t prev_img_gray
Previous gray image frame.
uint8_t fast9_threshold
FAST9 corner detection threshold.
#define OPTICFLOW_WINDOW_SIZE
void image_to_grayscale(struct image_t *input, struct image_t *output)
Convert an image to grayscale.
bool_t fast9_adaptive
Whether the FAST9 threshold should be adaptive.
struct image_t img_gray
Current gray image frame.
float vel_x
The velocity in the x direction.
uint8_t subpixel_factor
The amount of subpixels per pixel.
uint16_t corner_cnt
The amount of coners found by FAST9.
float vel_y
The velocity in the y direction.
float fps
Frames per second of the optical flow calculation.
efficient fixed-point optical-flow calculation
int analyze_linear_flow_field(struct flow_t *vectors, int count, float error_threshold, int n_iterations, int n_samples, int im_width, int im_height, struct linear_flow_fit_info *info)
Analyze a linear flow field, retrieving information such as divergence, surface roughness, focus of expansion, etc.
struct timeval ts
The timestamp of creation.
float divergence
Basically, relative_velocity_z. Actual divergence of a 2D flow field is 2 * relative_velocity_z.
float surface_roughness
The error of the linear fit is a measure of surface roughness.
float prev_theta
Theta from the previous image frame.
Grayscale image with only the Y part (uint8 per pixel)
static uint32_t timeval_diff(struct timeval *starttime, struct timeval *finishtime)
Calculate the difference from start till finish.
#define OPTICFLOW_MAX_TRACK_CORNERS
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, uint16_t max_points)
Compute the optical flow of several points using the Lucas-Kanade algorithm by Yves Bouguet The initi...
#define OPTICFLOW_SUBPIXEL_FACTOR
int16_t flow_x
Flow in x direction from the camera (in subpixels)
#define OPTICFLOW_MAX_ITERATIONS
float noise_measurement
noise of measurement, for state filter
int16_t flow_y
The y direction flow in subpixels.
float divergence
Divergence as determined with a linear flow fit.
float surface_roughness
Surface roughness as determined with a linear optical flow fit.
int16_t flow_der_x
The derotated flow calculation in the x direction (in subpixels)