37 #include "generated/airframe.h"
44 #define MAX_N_TEXTONS 255
53 #define TEXTONS_FPS 30
57 #ifndef TEXTONS_LOAD_DICTIONARY
58 #define TEXTONS_LOAD_DICTIONARY 1
62 #ifndef TEXTONS_REINITIALIZE_DICTIONARY
63 #define TEXTONS_REINITIALIZE_DICTIONARY 0
68 #define TEXTONS_ALPHA 0
72 #ifndef TEXTONS_N_TEXTONS
73 #define TEXTONS_N_TEXTONS 20
77 #ifndef TEXTONS_N_SAMPLES
78 #define TEXTONS_N_SAMPLES 250
82 #ifndef TEXTONS_PATCH_SIZE
83 #define TEXTONS_PATCH_SIZE 6
87 #ifndef TEXTONS_N_LEARNING_SAMPLES
88 #define TEXTONS_N_LEARNING_SAMPLES 5000
92 #ifndef TEXTONS_FULL_SAMPLING
93 #define TEXTONS_FULL_SAMPLING 0
97 #ifndef TEXTONS_BORDER_WIDTH
98 #define TEXTONS_BORDER_WIDTH 0
102 #ifndef TEXTONS_BORDER_HEIGHT
103 #define TEXTONS_BORDER_HEIGHT 0
107 #ifndef TEXTONS_DICTIONARY_NUMBER
108 #define TEXTONS_DICTIONARY_NUMBER 0
112 #ifndef TEXTONS_DICTIONARY_PATH
113 #define TEXTONS_DICTIONARY_PATH /data/ftp/internal_000
149 if (img->
buf_size == 0) {
return img; }
186 printf(
"Enough learning!\n");
229 int i, j,
w,
s, texton, c;
244 printf(
"Intializing dictionary!\n");
255 buf =
frame + (width * 2 * (i + y)) + 2 * x;
258 printf(
"Setting dictionary:\n");
278 float *texton_distances, * **patch;
279 texton_distances = (
float *)calloc(
n_textons,
sizeof(
float));
280 patch = (
float ** *)calloc(
patch_size,
sizeof(
float **));
283 patch[i] = (
float **)calloc(
patch_size,
sizeof(
float *));
285 patch[i][j] = (
float *)calloc(2,
sizeof(
float));
296 for (texton = 0; texton <
n_textons; texton++) {
297 texton_distances[texton] = 0;
302 buf =
frame + (width * 2 * (i + y)) + 2 * x;
305 patch[i][j][0] = (float) *
buf;
308 patch[i][j][1] = (float) *
buf;
316 for (c = 0; c < 2; c++) {
318 for (texton = 0; texton <
n_textons; texton++) {
319 texton_distances[texton] += (patch[i][j][c] -
dictionary[texton][i][j][c])
320 * (patch[i][j][c] -
dictionary[texton][i][j][c]);
328 float min_dist = texton_distances[0];
329 for (texton = 1; texton <
n_textons; texton++) {
330 if (texton_distances[texton] < min_dist) {
331 min_dist = texton_distances[texton];
339 for (c = 0; c < 2; c++) {
340 error_texton = patch[i][j][c] -
dictionary[assignment][i][j][c];
358 free(texton_distances);
376 int n_extracted_textons = 0;
385 float *texton_distances, * **patch;
386 texton_distances = (
float *)calloc(
n_textons,
sizeof(
float));
387 patch = (
float ** *)calloc(
patch_size,
sizeof(
float **));
389 patch[i] = (
float **)calloc(
patch_size,
sizeof(
float *));
391 patch[i][j] = (
float *)calloc(2,
sizeof(
float));
405 for (texton = 0; texton <
n_textons; texton++) {
406 texton_distances[texton] = 0;
411 buf =
frame + (width * 2 * (i + y)) + 2 * x;
414 patch[i][j][0] = (float) *
buf;
417 patch[i][j][1] = (float) *
buf;
425 for (c = 0; c < 2; c++) {
427 for (texton = 0; texton <
n_textons; texton++) {
428 texton_distances[texton] += (patch[i][j][c] -
dictionary[texton][i][j][c])
429 * (patch[i][j][c] -
dictionary[texton][i][j][c]);
438 float min_dist = texton_distances[0];
439 for (texton = 1; texton <
n_textons; texton++) {
440 if (texton_distances[texton] < min_dist) {
441 min_dist = texton_distances[texton];
448 n_extracted_textons++;
473 if (n_extracted_textons > 0) {
489 free(texton_distances);
512 printf(
"Filename: %s\n", filename);
513 perror(
"Error while opening the file.\n");
552 printf(
"Texton dictionary %d does not exist, we start learning one.\n",
dictionary_number);
564 printf(
"Textons init\n");
575 dictionary[
w][i][j] = (
float *) calloc(2,
sizeof(
float));
596 float entropy = 0.0f;
598 for (i = 0; i <
D; i++) {
600 entropy -= p_dist[i] * log2(p_dist[i]);
struct video_listener * cv_add_to_device(struct video_config_t *device, cv_function func, uint16_t fps, uint8_t id)
Computer vision framework for onboard processing.
if(GpsFixValid() &&e_identification_started)
uint32_t buf_size
The buffer size.
void * buf
Image buffer (depending on the image_type)
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Architecture independent timing functions.
void save_texton_dictionary(void)
Save the texton dictionary.
struct video_listener * listener
void load_texton_dictionary(void)
Load a texton dictionary.
float * texton_distribution
#define TEXTONS_PATCH_SIZE
uint32_t n_learning_samples
#define TEXTONS_DICTIONARY_NUMBER
#define TEXTONS_N_TEXTONS
void DictionaryTrainingYUV(uint8_t *frame, uint16_t width, uint16_t height)
Function that performs one pass for dictionary training.
static FILE * dictionary_logger
float get_entropy(float *p_dist, int D)
Function that calculates a base-2 Shannon entropy for a probability distribution.
#define TEXTONS_DICTIONARY_PATH
uint8_t dictionary_initialized
#define TEXTONS_LOAD_DICTIONARY
uint8_t reinitialize_dictionary
#define TEXTONS_BORDER_HEIGHT
void textons_init(void)
Initialize.
void DistributionExtraction(uint8_t *frame, uint16_t width, uint16_t height)
Function that extracts a texton histogram from an image.
#define TEXTONS_N_LEARNING_SAMPLES
#define TEXTONS_BORDER_WIDTH
uint8_t dictionary_number
#define TEXTONS_N_SAMPLES
#define TEXTONS_REINITIALIZE_DICTIONARY
struct image_t * texton_func(struct image_t *img, UNUSED uint8_t p)
Main texton processing function that first either loads or learns a dictionary and then extracts the ...
#define TEXTONS_FULL_SAMPLING
Takes an image and represents the texture and colors in the image with a texton histogram.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.