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 += 2) {
125 idx = interlace * (image_width * y + (x + c));
127 sobel_sum += Sobel[c + 1] * (
int32_t)img_buf[
idx];
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 += 2) {
144 idx = interlace * (image_width * (y + c) + x);
146 sobel_sum += Sobel[c + 1] * (
int32_t)img_buf[
idx];
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) {
200 for (x = border[0]; x < border[1]; x++) {
201 if (!SHIFT_TOO_FAR) {
202 for (c = -
D; c <=
D; c++) {
204 for (r = -W; r <= W; r++) {
205 SAD_temp[c +
D] += abs(edge_histogram[x + r] - edge_histogram_prev[x + r + c + der_shift]);
226 for (i = 1; i < n; i++) {
227 if (a[i] <= min_err) {
230 min_err_tot += min_err;
268 int32_t xend = size_int - border_int - 1;
269 sumX = xend * (xend + 1) / 2 - border_int * (border_int + 1) / 2 + border_int;
270 sumX2 = xend * (xend + 1) * (2 * xend + 1) / 6 - border_int * (border_int + 1) * (2 * border_int + 1) / 6 + border_int * border_int;
271 xMean = (size_int - 1) / 2;
272 count = size_int - 2 * border_int;
274 for (x = border_int; x < size_int - border_int; x++) {
275 sumY += displacement[x];
276 sumXY += x * displacement[x];
279 yMean =
RES * sumY / count;
281 divergence_int = (
RES * sumXY - sumX * yMean) / (sumX2 - sumX * xMean);
282 *divergence = divergence_int;
283 *flow = yMean - *divergence * xMean;
285 for (x = border_int; x < size_int - border_int; x++) {
286 total_error += abs(
RES * displacement[x] - divergence_int * x + yMean);
308 for (i = 1; i < img->
w - 1; i++) {
309 point1.
y = -(
uint16_t)edge_hist_x[i] / 100 + img->
h / 3;
311 point2.
y = -(
uint16_t)edge_hist_x[i + 1] / 100 + img->
h / 3;
314 point1_prev.
y = -(
uint16_t)edge_hist_x_prev[i] / 100 + img->
h * 2 / 3;
316 point2_prev.
y = -(
uint16_t)edge_hist_x_prev[i + 1] / 100 + img->
h * 2 / 3;
317 point2_prev.
x = i + 1;
323 point1_extra.
y = (edgeflow.
flow_x + edgeflow.
div_x * img->
w / 2) / 100 + img->
h / 2;
325 point2_extra.
y = (edgeflow.
flow_x + edgeflow.
div_x * img->
w / 2) / 100 + img->
h / 2;
326 point2_extra.
x = img->
w;
342 for (i = 1; i < size + 1; i ++) {
343 if (edgehist[i - 1] < edgehist[i] && edgehist[i] > edgehist[i + 1] && edgehist[i] > thres) {
uint32_t getMinimum(uint32_t *a, uint32_t n)
Calculate minimum of an array.
uint32_t getAmountPeaks(int32_t *edgehist, int32_t thres, int32_t size)
getAmountPeaks, calculates the amount of peaks in a edge histogram
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.
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 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.
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.
calculate optical flow with EdgeFlow
void image_draw_line(struct image_t *img, struct point_t *from, struct point_t *to)
Draw a pink line on the image.
void * buf
Image buffer (depending on the image_type)
uint32_t x
The x coordinate of the point.
uint32_t y
The y coordinate of the point.
@ IMAGE_GRAYSCALE
Grayscale image with only the Y part (uint8 per pixel)
@ IMAGE_YUV422
UYVY format (uint16 per pixel)
int16_t flow_x
Flow in x direction from the camera (in subpixels) with X positive to the right.
int16_t flow_y
Flow in y direction from the camera (in subpixels) with Y positive to the bottom.
uint16_t search_distance
Search distance for blockmatching alg.
struct opticflow_t opticflow[ACTIVE_CAMERAS]
Opticflow calculations.
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.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.