44 float distance_1, distance_2;
50 int32_t max_samples = (count * count - count) / 2;
54 }
else if (count >= max_samples) {
60 for (i = 0; i < count; i++) {
61 for (j = i + 1; j < count; j++) {
63 dx = (float)vectors[i].pos.x - (
float)vectors[j].
pos.
x;
64 dy = (float)vectors[i].pos.y - (
float)vectors[j].
pos.
y;
65 distance_1 = sqrtf(dx * dx + dy * dy);
67 if (distance_1 < 1
E-5) {
72 dx = (float)vectors[i].pos.x + (
float)vectors[i].
flow_x - (float)vectors[j].pos.x - (
float)vectors[j].
flow_x;
73 dy = (float)vectors[i].pos.y + (
float)vectors[i].
flow_y - (float)vectors[j].pos.y - (
float)vectors[j].
flow_y;
74 distance_2 = sqrtf(dx * dx + dy * dy);
76 divs_sum += (distance_2 - distance_1) / distance_1;
92 dx = (float)vectors[i].pos.x - (
float)vectors[j].
pos.
x;
93 dy = (float)vectors[i].pos.y - (
float)vectors[j].
pos.
y;
94 distance_1 = sqrtf(dx * dx + dy * dy);
96 if (distance_1 < 1
E-5) {
101 dx = (float)vectors[i].pos.x + (
float)vectors[i].
flow_x - (float)vectors[j].pos.x - (
float)vectors[j].
flow_x;
102 dy = (float)vectors[i].pos.y + (
float)vectors[i].
flow_y - (float)vectors[j].pos.y - (
float)vectors[j].
flow_y;
103 distance_2 = sqrtf(dx * dx + dy * dy);
105 divs_sum += (distance_2 - distance_1) / distance_1;
110 if (used_samples < 1){
115 return divs_sum / used_samples;
uint32_t x
The x coordinate of the point.
uint32_t y
The y coordinate of the point.
struct point_t pos
The original position the flow comes from in subpixels.
int32_t flow_y
The y direction flow in subpixels.
int32_t flow_x
The x direction flow in subpixels.
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.
Calculate divergence from flow vectors by looking at line sizes beteween the points.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.