Class: OpenCV::CvFeatureTree

Inherits:
Object
  • Object
show all
Defined in:
ext/opencv/cvfeaturetree.cpp

Instance Method Summary collapse

Constructor Details

#new(desc) ⇒ CvFeatureTree

Create a new kd-tree

Parameters:

  • desc (CvMat)

    Descriptors



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'ext/opencv/cvfeaturetree.cpp', line 58

VALUE
rb_initialize(VALUE self, VALUE desc)
{
  CvMat* desc_mat = CVMAT_WITH_CHECK(desc);
  CvFeatureTreeWrap* self_ptr = (CvFeatureTreeWrap*)DATA_PTR(self);
  free(self_ptr);
  self_ptr = ALLOC(CvFeatureTreeWrap);
  try {
    self_ptr->feature_tree = cvCreateKDTree(desc_mat);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  self_ptr->desc = desc;
  return self;
}

Instance Method Details

#find_features(desc, k, emax) ⇒ Array

Find features from kd-tree

Parameters:

  • desc (CvMat)

    m x d matrix of (row-)vectors to find the nearest neighbors of.

  • k (Integer)

    The number of neighbors to find.

  • emax (Integer)

    The maximum number of leaves to visit.

Returns:

  • (Array)

    Array of [results, dist]

    • results: m x k set of row indices of matching vectors (referring to matrix passed to cvCreateFeatureTree). Contains -1 in some columns if fewer than k neighbors found.

    • dist: m x k matrix of distances to k nearest neighbors.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'ext/opencv/cvfeaturetree.cpp', line 86

VALUE
rb_find_features(VALUE self, VALUE desc, VALUE k, VALUE emax)
{
  CvMat* desc_mat = CVMAT_WITH_CHECK(desc);
  int _k = NUM2INT(k);
  VALUE results = cCvMat::new_object(desc_mat->rows, _k, CV_32SC1);
  VALUE dist = cCvMat::new_object(desc_mat->rows, _k, CV_64FC1);
  try {
    cvFindFeatures(CVFEATURETREE(self), desc_mat, CVMAT(results), CVMAT(dist), _k, NUM2INT(emax));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return rb_assoc_new(results, dist);
}