Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
snake_gate_detection.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 2018, Guido de Croon and Michael Ozo
4  *
5  * This file is part of Paparazzi.
6  *
7  * Paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * Paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
42 #include <stdint.h>
44 #include "math/pprz_algebra.h"
46 
47 #define MAX_GATES 50
48 
49 /* Gate structure */
50 struct gate_img {
51  int x;
52  int y;
53  int x_corners[4];
54  int y_corners[4];
55  int sz;
56  float quality;
57  int n_sides;
58  float sz_left;
59  float sz_right;
60 };
61 
62 // snake-gate: main function to be called externally.
63 int snake_gate_detection(struct image_t *img, int n_samples, int min_px_size, float min_gate_quality,
64  float gate_thickness, int min_n_sides,
66  struct gate_img *best_gate, struct gate_img *gates_c, int *n_gates, int exclude_top, int exclude_bottom);
67 
68 // helper functions:
69 int check_color_snake_gate_detection(struct image_t *im, int x, int y);
70 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);
71 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);
72 void draw_gate(struct image_t *im, struct gate_img gate);
73 void draw_gate_color_square(struct image_t *im, struct gate_img gate, uint8_t *color);
74 void draw_gate_color_polygon(struct image_t *im, struct gate_img gate, uint8_t *color);
75 void check_line(struct image_t *im, struct point_t Q1, struct point_t Q2, int *n_points, int *n_colored_points);
76 void check_gate_initial(struct image_t *im, struct gate_img gate, float *quality, int *sides);
77 void check_gate_outline(struct image_t *im, struct gate_img gate, float *quality, int *n_sides);
78 float check_inside(struct image_t *im, int x, int y, int sz, int n_samples_in);
79 void set_gate_points(struct gate_img *gate);
80 void gate_refine_corners(struct image_t *color_image, int *x_points, int *y_points, int size);
81 void refine_single_corner(struct image_t *im, int *corner_x, int *corner_y, int size, float size_factor);
82 int overlap_intervals(int val_low_1, int val_high_1, int val_low_2, int val_high_2);
83 int intersection_boxes(int x_box_1[4], int y_box_1[4], int x_box_2[4], int y_box_2[4]);
84 float intersection_over_union(int x_box_1[4], int y_box_1[4], int x_box_2[4], int y_box_2[4]);
85 
gate_img::y
int y
The image y coordinate of the gate center.
Definition: snake_gate_detection.h:52
color_YM
uint8_t color_YM
Definition: detect_gate.c:91
gate_img::x
int x
The image x coordinate of the gate center.
Definition: snake_gate_detection.h:51
gates_c
struct gate_img gates_c[MAX_GATES]
Definition: detect_gate.c:103
gate_img::quality
float quality
gate quality
Definition: snake_gate_detection.h:56
gate_img::x_corners
int x_corners[4]
Array of corner x coordinates.
Definition: snake_gate_detection.h:53
overlap_intervals
int overlap_intervals(int val_low_1, int val_high_1, int val_low_2, int val_high_2)
Definition: snake_gate_detection.c:1183
gate_img::n_sides
int n_sides
How many sides are orange (to prevent detecting a small gate in the corner of a big one partially out...
Definition: snake_gate_detection.h:57
draw_gate
void draw_gate(struct image_t *im, struct gate_img gate)
Draw the gate on an image.
Definition: snake_gate_detection.c:478
color_VM
uint8_t color_VM
Definition: detect_gate.c:95
draw_gate_color_polygon
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.
Definition: snake_gate_detection.c:491
draw_gate_color_square
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.
Definition: snake_gate_detection.c:538
best_gate
struct gate_img best_gate
Definition: detect_gate.c:101
min_gate_quality
float min_gate_quality
Definition: detect_gate.c:88
gate_img::sz
int sz
Half the image size of the gate.
Definition: snake_gate_detection.h:55
pprz_algebra_float.h
Paparazzi floating point algebra.
check_inside
float check_inside(struct image_t *im, int x, int y, int sz, int n_samples_in)
Definition: snake_gate_detection.c:761
color_Vm
uint8_t color_Vm
Definition: detect_gate.c:94
snake_left_and_right
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.
Definition: snake_gate_detection.c:919
check_line
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.
Definition: snake_gate_detection.c:818
exclude_top
int exclude_top
Definition: detect_gate.c:96
cv.h
color_UM
uint8_t color_UM
Definition: detect_gate.c:93
snake_up_and_down
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.
Definition: snake_gate_detection.c:859
snake_gate_detection
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.
Definition: snake_gate_detection.c:135
intersection_boxes
int intersection_boxes(int x_box_1[4], int y_box_1[4], int x_box_2[4], int y_box_2[4])
Definition: snake_gate_detection.c:1167
gate_thickness
float gate_thickness
Definition: detect_gate.c:89
uint8_t
unsigned char uint8_t
Definition: types.h:14
intersection_over_union
float intersection_over_union(int x_box_1[4], int y_box_1[4], int x_box_2[4], int y_box_2[4])
Definition: snake_gate_detection.c:1131
color_Ym
uint8_t color_Ym
Definition: detect_gate.c:90
color_Um
uint8_t color_Um
Definition: detect_gate.c:92
n_samples
int n_samples
Definition: detect_gate.c:85
set_gate_points
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...
Definition: snake_gate_detection.c:971
min_px_size
int min_px_size
Definition: detect_gate.c:87
exclude_bottom
int exclude_bottom
Definition: detect_gate.c:97
gate_img::sz_left
float sz_left
Half the image size of the left side.
Definition: snake_gate_detection.h:58
gate_img
Definition: snake_gate_detection.h:50
check_color_snake_gate_detection
int check_color_snake_gate_detection(struct image_t *im, int x, int y)
Definition: snake_gate_detection.c:1102
check_gate_outline
void check_gate_outline(struct image_t *im, struct gate_img gate, float *quality, int *n_sides)
Check only the outline of the gate.
Definition: snake_gate_detection.c:581
gate_img::sz_right
float sz_right
Half the image size of the right side.
Definition: snake_gate_detection.h:59
pprz_algebra.h
Paparazzi generic algebra macros.
gate_refine_corners
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.
Definition: snake_gate_detection.c:993
check_gate_initial
void check_gate_initial(struct image_t *im, struct gate_img gate, float *quality, int *sides)
Check the outline and the center of the gate.
Definition: snake_gate_detection.c:673
point_t
Definition: image.h:58
gate_img::y_corners
int y_corners[4]
Array of corner y coordinates.
Definition: snake_gate_detection.h:54
image_t
Definition: image.h:44
refine_single_corner
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.
Definition: snake_gate_detection.c:1013
min_n_sides
int min_n_sides
Definition: detect_gate.c:86