32#ifndef CACHE_LINE_LENGTH
33#define CACHE_LINE_LENGTH 64
52 img->buf_size =
sizeof(
uint8_t) * 2 * width * height;
54 img->buf_size =
sizeof(
uint8_t) * 2 * width * height;
56 img->buf_size =
sizeof(
int16_t) * width * height;
58 img->buf_size =
sizeof(
int16_t) * width * height;
60 img->buf_size =
sizeof(
uint8_t) * width * height;
63#if __GLIBC__ > 2 || (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 16)
146 for (
int y = 0; y < height; y++) {
147 for (
int x = 0; x < width; x++) {
154 for (
int y = 0; y < height * width; y++) {
203 char u = source[0] - 127;
242 if (x % 2 == 1) { x--; }
251 buf += 2 * (y * (im->
w) + x);
284 if (x % 2 == 1) { x--; }
293 buf += 2 * (y * (im->
w) + x);
326 for(
int8_t i = 7; i > 0; i--){
432 sum = (input_buf[
row *
w +
col]) >> 1;
433 sum += (input_buf[
row *
w +
col + 1] + input_buf[
row *
w +
col - 1]) >> 2;
435 output_buf[i *
output->w +
j] = sum;
446 sum = (output_buf[
row *
w +
col]) >> 1;
447 sum += (output_buf[(
row + 1) *
w +
col] + output_buf[(
row - 1) *
w +
col]) >> 2;
449 output_buf[i *
output->w +
j] = sum;
536 output_buf[
output->w *
j + i] =
blend / (subpixel_factor * subpixel_factor);
557 for (
uint16_t x = 1; x < input->
w - 1; x++) {
558 for (
uint16_t y = 1; y < input->
h - 1; y++) {
559 dx_buf[(y - 1)*dx->
w + (x - 1)] = (
int16_t)input_buf[y * input->
w + x + 1] - (
int16_t)input_buf[y * input->
w + x - 1];
561 input_buf[(y - 1) * input->
w + x];
752 .
x =
vectors[i].pos.x / subpixel_factor,
753 .y =
vectors[i].pos.y / subpixel_factor
813 static int Sobel[9] = { -1, 0, 1, -2, 0, 2, -1, 0, 1};
818 for (
int x = -1;
x <= 1;
x++) {
819 for (
int y = -1;
y <= 1;
y++) {
951 if (delta_x > 0) {
incx = 1; }
952 else if (delta_x == 0) {
incx = 0; }
955 if (delta_y > 0) {
incy = 1; }
956 else if (delta_y == 0) {
incy = 0; }
961 delta_x =
abs(delta_x);
962 delta_y =
abs(delta_y);
963 if (delta_x > delta_y) { distance = delta_x * 20; }
964 else { distance = delta_y * 20; }
968 &&
t <= distance + 1;
t++) {
992 if (
xerr > distance) {
996 if (
yerr > distance) {
1092 for (
int x = 1;
x < width - 1;
x++) {
1103 for (
int y = 1;
y < height - 1;
y++) {
1110 for (
int x = 1;
x < width - 1;
x++) {
1128 for (
int x = 1;
x < width - 1;
x++) {
1143 for (
int x = 1;
x < width - 1;
x++) {
1152 for (
int y = 1;
y < height - 1;
y++) {
1158 for (
int x = 1;
x < width - 1;
x++) {
1173 for (
int x = 1;
x < width - 1;
x++) {
static const float offset[]
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.
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.
uint8_t ker_mul_3x3(uint8_t const *source, int_fast8_t const *kernel, uint8_t total, uint8_t setting, int width, int YUV)
Kernel multiplication for a 3 x 3 kernel.
void image_convolution_3x3(struct image_t *input, struct image_t *output, int_fast8_t const *kernel, uint8_t kernel_total)
Image convolution for a 3x3 kernel.
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...
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.
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.
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.
void image_draw_line(struct image_t *img, struct point_t *from, struct point_t *to)
Draw a pink line on the image.
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.
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...
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.
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.
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].
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...
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.
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.
void image_to_grayscale(struct image_t *input, struct image_t *output)
Convert an image to grayscale.
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,...
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...
void image_show_flow(struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor)
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.
void image_free(struct image_t *img)
Free the image.
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.
void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type)
Create a new image.
#define CACHE_LINE_LENGTH
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.
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.
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...
Image helper functions like resizing, color filter, converters...
struct timeval ts
The timestamp of creation.
uint32_t buf_size
The buffer size.
void * buf
Image buffer (depending on the image_type)
uint32_t x
The x coordinate of the point.
uint32_t pprz_ts
The timestamp in us since system startup.
uint32_t y
The y coordinate of the point.
enum image_type type
The image type.
struct FloatEulers eulers
Euler Angles at time of image.
@ IMAGE_GRAYSCALE
Grayscale image with only the Y part (uint8 per pixel)
@ IMAGE_YUV422
UYVY format (uint16 per pixel)
@ IMAGE_GRADIENT
An image gradient (int16 per pixel)
@ IMAGE_INT16
An image to hold disparity image data from openCV (int16 per pixel)
@ IMAGE_JPEG
An JPEG encoded image (not per pixel encoded)
efficient fixed-point optical-flow calculation
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.