Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 {
40 };
41 
42 /* Main image structure */
43 struct image_t {
47  struct timeval ts;
50 
53  void *buf;
54 };
55 
56 /* Image point structure */
57 struct point_t {
63 };
64 
65 /* Vector structure for point differences */
66 struct flow_t {
67  struct point_t pos;
70 };
71 
72 /* Image size structure */
73 struct img_size_t {
76 };
77 
78 /* Image crop structure */
79 struct crop_t {
84 };
85 
86 /* Usefull image functions */
87 void image_add_border(struct image_t *input, struct image_t *output, uint8_t border_size);
88 void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type);
89 void image_free(struct image_t *img);
90 void image_copy(struct image_t *input, struct image_t *output);
91 void image_switch(struct image_t *a, struct image_t *b);
92 void image_to_grayscale(struct image_t *input, struct image_t *output);
93 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,
94  uint8_t u_M, uint8_t v_m, uint8_t v_M);
95 void image_yuv422_downsample(struct image_t *input, struct image_t *output, uint16_t downsample);
96 void image_subpixel_window(struct image_t *input, struct image_t *output, struct point_t *center,
97  uint32_t subpixel_factor, uint8_t border_size);
98 void image_gradients(struct image_t *input, struct image_t *dx, struct image_t *dy);
99 void image_calculate_g(struct image_t *dx, struct image_t *dy, int32_t *g);
100 uint32_t image_difference(struct image_t *img_a, struct image_t *img_b, struct image_t *diff);
101 int32_t image_multiply(struct image_t *img_a, struct image_t *img_b, struct image_t *mult);
102 void image_show_points(struct image_t *img, struct point_t *points, uint16_t points_cnt);
103 void image_show_flow(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor);
104 void image_draw_line(struct image_t *img, struct point_t *from, struct point_t *to);
105 void image_draw_line_color(struct image_t *img, struct point_t *from, struct point_t *to, uint8_t *color);
106 void pyramid_next_level(struct image_t *input, struct image_t *output, uint8_t border_size);
107 void pyramid_build(struct image_t *input, struct image_t *output_array, uint8_t pyr_level, uint8_t border_size);
108 
109 #endif
unsigned short uint16_t
Definition: types.h:16
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:77
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:552
Definition: image.h:79
uint32_t buf_size
The buffer size.
Definition: image.h:52
image_type
Definition: image.h:35
void image_show_flow(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor)
Shows the flow from a specific point to a new point This works on YUV422 and Grayscale images...
Definition: image.c:577
uint16_t h
The height.
Definition: image.h:75
uint16_t h
height of the cropped area
Definition: image.h:83
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:245
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:290
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:364
Definition: image.h:43
Definition: image.h:66
uint16_t y
Start position y (vertical)
Definition: image.h:81
uint16_t x
Start position x (horizontal)
Definition: image.h:80
uint32_t x
The x coordinate of the point.
Definition: image.h:58
uint32_t pprz_ts
The timestamp in us since system startup.
Definition: image.h:49
uint16_t y_sub
The y subpixel coordinate of the point.
Definition: image.h:62
euler angles
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:97
uint16_t w
Width of the cropped area.
Definition: image.h:82
uint8_t buf_idx
Buffer index for V4L2 freeing.
Definition: image.h:51
void image_draw_line_color(struct image_t *img, struct point_t *from, struct point_t *to, uint8_t *color)
Draw a line on the image.
Definition: image.c:613
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:422
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:600
int16_t flow_x
The x direction flow in subpixels.
Definition: image.h:68
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:516
uint16_t w
Image width.
Definition: image.h:45
void image_yuv422_downsample(struct image_t *input, struct image_t *output, uint16_t downsample)
Simplified high-speed low CPU downsample function without averaging downsample factor must be 1...
Definition: image.c:213
unsigned long uint32_t
Definition: types.h:18
uint16_t h
Image height.
Definition: image.h:46
signed short int16_t
Definition: types.h:17
struct FloatEulers * eulerAngles
Pointer to the Euler Angles.
Definition: image.h:48
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:478
void * buf
Image buffer (depending on the image_type)
Definition: image.h:53
struct point_t pos
The original position the flow comes from.
Definition: image.h:67
uint32_t y
The y coordinate of the point.
Definition: image.h:59
Definition: image.h:57
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:446
signed long int32_t
Definition: types.h:19
uint16_t x_sub
The x subpixel coordinate of the point.
Definition: image.h:61
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:149
void pyramid_build(struct image_t *input, struct image_t *output_array, uint8_t pyr_level, uint8_t border_size)
This function populates given array of image_t structs with wanted number of padded pyramids based on...
Definition: image.c:337
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
struct timeval ts
The timestamp of creation.
Definition: image.h:47
void image_free(struct image_t *img)
Free the image.
Definition: image.c:63
uint16_t count
Number of times the point has been tracked successfully.
Definition: image.h:60
UYVY format (uint16 per pixel)
Definition: image.h:36
void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type)
Create a new image.
Definition: image.c:38
Grayscale image with only the Y part (uint8 per pixel)
Definition: image.h:37
void image_to_grayscale(struct image_t *input, struct image_t *output)
Convert an image to grayscale.
Definition: image.c:116
An image gradient (int16 per pixel)
Definition: image.h:39
uint16_t w
The width.
Definition: image.h:74
int16_t flow_y
The y direction flow in subpixels.
Definition: image.h:69
An JPEG encoded image (not per pixel encoded)
Definition: image.h:38
enum image_type type
The image type.
Definition: image.h:44