52#define SUCCESS_DETECT 1
86int cmpfunc(
const void *a,
const void *
b);
87int cmp_i(
const void *a,
const void *
b);
92 return (*(
const int *)a - * (
const int *)
b);
96int cmp_i(
const void *a,
const void *
b)
98 int ia = *(
const int *)a;
99 int ib = *(
const int *)
b;
276 for (
int g = 0;
g < (*n_gates);
g++) {
312#ifdef DEBUG_SNAKE_GATE
315 for (
int i = 0; i < (*n_gates); i++) {
406#ifdef DEBUG_SNAKE_GATE
447 for (
int i = 0; i < 3; i++) {
503 from.
x =
gate.y_corners[0];
504 from.
y =
gate.x_corners[0];
505 to.
x =
gate.y_corners[1];
506 to.
y =
gate.x_corners[1];
509 from.
x =
gate.y_corners[1];
510 from.
y =
gate.x_corners[1];
511 to.
x =
gate.y_corners[2];
512 to.
y =
gate.x_corners[2];
515 from.
x =
gate.y_corners[2];
516 from.
y =
gate.x_corners[2];
517 to.
x =
gate.y_corners[3];
518 to.
y =
gate.x_corners[3];
521 from.
x =
gate.y_corners[3];
522 from.
y =
gate.x_corners[3];
523 to.
x =
gate.y_corners[0];
524 to.
y =
gate.x_corners[0];
598 from.
x =
gate.x_corners[0];
599 from.
y =
gate.y_corners[0];
600 to.
x =
gate.x_corners[1];
601 to.
y =
gate.y_corners[1];
609 from.
x =
gate.x_corners[1];
610 from.
y =
gate.y_corners[1];
611 to.
x =
gate.x_corners[2];
612 to.
y =
gate.y_corners[2];
620 from.
x =
gate.x_corners[2];
621 from.
y =
gate.y_corners[2];
622 to.
x =
gate.x_corners[3];
623 to.
y =
gate.y_corners[3];
631 from.
x =
gate.x_corners[3];
632 from.
y =
gate.y_corners[3];
633 to.
x =
gate.x_corners[0];
634 to.
y =
gate.y_corners[0];
772 int x_in =
x + (
rand() % sz) - (0.5 * sz);
773 int y_in =
y + (
rand() % sz) - (0.5 * sz);
822 (*n_colored_points) = 0;
841 (*n_colored_points)++;
867 while ((*
y_low) > 0 && !done) {
888 while ((*
y_high) < im->
w - 1 && !done) {
926 while ((*
x_low) > 0 && !done) {
947 while ((*
x_high) < im->
h - 1 && !done) {
1031#ifdef DEBUG_SNAKE_GATE
1173 return width * height;
static void h(const real32_T x[7], const real32_T q[4], real32_T y[6])
struct gate_img best_gate
struct gate_img gates_c[MAX_GATES]
void image_draw_crosshair(struct image_t *img, struct point_t *loc, const uint8_t *color, uint32_t size_crosshair)
Draw a cross-hair on the image.
void image_draw_line_color(struct image_t *img, struct point_t *from, struct point_t *to, const uint8_t *color)
Draw a line on the image.
int check_color_yuv422(struct image_t *im, int x, int y, uint8_t y_m, uint8_t y_M, uint8_t u_m, uint8_t u_M, uint8_t v_m, uint8_t v_M)
Checks the color of a single pixel in a YUV422 image.
uint16_t image_yuv422_colorfilt(struct image_t *input, struct image_t *output, uint8_t y_m, uint8_t y_M, uint8_t u_m, uint8_t u_M, uint8_t v_m, uint8_t v_M)
Filter colors in an YUV422 image.
Image helper functions like resizing, color filter, converters...
uint32_t x
The x coordinate of the point.
uint32_t y
The y coordinate of the point.
int check_color_snake_gate_detection(struct image_t *im, int x, int y)
int overlap_intervals(int val_low_1, int val_high_1, int val_low_2, int val_high_2)
void draw_gate_color_polygon(struct image_t *im, struct gate_img gate, uint8_t *color)
Draw the gate on an image, using the corner points, possibly resulting in a polygon.
int intersection_boxes(int x_box_1[4], int y_box_1[4], int x_box_2[4], int y_box_2[4])
int cmp_i(const void *a, const void *b)
void gate_refine_corners(struct image_t *color_image, int *x_points, int *y_points, int size)
Refine the four corners of the gate, based on the color around the supposed corner locations.
struct image_t img_result
void check_line(struct image_t *im, struct point_t Q1, struct point_t Q2, int *n_points, int *n_colored_points)
Checks whether points on a line between two 2D-points are of a given color.
int cmpfunc(const void *a, const void *b)
struct gate_img temp_check_gate
int snake_gate_detection(struct image_t *img, int n_samples, int min_px_size, float min_gate_quality, float gate_thickness, int min_n_sides, uint8_t color_Ym, uint8_t color_YM, uint8_t color_Um, uint8_t color_UM, uint8_t color_Vm, uint8_t color_VM, struct gate_img *best_gate, struct gate_img *gates_c, int *n_gates, int exclude_top, int exclude_bottom)
Run snake gate detection on an image.
void check_gate_initial(struct image_t *im, struct gate_img gate, float *quality, int *n_sides)
Check the outline and the center of the gate.
float segment_length(struct point_t Q1, struct point_t Q2)
Determine the segment length between two 2D-points.
void draw_gate_color_square(struct image_t *im, struct gate_img gate, uint8_t *color)
Draw the gate on an image, using only the center coordinate and sizes - resulting in a square gate.
void snake_up_and_down(struct image_t *im, int x, int y, int *x_low, int *y_low, int *x_high, int *y_high)
The actual snaking.
void check_gate_outline(struct image_t *im, struct gate_img gate, float *quality, int *n_sides)
Check only the outline of the gate.
float check_inside(struct image_t *im, int x, int y, int sz, int n_samples_in)
void set_gate_points(struct gate_img *gate)
Determine and set the corner locations in gate.x_corners, g.y_corners, based on the center of the gat...
float intersection_over_union(int x_box_1[4], int y_box_1[4], int x_box_2[4], int y_box_2[4])
void snake_left_and_right(struct image_t *im, int x, int y, int *x_low, int *y_low, int *x_high, int *y_high)
The actual snaking.
void refine_single_corner(struct image_t *im, int *corner_x, int *corner_y, int size, float size_factor)
Refine a single corner, based on the color around the coordinate.
void draw_gate(struct image_t *im, struct gate_img gate)
Draw the gate on an image.
Detects gates as used in the IROS drone races, i.e., square colored gates.
int sz
Half the image size of the gate.
int n_sides
How many sides are orange (to prevent detecting a small gate in the corner of a big one partially out...
float sz_left
Half the image size of the left side.
int x
The image x coordinate of the gate center.
float sz_right
Half the image size of the right side.
int y
The image y coordinate of the gate center.
int x_corners[4]
Array of corner x coordinates.
int y_corners[4]
Array of corner y coordinates.
float quality
gate quality
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.