Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
image.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freek van Tienen <freek.v.tienen@gmail.com>
3  *
4  * This file is part of Paparazzi.
5  *
6  * Paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * Paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef _CV_LIB_VISION_IMAGE_H
28 #define _CV_LIB_VISION_IMAGE_H
29 
30 #include "std.h"
31 #include <sys/time.h>
32 #include <state.h>
33 
34 /* The different type of images we currently support */
35 enum image_type {
41 };
42 
43 /* Main image structure */
44 struct image_t {
48  struct timeval ts;
51 
54  void *buf;
55 };
56 
57 /* Image point structure */
58 struct point_t {
64 };
65 
66 
67 /* 3d Image point structure */
68 struct point3d_t {
69  float X;
70  float Y;
71  float Z;
72 
73 };
74 
75 
76 
77 /* Vector structure for point differences */
78 struct flow_t {
79  struct point_t pos;
83 };
84 
85 /* Image size structure */
86 struct img_size_t {
89 };
90 
91 /* Image crop structure */
92 struct crop_t {
97 };
98 
99 /* Usefull image functions */
100 void image_add_border(struct image_t *input, struct image_t *output, uint8_t border_size);
101 void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type);
102 void image_free(struct image_t *img);
103 void image_copy(struct image_t *input, struct image_t *output);
104 void image_switch(struct image_t *a, struct image_t *b);
105 void image_to_grayscale(struct image_t *input, struct image_t *output);
106 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,
107  uint8_t u_M, uint8_t v_m, uint8_t v_M);
108 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);
109 void set_color_yuv422(struct image_t *im, int x, int y, uint8_t Y, uint8_t U, uint8_t V);
110 void image_yuv422_downsample(struct image_t *input, struct image_t *output, uint8_t downsample);
111 void image_subpixel_window(struct image_t *input, struct image_t *output, struct point_t *center,
112  uint32_t subpixel_factor, uint8_t border_size);
113 void image_gradients(struct image_t *input, struct image_t *dx, struct image_t *dy);
114 void image_calculate_g(struct image_t *dx, struct image_t *dy, int32_t *g);
115 uint32_t image_difference(struct image_t *img_a, struct image_t *img_b, struct image_t *diff);
116 int32_t image_multiply(struct image_t *img_a, struct image_t *img_b, struct image_t *mult);
117 void image_show_points(struct image_t *img, struct point_t *points, uint16_t points_cnt);
118 void image_show_points_color(struct image_t *img, struct point_t *points, uint16_t points_cnt, uint8_t *color);
119 void image_show_flow_color(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor,
120  const uint8_t *color, const uint8_t *bad_color);
121 void image_show_flow(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor);
122 void image_draw_crosshair(struct image_t *img, struct point_t *loc, const uint8_t *color, uint32_t size_crosshair);
123 void image_draw_rectangle(struct image_t *img, int x_min, int x_max, int y_min, int y_max, uint8_t *color);
124 void image_draw_line(struct image_t *img, struct point_t *from, struct point_t *to);
125 void image_draw_line_color(struct image_t *img, struct point_t *from, struct point_t *to, const uint8_t *color);
126 void pyramid_next_level(struct image_t *input, struct image_t *output, uint8_t border_size);
127 void pyramid_build(struct image_t *input, struct image_t *output_array, uint8_t pyr_level, uint16_t border_size);
128 void image_gradient_pixel(struct image_t *img, struct point_t *loc, int method, int *dx, int *dy);
129 
130 #endif
pyramid_next_level
void pyramid_next_level(struct image_t *input, struct image_t *output, uint8_t border_size)
This function takes previous padded pyramid level and outputs next level of pyramid without padding.
Definition: image.c:406
image_show_flow
void image_show_flow(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor)
Definition: image.c:715
uint16_t
unsigned short uint16_t
Definition: types.h:16
crop_t::h
uint16_t h
height of the cropped area
Definition: image.h:96
image_t::type
enum image_type type
The image type.
Definition: image.h:45
image_yuv422_downsample
void image_yuv422_downsample(struct image_t *input, struct image_t *output, uint8_t downsample)
Simplified high-speed low CPU downsample function without averaging downsample factor must be 1,...
Definition: image.c:311
image_show_points_color
void image_show_points_color(struct image_t *img, struct point_t *points, uint16_t points_cnt, uint8_t *color)
Show points in an image by coloring them through giving the pixels the maximum value.
Definition: image.c:690
img_size_t::w
uint16_t w
The width.
Definition: image.h:87
point3d_t
Definition: image.h:68
set_color_yuv422
void set_color_yuv422(struct image_t *im, int x, int y, uint8_t Y, uint8_t U, uint8_t V)
Sets Y,U,V for a single pixel.
Definition: image.c:272
point_t::count
uint16_t count
Number of times the point has been tracked successfully.
Definition: image.h:61
b
float b
Definition: wedgebug.c:202
image_draw_crosshair
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.
Definition: image.c:880
image_gradient_pixel
void image_gradient_pixel(struct image_t *img, struct point_t *loc, int method, int *dx, int *dy)
Get the gradient at a pixel location.
Definition: image.c:766
image_draw_line
void image_draw_line(struct image_t *img, struct point_t *from, struct point_t *to)
Draw a pink line on the image.
Definition: image.c:906
img_size_t::h
uint16_t h
The height.
Definition: image.h:88
crop_t::w
uint16_t w
Width of the cropped area.
Definition: image.h:95
uint32_t
unsigned long uint32_t
Definition: types.h:18
flow_t::pos
struct point_t pos
The original position the flow comes from in subpixels.
Definition: image.h:79
image_t::w
uint16_t w
Image width.
Definition: image.h:46
image_add_border
void image_add_border(struct image_t *input, struct image_t *output, uint8_t border_size)
This function adds padding to input image by mirroring the edge image elements.
Definition: image.c:361
image_gradients
void image_gradients(struct image_t *input, struct image_t *dx, struct image_t *dy)
Calculate the gradients using the following matrix: [0 -1 0; -1 0 1; 0 1 0].
Definition: image.c:538
image_switch
void image_switch(struct image_t *a, struct image_t *b)
This will switch image *a and *b This is faster as image_copy because it doesn't copy the whole image...
Definition: image.c:112
image_yuv422_colorfilt
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.
Definition: image.c:166
image_subpixel_window
void image_subpixel_window(struct image_t *input, struct image_t *output, struct point_t *center, uint32_t subpixel_factor, uint8_t border_size)
This outputs a subpixel window image in grayscale Currently only works with Grayscale images as input...
Definition: image.c:480
IMAGE_GRAYSCALE
@ IMAGE_GRAYSCALE
Grayscale image with only the Y part (uint8 per pixel)
Definition: image.h:37
image_copy
void image_copy(struct image_t *input, struct image_t *output)
Copy an image from inut to output This will only work if the formats are the same.
Definition: image.c:89
image_t::buf_size
uint32_t buf_size
The buffer size.
Definition: image.h:53
crop_t
Definition: image.h:92
image_t::h
uint16_t h
Image height.
Definition: image.h:47
IMAGE_INT16
@ IMAGE_INT16
An image to hold disparity image data from openCV (int16 per pixel)
Definition: image.h:40
std.h
point3d_t::X
float X
The x coordinate of the point.
Definition: image.h:69
point_t::y_sub
uint16_t y_sub
The y subpixel coordinate of the point.
Definition: image.h:63
image_difference
uint32_t image_difference(struct image_t *img_a, struct image_t *img_b, struct image_t *diff)
Calculate the difference between two images and return the error This will only work with grayscale i...
Definition: image.c:594
uint8_t
unsigned char uint8_t
Definition: types.h:14
point3d_t::Z
float Z
The y coordinate of the point.
Definition: image.h:71
IMAGE_JPEG
@ IMAGE_JPEG
An JPEG encoded image (not per pixel encoded)
Definition: image.h:38
image_to_grayscale
void image_to_grayscale(struct image_t *input, struct image_t *output)
Convert an image to grayscale.
Definition: image.c:131
image_draw_rectangle
void image_draw_rectangle(struct image_t *img, int x_min, int x_max, int y_min, int y_max, uint8_t *color)
Draw a rectangle on the image.
Definition: image.c:838
image_create
void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type)
Create a new image.
Definition: image.c:43
image_multiply
int32_t image_multiply(struct image_t *img_a, struct image_t *img_b, struct image_t *mult)
Calculate the multiplication between two images and return the error This will only work with image g...
Definition: image.c:632
point_t::x
uint32_t x
The x coordinate of the point.
Definition: image.h:59
image_draw_line_color
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.
Definition: image.c:921
pyramid_build
void pyramid_build(struct image_t *input, struct image_t *output_array, uint8_t pyr_level, uint16_t border_size)
This function populates given array of image_t structs with wanted number of padded pyramids based on...
Definition: image.c:453
img_size_t
Definition: image.h:86
image_calculate_g
void image_calculate_g(struct image_t *dx, struct image_t *dy, int32_t *g)
Calculate the G vector of an image gradient This is used for optical flow calculation.
Definition: image.c:562
flow_t
Definition: image.h:78
IMAGE_YUV422
@ IMAGE_YUV422
UYVY format (uint16 per pixel)
Definition: image.h:36
image_show_points
void image_show_points(struct image_t *img, struct point_t *points, uint16_t points_cnt)
Show points in an image by coloring them through giving the pixels the maximum value.
Definition: image.c:668
int32_t
signed long int32_t
Definition: types.h:19
point_t::y
uint32_t y
The y coordinate of the point.
Definition: image.h:60
crop_t::y
uint16_t y
Start position y (vertical)
Definition: image.h:94
point_t::x_sub
uint16_t x_sub
The x subpixel coordinate of the point.
Definition: image.h:62
image_type
image_type
Definition: image.h:35
image_t::pprz_ts
uint32_t pprz_ts
The timestamp in us since system startup.
Definition: image.h:50
check_color_yuv422
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.
Definition: image.c:230
type
timer subsystem type(config options) --------------------------------------------(advanced timers using RCC_APB1) TIM1 adc(if USE_AD_TIM1) radio_control/ppm(if USE_PPM_TIM1
image_free
void image_free(struct image_t *img)
Free the image.
Definition: image.c:75
flow_t::flow_x
int32_t flow_x
The x direction flow in subpixels.
Definition: image.h:80
image_show_flow_color
void image_show_flow_color(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor, const uint8_t *color, const uint8_t *bad_color)
Shows the flow from a specific point to a new point This works on YUV422 and Grayscale images.
Definition: image.c:732
FloatEulers
euler angles
Definition: pprz_algebra_float.h:84
image_t::ts
struct timeval ts
The timestamp of creation.
Definition: image.h:48
image_t::buf
void * buf
Image buffer (depending on the image_type)
Definition: image.h:54
IMAGE_GRADIENT
@ IMAGE_GRADIENT
An image gradient (int16 per pixel)
Definition: image.h:39
state.h
image_t::buf_idx
uint8_t buf_idx
Buffer index for V4L2 freeing.
Definition: image.h:52
point_t
Definition: image.h:58
crop_t::x
uint16_t x
Start position x (horizontal)
Definition: image.h:93
mesonh.mesonh_atmosphere.Y
int Y
Definition: mesonh_atmosphere.py:44
flow_t::error
uint32_t error
The matching error in the tracking process in subpixels.
Definition: image.h:82
flow_t::flow_y
int32_t flow_y
The y direction flow in subpixels.
Definition: image.h:81
point3d_t::Y
float Y
The y coordinate of the point.
Definition: image.h:70
image_t
Definition: image.h:44
image_t::eulers
struct FloatEulers eulers
Euler Angles at time of image.
Definition: image.h:49