Paparazzi UAS  v7.0_unstable
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 
Computer vision framework for onboard processing.
int n_samples
Definition: detect_gate.c:85
uint8_t color_Um
Definition: detect_gate.c:92
float gate_thickness
Definition: detect_gate.c:89
uint8_t color_Vm
Definition: detect_gate.c:94
uint8_t color_VM
Definition: detect_gate.c:95
int min_px_size
Definition: detect_gate.c:87
uint8_t color_YM
Definition: detect_gate.c:91
struct gate_img best_gate
Definition: detect_gate.c:101
struct gate_img gates_c[MAX_GATES]
Definition: detect_gate.c:103
int exclude_top
Definition: detect_gate.c:96
int exclude_bottom
Definition: detect_gate.c:97
float min_gate_quality
Definition: detect_gate.c:88
uint8_t color_UM
Definition: detect_gate.c:93
int min_n_sides
Definition: detect_gate.c:86
uint8_t color_Ym
Definition: detect_gate.c:90
Definition: image.h:44
Definition: image.h:58
Paparazzi generic algebra macros.
Paparazzi floating point algebra.
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])
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.
int sz
Half the image size of the gate.
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 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 *sides)
Check the outline and the center 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.
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.
int y_corners[4]
Array of corner y coordinates.
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 quality
gate quality
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.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98