49 flow_mag_x = abs(result->
flow_x);
50 flow_mag_y = abs(result->
flow_y);
54 uint8_t previous_frame_offset_x = previous_frame_offset[0];
55 uint8_t previous_frame_offset_y = previous_frame_offset[1];
60 if (flow_mag_x > max_flow && previous_frame_offset_x > 1) {
61 previous_frame_offset[0] = previous_frame_offset_x - 1;
63 if (flow_mag_x < min_flow && previous_frame_offset_x <
MAX_HORIZON - 1) {
64 previous_frame_offset[0] = previous_frame_offset_x + 1;
66 if (flow_mag_y > max_flow && previous_frame_offset_y > 1) {
67 previous_frame_offset[1] = previous_frame_offset_y - 1;
69 if (flow_mag_y < min_flow && previous_frame_offset_y <
MAX_HORIZON - 1) {
70 previous_frame_offset[1] = previous_frame_offset_y + 1;
75 previous_frame_nr[0] = (current_frame_nr - previous_frame_offset[0] +
MAX_HORIZON) %
77 previous_frame_nr[1] = (current_frame_nr - previous_frame_offset[1] +
MAX_HORIZON) %
118 edge_histogram[0] = edge_histogram[image_width - 1] = 0;
119 for (x = 1; x < image_width - 1; x++) {
120 edge_histogram[x] = 0;
121 for (y = 0; y < image_height; y++) {
124 for (c = -1; c <= 1; c++) {
125 idx = interlace * (image_width * y + (x + c));
127 sobel_sum += Sobel[c + 1] * (
int32_t)img_buf[
idx + 1];
129 sobel_sum = abs(sobel_sum);
130 if (sobel_sum > edge_threshold) {
131 edge_histogram[x] += sobel_sum;
137 edge_histogram[0] = edge_histogram[image_height - 1] = 0;
138 for (y = 1; y < image_height - 1; y++) {
139 edge_histogram[y] = 0;
140 for (x = 0; x < image_width; x++) {
143 for (c = -1; c <= 1; c++) {
144 idx = interlace * (image_width * (y + c) + x);
146 sobel_sum += Sobel[c + 1] * (
int32_t)img_buf[
idx + 1];
148 sobel_sum = abs(sobel_sum);
149 if (sobel_sum > edge_threshold) {
150 edge_histogram[y] += sobel_sum;
181 memset(displacement, 0,
sizeof(
int32_t)*size);
186 border[0] = W + D + der_shift;
187 border[1] = size - W - D;
188 }
else if (der_shift > 0) {
190 border[1] = size - W - D - der_shift;
193 border[1] = size - W - D;
196 if (border[0] >= border[1] || abs(der_shift) >= 10) {
201 for (x = border[0]; x < border[1]; x++) {
203 if (!SHIFT_TOO_FAR) {
204 for (c = -D; c <= D; c++) {
206 for (r = -W; r <= W; r++) {
207 SAD_temp[c + D] += abs(edge_histogram[x + r] - edge_histogram_prev[x + r + c + der_shift]);
230 for (i = 1; i < n; i++) {
231 if (a[i] <= min_err) {
234 min_err_tot += min_err;
272 int32_t xend = size_int - border_int - 1;
273 sumX = xend * (xend + 1) / 2 - border_int * (border_int + 1) / 2 + border_int;
274 sumX2 = xend * (xend + 1) * (2 * xend + 1) / 6;
275 xMean = (size_int - 1) / 2;
276 count = size_int - 2 * border_int;
278 for (x = border_int; x < size - border_int; x++) {
279 sumY += displacement[x];
280 sumXY += x * displacement[x];
283 yMean = RES * sumY / count;
285 divergence_int = (RES * sumXY - sumX * yMean) / (sumX2 - sumX * xMean);
286 *divergence = divergence_int;
287 *flow = yMean - *divergence * xMean;
289 for (x = border_int; x < size - border_int; x++) {
290 total_error += abs(RES * displacement[x] - divergence_int * x + yMean);
312 for (i = 1; i < img->
w - 1; i++) {
313 point1.
y = -(
uint16_t)edge_hist_x[i] / 100 + img->
h / 3;
315 point2.
y = -(
uint16_t)edge_hist_x[i + 1] / 100 + img->
h / 3;
318 point1_prev.
y = -(
uint16_t)edge_hist_x_prev[i] / 100 + img->
h * 2 / 3;
320 point2_prev.
y = -(
uint16_t)edge_hist_x_prev[i + 1] / 100 + img->
h * 2 / 3;
321 point2_prev.
x = i + 1;
327 point1_extra.
y = (edgeflow.
flow_x + edgeflow.
div_x * img->
w / 2) / 100 + img->
h / 2;
329 point2_extra.
y = (edgeflow.
flow_x + edgeflow.
div_x * img->
w / 2) / 100 + img->
h / 2;
330 point2_extra.
x = img->
w;
346 for (i = 1; i < size + 1; i ++) {
347 if (edgehist[i - 1] < edgehist[i] && edgehist[i] > edgehist[i + 1] && edgehist[i] > thres) {
int16_t flow_y
Flow in y direction from the camera (in subpixels)
void calculate_edge_displacement(int32_t *edge_histogram, int32_t *edge_histogram_prev, int32_t *displacement, uint16_t size, uint8_t window, uint8_t disp_range, int32_t der_shift)
Calculate_displacement calculates the displacement between two histograms.
struct opticflow_t opticflow
Opticflow calculations.
calculate optical flow with EdgeFlow
void draw_edgeflow_img(struct image_t *img, struct edge_flow_t edgeflow, int32_t *edge_hist_x_prev, int32_t *edge_hist_x)
Draws edgehistogram, displacement and linefit directly on the image for debugging (only for edgeflow ...
void image_draw_line(struct image_t *img, struct point_t *from, struct point_t *to)
Draw a line on the image.
uint32_t x
The x coordinate of the point.
void calculate_edge_histogram(struct image_t *img, int32_t edge_histogram[], char direction, uint16_t edge_threshold)
Calculate a edge/gradient histogram for each dimension of the image.
uint32_t getMinimum(uint32_t *a, uint32_t n)
Calculate minimum of an array.
void * buf
Image buffer (depending on the image_type)
uint32_t y
The y coordinate of the point.
UYVY format (uint16 per pixel)
Grayscale image with only the Y part (uint8 per pixel)
void line_fit(int32_t *displacement, int32_t *divergence, int32_t *flow, uint32_t size, uint32_t border, uint16_t RES)
Fits a linear model to an array with pixel displacements with least squares.
void calc_previous_frame_nr(struct opticflow_result_t *result, struct opticflow_t *opticflow, uint8_t current_frame_nr, uint8_t *previous_frame_offset, uint8_t *previous_frame_nr)
Calc_previous_frame_nr; adaptive Time Horizon.
int16_t flow_x
Flow in x direction from the camera (in subpixels)
uint32_t getAmountPeaks(int32_t *edgehist, uint32_t thres, int32_t size)
getAmountPeaks, calculates the amount of peaks in a edge histogram
uint16_t search_distance
Search distance for blockmatching alg.