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));
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);
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) {