28 #define N_WINDOW_SIZES 1
34 #ifndef DETECT_WINDOW_FPS
35 #define DETECT_WINDOW_FPS 0
41 #ifdef DETECT_WINDOW_CAMERA
44 #warning "DETECT_WINDOW_CAMERA not defined, CV callback not added to device"
52 coordinate[0] = 0; coordinate[1] = 0;
61 printf(
"Coordinate: %d, %d\n", coordinate[0], coordinate[1]);
62 printf(
"Response = %d\n", response);
73 uint8_t calculate_integral_image = 1;
85 calculate_integral_image = (
s == 0);
87 calculate_integral_image, integral_image, MODE);
88 if (
s == 0 || best_response[
s] < best_response[best_index]) {
90 best_xc = coordinate[0];
91 best_yc = coordinate[1];
95 coordinate[0] = best_xc;
96 coordinate[1] = best_yc;
97 return best_response[best_index];
115 uint16_t window_size, border_size, feature_size, px_whole, px_inner, px_border, px_outer;
124 if (calculate_integral_image) {
129 window_size = (*size);
130 border_size = (relative_border * window_size) / 100;
131 feature_size = window_size + 2 * border_size;
132 px_inner = feature_size - 2 * border_size;
133 px_inner = px_inner * px_inner;
134 px_whole = feature_size * feature_size;
135 px_border = px_whole - px_inner;
136 px_outer = border_size * window_size;
139 for (x = 0; x < image_width - feature_size; x++) {
140 for (y = 0; y < image_height - feature_size; y++) {
141 response =
get_window_response(x, y, feature_size, border_size, integral_image, image_width, image_height, px_inner,
144 if (response <
RES) {
147 response =
get_border_response(x, y, feature_size, window_size, border_size, integral_image, image_width, image_height,
151 if (response < min_response) {
154 min_response = response;
165 coordinate[0] += feature_size / 2;
166 coordinate[1] += feature_size / 2;
180 cell_width = (image_width - 2 * border) / n_cells;
181 cell_height = (image_height - 2 * border) / n_cells;
183 for (
c = 0;
c < n_cells;
c++) {
184 for (r = 0; r < n_cells; r++) {
185 avg =
get_avg_disparity(
c * cell_width + border, r * cell_height + border, (
c + 1) * cell_width + border,
186 (r + 1) * cell_height + border, integral_image, image_width, image_height);
195 if (min_avg == 10000) {
196 escape_coordinate[0] = image_width / 2;
197 escape_coordinate[1] = image_height / 2;
199 escape_coordinate[0] = min_c * cell_width + border + cell_width / 2;
200 escape_coordinate[1] = min_r * cell_height + border + cell_height / 2;
209 for (x = 0; x < image_width; x++) {
210 for (y = 0; y < image_height; y++) {
211 if (x >= 1 && y >= 1) {
212 integral_image[x + y * image_width] = (
uint32_t) in[x + y * image_width] + integral_image[x - 1 + y * image_width] +
213 integral_image[x + (y - 1) * image_width] - integral_image[x - 1 + (y - 1) * image_width];
215 integral_image[x + y * image_width] = (
uint32_t) in[x + y * image_width] + integral_image[x - 1 + y * image_width];
217 integral_image[x + y * image_width] = (
uint32_t) in[x + y * image_width] + integral_image[x + (y - 1) * image_width];
219 integral_image[x + y * image_width] = (
uint32_t) in[x + y * image_width];
231 if (max_x + max_y * image_width >= image_width * image_height) {
return 0; }
232 sum = integral_image[min_x + min_y * image_width] + integral_image[max_x + max_y * image_width] -
233 integral_image[max_x + min_y * image_width] - integral_image[min_x + max_y * image_width];
244 w = max_x - min_x + 1;
245 h = max_y - min_y + 1;
248 sum = integral_image[min_x + min_y * image_width] + integral_image[max_x + max_y * image_width] -
249 integral_image[max_x + min_y * image_width] - integral_image[min_x + max_y * image_width];
251 avg = (sum *
RES) / n_pix;
259 uint32_t whole_area, inner_area, resp;
261 whole_area =
get_sum_disparities(x, y, x + feature_size, y + feature_size, integral_image, image_width, image_height);
263 inner_area =
get_sum_disparities(x + border, y + border, x + feature_size - border, y + feature_size - border,
264 integral_image, image_width, image_height);
267 if (whole_area - inner_area > 0) {
268 resp = (inner_area *
RES * px_border) / ((whole_area - inner_area) * px_inner);
273 if (inner_area > 0 && (inner_area / px_inner) > 0) {
274 resp = (
RES * (whole_area - inner_area) / px_border) / (inner_area / px_inner);
288 uint32_t inner_area, avg_inner, left_area, right_area, up_area, down_area, darkest, avg_dark, resp;
290 inner_area =
get_sum_disparities(x + border, y + border, x + feature_size - border, y + feature_size - border,
291 integral_image, image_width, image_height);
292 avg_inner = (
RES * inner_area) / px_inner;
294 left_area =
get_sum_disparities(x, y + border, x + border, y + border + window_size, integral_image, image_width,
296 right_area =
get_sum_disparities(x + border + window_size, y + border, x + 2 * border + window_size,
297 y + border + window_size, integral_image, image_width, image_height);
298 up_area =
get_sum_disparities(x + border, y, x + border + window_size, y + border, integral_image, image_width,
300 down_area =
get_sum_disparities(x + border, y + border + window_size, x + border + window_size,
301 y + 2 * border + window_size, integral_image, image_width, image_height);
303 darkest = (left_area < right_area) ? left_area : right_area;
304 darkest = (darkest < up_area) ? darkest : up_area;
305 darkest = (darkest < down_area) ? darkest : down_area;
306 avg_dark =
RES * darkest / px_outer;
307 if (avg_dark < avg_inner) {
313 resp =
RES * avg_inner / avg_dark;
323 for (x = 0; x < image_width; x++) {
324 for (y = 0; y < image_height; y++) {
325 if (in[x + y * image_width] < 4) {
326 in[x + y * image_width] = 6;
337 for (x = 0; x < image_width; x++) {
338 for (y = 0; y < image_height; y++) {
341 out[x + y * image_width] = in[2 * (x + y * image_width)] >> n_bits;
343 out[x + y * image_width] = (255 - in[2 * (x + y * image_width)]) >> n_bits;