Paparazzi UAS
v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
|
Image helper functions like resizing, color filter, converters... More...
#include "std.h"
#include <sys/time.h>
Go to the source code of this file.
Data Structures | |
struct | image_t |
struct | point_t |
struct | flow_t |
Enumerations | |
enum | image_type { IMAGE_YUV422, IMAGE_GRAYSCALE, IMAGE_JPEG, IMAGE_GRADIENT } |
Functions | |
void | image_create (struct image_t *img, uint16_t width, uint16_t height, enum image_type type) |
Create a new image. More... | |
void | image_free (struct image_t *img) |
Free the image. More... | |
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. More... | |
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 buffer. More... | |
void | image_to_grayscale (struct image_t *input, struct image_t *output) |
Convert an image to grayscale. More... | |
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. More... | |
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, 2, 4, 8 ... More... | |
void | image_subpixel_window (struct image_t *input, struct image_t *output, struct point_t *center, uint16_t subpixel_factor) |
This outputs a subpixel window image in grayscale Currently only works with Grayscale images as input but could be upgraded to also support YUV422 images. More... | |
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]. More... | |
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. More... | |
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 images. More... | |
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 gradients. More... | |
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. More... | |
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. More... | |
void | image_draw_line (struct image_t *img, struct point_t *from, struct point_t *to) |
Draw a line on the image. More... | |
Image helper functions like resizing, color filter, converters...
Definition in file image.h.
struct image_t |
Data Fields | ||
---|---|---|
void * | buf | Image buffer (depending on the image_type) |
uint8_t | buf_idx | Buffer index for V4L2 freeing. |
uint32_t | buf_size | The buffer size. |
uint16_t | h | Image height. |
struct timeval | ts | The timestamp of creation. |
enum image_type | type | The image type. |
uint16_t | w | Image width. |
struct point_t |
struct flow_t |
enum image_type |
Calculate the G vector of an image gradient This is used for optical flow calculation.
[in] | *dx | The gradient in the X direction |
[in] | *dy | The gradient in the Y direction |
[out] | *g | The G[4] vector devided by 255 to keep in range |
Definition at line 325 of file image.c.
References image_t::buf, image_t::h, and image_t::w.
Referenced by opticFlowLK().
Copy an image from inut to output This will only work if the formats are the same.
[in] | *input | The input image to copy from |
[out] | *output | The out image to copy to |
Definition at line 77 of file image.c.
References image_t::buf, image_t::buf_size, image_t::h, image_t::ts, image_t::type, and image_t::w.
Referenced by opticflow_calc_frame().
void image_create | ( | struct image_t * | img, |
uint16_t | width, | ||
uint16_t | height, | ||
enum image_type | type | ||
) |
Create a new image.
[out] | *img | The output image |
[in] | width | The width of the image |
[in] | height | The height of the image |
[in] | type | The type of image (YUV422 or grayscale) |
Definition at line 38 of file image.c.
References image_t::buf, image_t::buf_size, image_t::h, IMAGE_GRADIENT, IMAGE_JPEG, IMAGE_YUV422, image_t::type, and image_t::w.
Referenced by bebop_front_camera_thread(), cv_blob_locator_func(), cv_window_func(), detect_window(), opticflow_calc_init(), opticflow_module_calc(), opticFlowLK(), qrscan(), video_thread_function(), video_thread_periodic(), and viewvideo_function().
Calculate the difference between two images and return the error This will only work with grayscale images.
[in] | *img_a | The image to substract from |
[in] | *img_b | The image to substract from img_a |
[out] | *diff | The image difference (if not needed can be NULL) |
Definition at line 357 of file image.c.
References image_t::buf, image_t::h, and image_t::w.
Referenced by opticFlowLK().
Draw a line on the image.
[in,out] | *img | The image to show the line on |
[in] | *from | The point to draw from |
[in] | *to | The point to draw to |
Definition at line 479 of file image.c.
References image_t::buf, image_t::h, IMAGE_YUV422, image_t::type, image_t::w, point_t::x, and point_t::y.
Referenced by image_show_flow().
void image_free | ( | struct image_t * | img | ) |
Free the image.
[in] | *img | The image to free |
Definition at line 63 of file image.c.
References image_t::buf.
Referenced by cv_blob_locator_func(), cv_window_func(), detect_window(), opticflow_module_calc(), opticFlowLK(), video_thread_function(), video_thread_periodic(), and viewvideo_function().
Calculate the gradients using the following matrix: [0 -1 0; -1 0 1; 0 1 0].
[in] | *input | Input grayscale image |
[out] | *dx | Output gradient in the X direction (dx->w = input->w-2, dx->h = input->h-2) |
[out] | *dy | Output gradient in the Y direction (dx->w = input->w-2, dx->h = input->h-2) |
Definition at line 302 of file image.c.
References image_t::buf, image_t::h, and image_t::w.
Referenced by opticFlowLK().
Calculate the multiplication between two images and return the error This will only work with image gradients.
[in] | *img_a | The image to multiply |
[in] | *img_b | The image to multiply with |
[out] | *mult | The image multiplication (if not needed can be NULL) |
Definition at line 395 of file image.c.
References image_t::buf, image_t::h, and image_t::w.
Referenced by opticFlowLK().
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.
[in,out] | *img | The image to show the flow on |
[in] | *vectors | The flow vectors to show |
[in] | *points_cnt | The amount of points and vectors to show |
Definition at line 456 of file image.c.
References flow_t::flow_x, flow_t::flow_y, image_draw_line(), flow_t::pos, point_t::x, and point_t::y.
Referenced by opticflow_calc_frame().
Show points in an image by coloring them through giving the pixels the maximum value.
This works with YUV422 and grayscale images
[in,out] | *img | The image to place the points on |
[in] | *points | The points to sohw |
[in] | *points_cnt | The amount of points to show |
Definition at line 431 of file image.c.
References image_t::buf, IMAGE_YUV422, image_t::type, image_t::w, point_t::x, and point_t::y.
Referenced by opticflow_calc_frame().
void image_subpixel_window | ( | struct image_t * | input, |
struct image_t * | output, | ||
struct point_t * | center, | ||
uint16_t | subpixel_factor | ||
) |
This outputs a subpixel window image in grayscale Currently only works with Grayscale images as input but could be upgraded to also support YUV422 images.
[in] | *input | Input image (grayscale only) |
[out] | *output | Window output (width and height is used to calculate the window size) |
[in] | *center | Center point in subpixel coordinates |
[in] | subpixel_factor | The subpixel factor per pixel |
Definition at line 247 of file image.c.
References image_t::buf, image_t::h, image_t::w, point_t::x, and point_t::y.
Referenced by opticFlowLK().
This will switch image *a and *b This is faster as image_copy because it doesn't copy the whole image buffer.
[in,out] | *a | The image to switch |
[in,out] | *b | The image to switch with |
Definition at line 97 of file image.c.
Referenced by opticflow_calc_frame().
Convert an image to grayscale.
Depending on the output type the U/V bytes are removed
[in] | *input | The input image (Needs to be YUV422) |
[out] | *output | The output image |
Definition at line 116 of file image.c.
References image_t::buf, dest, image_t::h, IMAGE_YUV422, image_t::ts, image_t::type, and image_t::w.
Referenced by cv_window_func(), detect_window(), and opticflow_calc_frame().
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.
[in] | *input | The input image to filter |
[out] | *output | The filtered output image |
[in] | y_m | The Y minimum value |
[in] | y_M | The Y maximum value |
[in] | u_m | The U minimum value |
[in] | u_M | The U maximum value |
[in] | v_m | The V minimum value |
[in] | v_M | The V maximum value |
Definition at line 149 of file image.c.
References image_t::buf, dest, image_t::h, image_t::ts, and image_t::w.
Referenced by colorfilter_func().
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, 2, 4, 8 ...
2^X image of typ UYVY expected. Only one color UV per 2 pixels
we keep the UV color of the first pixel pair and sample the intensity evenly 1-3-5-7-... or 1-5-9-...
input: u1y1 v1y2 u3y3 v3y4 u5y5 v5y6 u7y7 v7y8 ... downsample=1 u1y1 v1y2 u3y3 v3y4 u5y5 v5y6 u7y7 v7y8 ... downsample=2 u1y1v1 (skip2) y3 (skip2) u5y5v5 (skip2 y7 (skip2) ... downsample=4 u1y1v1 (skip6) y5 (skip6) ...
[in] | *input | The input YUV422 image |
[out] | *output | The downscaled YUV422 image |
[in] | downsample | The downsampel facter (must be downsample=2^X) |
Definition at line 213 of file image.c.
References image_t::buf, dest, image_t::h, image_t::ts, and image_t::w.
Referenced by viewvideo_function().