Go to the documentation of this file.00001 #include "pyramid_level.hpp"
00002
00003 #include <stdio.h>
00004
00005 #include "internal_utils.hpp"
00006 #include "gauss_pyramid.h"
00007
00008 #ifndef ALIGNMENT
00009 #define ALIGNMENT 16
00010 #endif
00011
00012 namespace fovis
00013 {
00014
00015 PyramidLevel::PyramidLevel(int width, int height, int level_num,
00016 int feature_window_size,
00017 GridKeyPointFilter& grid_filter) :
00018 _grid_filter(grid_filter)
00019 {
00020 _width = width;
00021 _height = height;
00022 _raw_gray_stride = round_up_to_multiple(_width, ALIGNMENT);
00023 _descriptor_extractor = new IntensityDescriptorExtractor(_raw_gray_stride, feature_window_size);
00024
00025 int status = posix_memalign((void**)&_raw_gray, ALIGNMENT, _raw_gray_stride * _height);
00026 if(0 != status) {
00027 fprintf(stderr, "memory allocation (%d bytes) failed for pyramid level %d\n",
00028 _raw_gray_stride * _height, level_num);
00029 _raw_gray = NULL;
00030 }
00031 memset(_raw_gray, 0, _raw_gray_stride * _height);
00032
00033 _keypoint_min_x = feature_window_size;
00034 _keypoint_min_y = feature_window_size;
00035 _keypoint_max_x = _width - feature_window_size - 2;
00036 _keypoint_max_y = _height - feature_window_size - 2;
00037
00038
00039 int pyrbuf_size = gauss_pyr_down_get_buf_size_8u_C1R(_width, _height);
00040 _pyrbuf = (uint8_t*) malloc(pyrbuf_size);
00041
00042 _level_num = level_num;
00043
00044 _num_keypoints = 0;
00045 _keypoints_capacity = 1500;
00046 _keypoints = new KeypointData[_keypoints_capacity];
00047
00048 _initial_keypoints.reserve(2000);
00049
00050 _descriptors = NULL;
00051
00052
00053 int desc_buf_size = _keypoints_capacity * _descriptor_extractor->getDescriptorStride();
00054 if(0 != posix_memalign((void**)&_descriptors, ALIGNMENT, desc_buf_size)) {
00055 fprintf(stderr, "error allocating descriptor memory\n");
00056 }
00057 }
00058
00059 void
00060 PyramidLevel::increase_capacity(int new_capacity)
00061 {
00062 _keypoints_capacity = new_capacity;
00063 delete[] _keypoints;
00064 _keypoints = new KeypointData[_keypoints_capacity];
00065
00066
00067 int descriptor_buf_size = _keypoints_capacity * getDescriptorStride();
00068 free(_descriptors);
00069 int status = posix_memalign((void**)&_descriptors, ALIGNMENT,
00070 descriptor_buf_size);
00071 if(0 != status) {
00072 fprintf(stderr, "error allocating descriptor memory\n");
00073 }
00074 }
00075
00076 PyramidLevel::~PyramidLevel()
00077 {
00078 free(_raw_gray);
00079 free(_descriptors);
00080 free(_pyrbuf);
00081 free(_keypoints);
00082 delete _descriptor_extractor;
00083 _raw_gray = NULL;
00084 _descriptors = NULL;
00085 _pyrbuf = NULL;
00086 _keypoints = NULL;
00087 _keypoints_capacity = 0;
00088 }
00089
00090 void
00091 PyramidLevel::populateDescriptorInterp(float x, float y, uint8_t* descriptor) const
00092 {
00093 _descriptor_extractor->populateDescriptorInterp(_raw_gray, x, y, descriptor);
00094 }
00095
00096 void
00097 PyramidLevel::populateDescriptorAligned(int x, int y, uint8_t* descriptor) const
00098 {
00099 _descriptor_extractor->populateDescriptorAligned(_raw_gray, x, y, descriptor);
00100 }
00101
00102 void
00103 PyramidLevel::populateDescriptorsInterp(const KeypointData* keypoints,
00104 int num_keypoints,
00105 uint8_t* descriptors) const
00106 {
00107 _descriptor_extractor->populateDescriptorsInterp(_raw_gray, keypoints,
00108 num_keypoints, descriptors);
00109 }
00110
00111 void
00112 PyramidLevel::populateDescriptorsAligned(const KeypointData* keypoints,
00113 int num_keypoints,
00114 uint8_t* descriptors) const
00115 {
00116 _descriptor_extractor->populateDescriptorsAligned(_raw_gray, keypoints,
00117 num_keypoints, descriptors);
00118 }
00119
00120 }