-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
image.h
132 lines (115 loc) · 6.27 KB
/
image.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright (C) 2015 Freek van Tienen <freek.v.tienen@gmail.com>
*
* This file is part of Paparazzi.
*
* Paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* Paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* @file modules/computer_vision/lib/vision/image.h
* Image helper functions like resizing, color filter, converters...
*/
#ifndef _CV_LIB_VISION_IMAGE_H
#define _CV_LIB_VISION_IMAGE_H
#include "std.h"
#include <sys/time.h>
#include <state.h>
/* The different type of images we currently support */
enum image_type {
IMAGE_YUV422, ///< UYVY format (uint16 per pixel)
IMAGE_GRAYSCALE, ///< Grayscale image with only the Y part (uint8 per pixel)
IMAGE_JPEG, ///< An JPEG encoded image (not per pixel encoded)
IMAGE_GRADIENT, ///< An image gradient (int16 per pixel)
IMAGE_INT16 ///< An image to hold disparity image data from openCV (int16 per pixel)
};
/* Main image structure */
struct image_t {
enum image_type type; ///< The image type
uint16_t w; ///< Image width
uint16_t h; ///< Image height
struct timeval ts; ///< The timestamp of creation
struct FloatEulers eulers; ///< Euler Angles at time of image
uint32_t pprz_ts; ///< The timestamp in us since system startup
uint8_t buf_idx; ///< Buffer index for V4L2 freeing
uint32_t buf_size; ///< The buffer size
void *buf; ///< Image buffer (depending on the image_type)
};
/* Image point structure */
struct point_t {
uint32_t x; ///< The x coordinate of the point
uint32_t y; ///< The y coordinate of the point
uint16_t count; ///< Number of times the point has been tracked successfully
uint16_t x_sub; ///< The x subpixel coordinate of the point
uint16_t y_sub; ///< The y subpixel coordinate of the point
};
/* 3d Image point structure */
struct point3d_t {
float X; ///< The x coordinate of the point
float Y; ///< The y coordinate of the point
float Z; ///< The y coordinate of the point
};
/* Vector structure for point differences */
struct flow_t {
struct point_t pos; ///< The original position the flow comes from in subpixels
int32_t flow_x; ///< The x direction flow in subpixels
int32_t flow_y; ///< The y direction flow in subpixels
uint32_t error; ///< The matching error in the tracking process in subpixels
};
/* Image size structure */
struct img_size_t {
uint16_t w; ///< The width
uint16_t h; ///< The height
};
/* Image crop structure */
struct crop_t {
uint16_t x; ///< Start position x (horizontal)
uint16_t y; ///< Start position y (vertical)
uint16_t w; ///< Width of the cropped area
uint16_t h; ///< height of the cropped area
};
/* Usefull image functions */
void image_add_border(struct image_t *input, struct image_t *output, uint8_t border_size);
void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type);
void image_free(struct image_t *img);
void image_copy(struct image_t *input, struct image_t *output);
void image_switch(struct image_t *a, struct image_t *b);
void image_to_grayscale(struct image_t *input, struct image_t *output);
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);
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);
void set_color_yuv422(struct image_t *im, int x, int y, uint8_t Y, uint8_t U, uint8_t V);
void image_yuv422_downsample(struct image_t *input, struct image_t *output, uint8_t downsample);
void image_subpixel_window(struct image_t *input, struct image_t *output, struct point_t *center,
uint32_t subpixel_factor, uint8_t border_size);
void image_gradients(struct image_t *input, struct image_t *dx, struct image_t *dy);
void image_calculate_g(struct image_t *dx, struct image_t *dy, int32_t *g);
uint32_t image_difference(struct image_t *img_a, struct image_t *img_b, struct image_t *diff);
int32_t image_multiply(struct image_t *img_a, struct image_t *img_b, struct image_t *mult);
void image_show_points(struct image_t *img, struct point_t *points, uint16_t points_cnt);
void image_show_points_color(struct image_t *img, struct point_t *points, uint16_t points_cnt, uint8_t *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);
void image_show_flow(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor);
void image_draw_crosshair(struct image_t *img, struct point_t *loc, const uint8_t *color, uint32_t size_crosshair);
void image_draw_rectangle(struct image_t *img, int x_min, int x_max, int y_min, int y_max, uint8_t *color);
void image_draw_line(struct image_t *img, struct point_t *from, struct point_t *to);
void image_draw_line_color(struct image_t *img, struct point_t *from, struct point_t *to, const uint8_t *color);
void pyramid_next_level(struct image_t *input, struct image_t *output, uint8_t border_size);
void pyramid_build(struct image_t *input, struct image_t *output_array, uint8_t pyr_level, uint16_t border_size);
void image_gradient_pixel(struct image_t *img, struct point_t *loc, int method, int *dx, int *dy);
uint8_t ker_mul_3x3(uint8_t const *source, int_fast8_t const *kernel, uint8_t total, uint8_t setting, int width, int YUV);
void image_convolution_3x3(struct image_t *input, struct image_t *output, int_fast8_t const *kernel, uint8_t kernel_total);
#endif