31
#ifndef OPENCV_FLANN_GROUND_TRUTH_H_
32
#define OPENCV_FLANN_GROUND_TRUTH_H_
43
template
<
typename
Distance>
44
void
find_nearest(
const
Matrix<typename Distance::ElementType>& dataset,
typename
Distance::ElementType* query,
int* matches,
int
nn,
45
int
skip = 0, Distance distance = Distance())
47
typedef
typename
Distance::ResultType DistanceType;
50
std::vector<int> match(n);
51
std::vector<DistanceType> dists(n);
53
dists[0] = distance(dataset[0], query, dataset.cols);
57
for
(
size_t
i=1; i<dataset.rows; ++i) {
58
DistanceType tmp = distance(dataset[i], query, dataset.cols);
64
else
if
(tmp < dists[dcnt-1]) {
66
match[dcnt-1] = (int)i;
71
while
(j>=1 && dists[j]<dists[j-1]) {
78
for
(
int
i=0; i<nn; ++i) {
79
matches[i] = match[i+skip];
84
template
<
typename
Distance>
85
void
compute_ground_truth(
const
Matrix<typename Distance::ElementType>& dataset,
const
Matrix<typename Distance::ElementType>& testset, Matrix<int>& matches,
86
int
skip=0, Distance d = Distance())
88
for
(
size_t
i=0; i<testset.rows; ++i) {
89
find_nearest<Distance>(dataset, testset[i], matches[i], (
int)matches.cols, skip, d);
CV_EXPORTS void swap(Mat &a, Mat &b)
Swaps two matrices