52 float mean_divergence;
63 n_elements = (count * count -
count) / 2;
64 divs = (
float *) malloc(
sizeof(
float) * n_elements);
68 for (i = 0; i <
count; i++) {
69 for (j = i + 1; j <
count; j++) {
71 dx = (float)vectors[i].pos.x - (
float)vectors[j].
pos.
x;
72 dy = (float)vectors[i].pos.y - (
float)vectors[j].
pos.
y;
73 distance_1 = sqrt(dx * dx + dy * dy);
76 dx = (float)vectors[i].pos.x + (
float)vectors[i].
flow_x - (float)vectors[j].pos.x - (
float)vectors[j].
flow_x;
77 dy = (float)vectors[i].pos.y + (
float)vectors[i].
flow_y - (float)vectors[j].pos.y - (
float)vectors[j].
flow_y;
78 distance_2 = sqrt(dx * dx + dy * dy);
81 divs[sample] = (distance_2 - distance_1) / distance_1;
87 mean_divergence =
get_mean(divs, n_elements);
93 divs = (
float *) malloc(
sizeof(
float) * n_samples);
96 for (sample = 0; sample < n_samples; sample++) {
106 dx = (float)vectors[i].pos.x - (
float)vectors[j].
pos.
x;
107 dy = (float)vectors[i].pos.y - (
float)vectors[j].
pos.
y;
108 distance_1 = sqrt(dx * dx + dy * dy);
111 dx = (float)vectors[i].pos.x + (
float)vectors[i].
flow_x - (float)vectors[j].pos.x - (
float)vectors[j].
flow_x;
112 dy = (float)vectors[i].pos.y + (
float)vectors[i].
flow_y - (float)vectors[j].pos.y - (
float)vectors[j].
flow_y;
113 distance_2 = sqrt(dx * dx + dy * dy);
117 divs[sample] = (distance_2 - distance_1) / distance_1;
121 mean_divergence =
get_mean(divs, n_samples);
127 return mean_divergence;
140 for (i = 0; i < n_elements; i++) {
float get_mean(float *numbers, int n_elements)
Get the sample mean of a vector of floats.
Calculate divergence from flow vectors by looking at line sizes beteween the points.
uint32_t x
The x coordinate of the point.
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.
int16_t flow_x
The x direction flow in subpixels.
struct point_t pos
The original position the flow comes from.
uint32_t y
The y coordinate of the point.
uint16_t count
Number of times the point has been tracked successfully.
int16_t flow_y
The y direction flow in subpixels.