void
IntensityDescriptorExtractor::initialize() {
  _descriptor_len = _feature_window_size * _feature_window_size;
  // omit a pixel from the descriptor where doing so results in a descriptor
  // length that's a multiple of 16 (e.g., feature window sizes 7, 9, etc.)
  // This makes for faster descriptor comparisons.  If using other feature
  // window sizes (e.g., 8, 10) then there's no significant advantage for
  // omitting that pixel.
  if((_descriptor_len - 1) % 16 == 0) {
    _descriptor_len -= 1;
  }

  // descriptor properties
  _descriptor_stride = round_up_to_multiple(_descriptor_len, ALIGNMENT);
  _brightess_offset_num_sse_ops = _descriptor_stride / 16;
  _num_descriptor_pad_bytes = _descriptor_stride - _descriptor_len;

  // populate the descriptor offset vector.  This vector stores the index
  // offsets of descriptor pixels for a descriptor centered around a given
  // pixel.
  _descriptor_index_offsets = new int[_descriptor_len];
  int i=0;
  int dr = (_feature_window_size - 1) / 2;
  for(int y_offset = -dr; y_offset<=dr; y_offset++) {
    for(int x_offset = -dr; x_offset<=dr && i<_descriptor_len; x_offset++) {
      _descriptor_index_offsets[i] = y_offset * _raw_gray_stride + x_offset;
      i++;
    }
  }
  assert(i == _descriptor_len);

  if(0 != posix_memalign((void**)&_descriptor_brightness_offset, ALIGNMENT, 16))
      fprintf(stderr, "error allocating descriptor brightness offset\n");
}
示例#2
0
size_t LookupTables::add_table(DeviceScene *dscene, vector<float>& data)
{
	assert(data.size() > 0);

	need_update = true;

	Table new_table;
	new_table.offset = 0;
	new_table.size = round_up_to_multiple(data.size(), TABLE_CHUNK_SIZE);

	/* find space to put lookup table */
	list<Table>::iterator table;

	for(table = lookup_tables.begin(); table != lookup_tables.end(); table++) {
		if(new_table.offset + new_table.size <= table->offset) {
			lookup_tables.insert(table, new_table);
			break;
		}
		else
			new_table.offset = table->offset + table->size;
	}

	if(table == lookup_tables.end()) {
		/* add at the end */
		lookup_tables.push_back(new_table);
		dscene->lookup_table.resize(new_table.offset + new_table.size);
	}

	/* copy table data and return offset */
	dscene->lookup_table.copy_at(&data[0], new_table.offset, data.size());
	return new_table.offset;
}
示例#3
0
PyramidLevel::PyramidLevel(int width, int height, int level_num,
                           int feature_window_size,
                           GridKeyPointFilter& grid_filter) :
    _grid_filter(grid_filter)
{
  _width = width;
  _height = height;
  _raw_gray_stride = round_up_to_multiple(_width, ALIGNMENT);
  _descriptor_extractor = new IntensityDescriptorExtractor(_raw_gray_stride, feature_window_size);

  int status = posix_memalign((void**)&_raw_gray, ALIGNMENT, _raw_gray_stride * _height);
  if(0 != status) {
      fprintf(stderr, "memory allocation (%d bytes) failed for pyramid level %d\n",
              _raw_gray_stride * _height, level_num);
      _raw_gray = NULL;
  }
  memset(_raw_gray, 0, _raw_gray_stride * _height);

  _keypoint_min_x = feature_window_size;
  _keypoint_min_y = feature_window_size;
  _keypoint_max_x = _width - feature_window_size - 2;
  _keypoint_max_y = _height - feature_window_size - 2;

  // allocate workspace for computing the next pyramid level
  int pyrbuf_size = gauss_pyr_down_get_buf_size_8u_C1R(_width, _height);
  _pyrbuf = (uint8_t*) malloc(pyrbuf_size);

  _level_num = level_num;

  _num_keypoints = 0;
  _keypoints_capacity = 1500;
  _keypoints = new KeypointData[_keypoints_capacity];

  _initial_keypoints.reserve(2000);

  _descriptors = NULL;

  // allocate descriptor buffers
  int desc_buf_size = _keypoints_capacity * _descriptor_extractor->getDescriptorStride();
  if(0 != posix_memalign((void**)&_descriptors, ALIGNMENT, desc_buf_size)) {
    fprintf(stderr, "error allocating descriptor memory\n");
  }
}