48 float distance_1, distance_2;
58 }
else if (count >= max_samples) {
63 divs = (
float *) malloc(
sizeof(
float) * max_samples);
66 for (i = 0; i <
count; i++) {
67 for (j = i + 1; j <
count; j++) {
69 dx = (float)vectors[i].pos.x - (
float)vectors[j].
pos.
x;
70 dy = (float)vectors[i].pos.y - (
float)vectors[j].
pos.
y;
71 distance_1 = sqrtf(dx * dx + dy * dy);
74 dx = (float)vectors[i].pos.x + (
float)vectors[i].
flow_x - (float)vectors[j].pos.x - (
float)vectors[j].
flow_x;
75 dy = (float)vectors[i].pos.y + (
float)vectors[i].
flow_y - (float)vectors[j].pos.y - (
float)vectors[j].
flow_y;
76 distance_2 = sqrtf(dx * dx + dy * dy);
79 if (distance_1 > 1
E-5) {
80 divs[used_samples] = (distance_2 - distance_1) / distance_1;
86 divs = (
float *) malloc(
sizeof(
float) *
n_samples);
99 dx = (float)vectors[i].pos.x - (
float)vectors[j].
pos.
x;
100 dy = (float)vectors[i].pos.y - (
float)vectors[j].
pos.
y;
101 distance_1 = sqrt(dx * dx + dy * dy);
104 dx = (float)vectors[i].pos.x + (
float)vectors[i].
flow_x - (float)vectors[j].pos.x - (
float)vectors[j].
flow_x;
105 dy = (float)vectors[i].pos.y + (
float)vectors[i].
flow_y - (float)vectors[j].pos.y - (
float)vectors[j].
flow_y;
106 distance_2 = sqrt(dx * dx + dy * dy);
110 if (distance_1 > 1
E-5) {
111 divs[used_samples] = (distance_2 - distance_1) / distance_1;
118 float mean_divergence =
mean_f(divs, used_samples);
124 return mean_divergence;
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.
float mean_f(float *array, uint32_t n_elements)
Compute the mean value of an array (float)
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.