openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:0e0631af0305 1 /***********************************************************************
RyoheiHagimoto 0:0e0631af0305 2 * Software License Agreement (BSD License)
RyoheiHagimoto 0:0e0631af0305 3 *
RyoheiHagimoto 0:0e0631af0305 4 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
RyoheiHagimoto 0:0e0631af0305 5 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
RyoheiHagimoto 0:0e0631af0305 6 *
RyoheiHagimoto 0:0e0631af0305 7 * THE BSD LICENSE
RyoheiHagimoto 0:0e0631af0305 8 *
RyoheiHagimoto 0:0e0631af0305 9 * Redistribution and use in source and binary forms, with or without
RyoheiHagimoto 0:0e0631af0305 10 * modification, are permitted provided that the following conditions
RyoheiHagimoto 0:0e0631af0305 11 * are met:
RyoheiHagimoto 0:0e0631af0305 12 *
RyoheiHagimoto 0:0e0631af0305 13 * 1. Redistributions of source code must retain the above copyright
RyoheiHagimoto 0:0e0631af0305 14 * notice, this list of conditions and the following disclaimer.
RyoheiHagimoto 0:0e0631af0305 15 * 2. Redistributions in binary form must reproduce the above copyright
RyoheiHagimoto 0:0e0631af0305 16 * notice, this list of conditions and the following disclaimer in the
RyoheiHagimoto 0:0e0631af0305 17 * documentation and/or other materials provided with the distribution.
RyoheiHagimoto 0:0e0631af0305 18 *
RyoheiHagimoto 0:0e0631af0305 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
RyoheiHagimoto 0:0e0631af0305 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
RyoheiHagimoto 0:0e0631af0305 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
RyoheiHagimoto 0:0e0631af0305 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
RyoheiHagimoto 0:0e0631af0305 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
RyoheiHagimoto 0:0e0631af0305 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
RyoheiHagimoto 0:0e0631af0305 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
RyoheiHagimoto 0:0e0631af0305 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
RyoheiHagimoto 0:0e0631af0305 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
RyoheiHagimoto 0:0e0631af0305 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
RyoheiHagimoto 0:0e0631af0305 29 *************************************************************************/
RyoheiHagimoto 0:0e0631af0305 30
RyoheiHagimoto 0:0e0631af0305 31 #ifndef OPENCV_FLANN_INDEX_TESTING_H_
RyoheiHagimoto 0:0e0631af0305 32 #define OPENCV_FLANN_INDEX_TESTING_H_
RyoheiHagimoto 0:0e0631af0305 33
RyoheiHagimoto 0:0e0631af0305 34 #include <cstring>
RyoheiHagimoto 0:0e0631af0305 35 #include <cassert>
RyoheiHagimoto 0:0e0631af0305 36 #include <cmath>
RyoheiHagimoto 0:0e0631af0305 37
RyoheiHagimoto 0:0e0631af0305 38 #include "matrix.h"
RyoheiHagimoto 0:0e0631af0305 39 #include "nn_index.h"
RyoheiHagimoto 0:0e0631af0305 40 #include "result_set.h"
RyoheiHagimoto 0:0e0631af0305 41 #include "logger.h"
RyoheiHagimoto 0:0e0631af0305 42 #include "timer.h"
RyoheiHagimoto 0:0e0631af0305 43
RyoheiHagimoto 0:0e0631af0305 44
RyoheiHagimoto 0:0e0631af0305 45 namespace cvflann
RyoheiHagimoto 0:0e0631af0305 46 {
RyoheiHagimoto 0:0e0631af0305 47
RyoheiHagimoto 0:0e0631af0305 48 inline int countCorrectMatches(int* neighbors, int* groundTruth, int n)
RyoheiHagimoto 0:0e0631af0305 49 {
RyoheiHagimoto 0:0e0631af0305 50 int count = 0;
RyoheiHagimoto 0:0e0631af0305 51 for (int i=0; i<n; ++i) {
RyoheiHagimoto 0:0e0631af0305 52 for (int k=0; k<n; ++k) {
RyoheiHagimoto 0:0e0631af0305 53 if (neighbors[i]==groundTruth[k]) {
RyoheiHagimoto 0:0e0631af0305 54 count++;
RyoheiHagimoto 0:0e0631af0305 55 break;
RyoheiHagimoto 0:0e0631af0305 56 }
RyoheiHagimoto 0:0e0631af0305 57 }
RyoheiHagimoto 0:0e0631af0305 58 }
RyoheiHagimoto 0:0e0631af0305 59 return count;
RyoheiHagimoto 0:0e0631af0305 60 }
RyoheiHagimoto 0:0e0631af0305 61
RyoheiHagimoto 0:0e0631af0305 62
RyoheiHagimoto 0:0e0631af0305 63 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 64 typename Distance::ResultType computeDistanceRaport(const Matrix<typename Distance::ElementType>& inputData, typename Distance::ElementType* target,
RyoheiHagimoto 0:0e0631af0305 65 int* neighbors, int* groundTruth, int veclen, int n, const Distance& distance)
RyoheiHagimoto 0:0e0631af0305 66 {
RyoheiHagimoto 0:0e0631af0305 67 typedef typename Distance::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 68
RyoheiHagimoto 0:0e0631af0305 69 DistanceType ret = 0;
RyoheiHagimoto 0:0e0631af0305 70 for (int i=0; i<n; ++i) {
RyoheiHagimoto 0:0e0631af0305 71 DistanceType den = distance(inputData[groundTruth[i]], target, veclen);
RyoheiHagimoto 0:0e0631af0305 72 DistanceType num = distance(inputData[neighbors[i]], target, veclen);
RyoheiHagimoto 0:0e0631af0305 73
RyoheiHagimoto 0:0e0631af0305 74 if ((den==0)&&(num==0)) {
RyoheiHagimoto 0:0e0631af0305 75 ret += 1;
RyoheiHagimoto 0:0e0631af0305 76 }
RyoheiHagimoto 0:0e0631af0305 77 else {
RyoheiHagimoto 0:0e0631af0305 78 ret += num/den;
RyoheiHagimoto 0:0e0631af0305 79 }
RyoheiHagimoto 0:0e0631af0305 80 }
RyoheiHagimoto 0:0e0631af0305 81
RyoheiHagimoto 0:0e0631af0305 82 return ret;
RyoheiHagimoto 0:0e0631af0305 83 }
RyoheiHagimoto 0:0e0631af0305 84
RyoheiHagimoto 0:0e0631af0305 85 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 86 float search_with_ground_truth(NNIndex<Distance>& index, const Matrix<typename Distance::ElementType>& inputData,
RyoheiHagimoto 0:0e0631af0305 87 const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches, int nn, int checks,
RyoheiHagimoto 0:0e0631af0305 88 float& time, typename Distance::ResultType& dist, const Distance& distance, int skipMatches)
RyoheiHagimoto 0:0e0631af0305 89 {
RyoheiHagimoto 0:0e0631af0305 90 typedef typename Distance::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 91
RyoheiHagimoto 0:0e0631af0305 92 if (matches.cols<size_t(nn)) {
RyoheiHagimoto 0:0e0631af0305 93 Logger::info("matches.cols=%d, nn=%d\n",matches.cols,nn);
RyoheiHagimoto 0:0e0631af0305 94
RyoheiHagimoto 0:0e0631af0305 95 throw FLANNException("Ground truth is not computed for as many neighbors as requested");
RyoheiHagimoto 0:0e0631af0305 96 }
RyoheiHagimoto 0:0e0631af0305 97
RyoheiHagimoto 0:0e0631af0305 98 KNNResultSet<DistanceType> resultSet(nn+skipMatches);
RyoheiHagimoto 0:0e0631af0305 99 SearchParams searchParams(checks);
RyoheiHagimoto 0:0e0631af0305 100
RyoheiHagimoto 0:0e0631af0305 101 std::vector<int> indices(nn+skipMatches);
RyoheiHagimoto 0:0e0631af0305 102 std::vector<DistanceType> dists(nn+skipMatches);
RyoheiHagimoto 0:0e0631af0305 103 int* neighbors = &indices[skipMatches];
RyoheiHagimoto 0:0e0631af0305 104
RyoheiHagimoto 0:0e0631af0305 105 int correct = 0;
RyoheiHagimoto 0:0e0631af0305 106 DistanceType distR = 0;
RyoheiHagimoto 0:0e0631af0305 107 StartStopTimer t;
RyoheiHagimoto 0:0e0631af0305 108 int repeats = 0;
RyoheiHagimoto 0:0e0631af0305 109 while (t.value<0.2) {
RyoheiHagimoto 0:0e0631af0305 110 repeats++;
RyoheiHagimoto 0:0e0631af0305 111 t.start();
RyoheiHagimoto 0:0e0631af0305 112 correct = 0;
RyoheiHagimoto 0:0e0631af0305 113 distR = 0;
RyoheiHagimoto 0:0e0631af0305 114 for (size_t i = 0; i < testData.rows; i++) {
RyoheiHagimoto 0:0e0631af0305 115 resultSet.init(&indices[0], &dists[0]);
RyoheiHagimoto 0:0e0631af0305 116 index.findNeighbors(resultSet, testData[i], searchParams);
RyoheiHagimoto 0:0e0631af0305 117
RyoheiHagimoto 0:0e0631af0305 118 correct += countCorrectMatches(neighbors,matches[i], nn);
RyoheiHagimoto 0:0e0631af0305 119 distR += computeDistanceRaport<Distance>(inputData, testData[i], neighbors, matches[i], (int)testData.cols, nn, distance);
RyoheiHagimoto 0:0e0631af0305 120 }
RyoheiHagimoto 0:0e0631af0305 121 t.stop();
RyoheiHagimoto 0:0e0631af0305 122 }
RyoheiHagimoto 0:0e0631af0305 123 time = float(t.value/repeats);
RyoheiHagimoto 0:0e0631af0305 124
RyoheiHagimoto 0:0e0631af0305 125 float precicion = (float)correct/(nn*testData.rows);
RyoheiHagimoto 0:0e0631af0305 126
RyoheiHagimoto 0:0e0631af0305 127 dist = distR/(testData.rows*nn);
RyoheiHagimoto 0:0e0631af0305 128
RyoheiHagimoto 0:0e0631af0305 129 Logger::info("%8d %10.4g %10.5g %10.5g %10.5g\n",
RyoheiHagimoto 0:0e0631af0305 130 checks, precicion, time, 1000.0 * time / testData.rows, dist);
RyoheiHagimoto 0:0e0631af0305 131
RyoheiHagimoto 0:0e0631af0305 132 return precicion;
RyoheiHagimoto 0:0e0631af0305 133 }
RyoheiHagimoto 0:0e0631af0305 134
RyoheiHagimoto 0:0e0631af0305 135
RyoheiHagimoto 0:0e0631af0305 136 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 137 float test_index_checks(NNIndex<Distance>& index, const Matrix<typename Distance::ElementType>& inputData,
RyoheiHagimoto 0:0e0631af0305 138 const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches,
RyoheiHagimoto 0:0e0631af0305 139 int checks, float& precision, const Distance& distance, int nn = 1, int skipMatches = 0)
RyoheiHagimoto 0:0e0631af0305 140 {
RyoheiHagimoto 0:0e0631af0305 141 typedef typename Distance::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 142
RyoheiHagimoto 0:0e0631af0305 143 Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
RyoheiHagimoto 0:0e0631af0305 144 Logger::info("---------------------------------------------------------\n");
RyoheiHagimoto 0:0e0631af0305 145
RyoheiHagimoto 0:0e0631af0305 146 float time = 0;
RyoheiHagimoto 0:0e0631af0305 147 DistanceType dist = 0;
RyoheiHagimoto 0:0e0631af0305 148 precision = search_with_ground_truth(index, inputData, testData, matches, nn, checks, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 149
RyoheiHagimoto 0:0e0631af0305 150 return time;
RyoheiHagimoto 0:0e0631af0305 151 }
RyoheiHagimoto 0:0e0631af0305 152
RyoheiHagimoto 0:0e0631af0305 153 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 154 float test_index_precision(NNIndex<Distance>& index, const Matrix<typename Distance::ElementType>& inputData,
RyoheiHagimoto 0:0e0631af0305 155 const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches,
RyoheiHagimoto 0:0e0631af0305 156 float precision, int& checks, const Distance& distance, int nn = 1, int skipMatches = 0)
RyoheiHagimoto 0:0e0631af0305 157 {
RyoheiHagimoto 0:0e0631af0305 158 typedef typename Distance::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 159 const float SEARCH_EPS = 0.001f;
RyoheiHagimoto 0:0e0631af0305 160
RyoheiHagimoto 0:0e0631af0305 161 Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
RyoheiHagimoto 0:0e0631af0305 162 Logger::info("---------------------------------------------------------\n");
RyoheiHagimoto 0:0e0631af0305 163
RyoheiHagimoto 0:0e0631af0305 164 int c2 = 1;
RyoheiHagimoto 0:0e0631af0305 165 float p2;
RyoheiHagimoto 0:0e0631af0305 166 int c1 = 1;
RyoheiHagimoto 0:0e0631af0305 167 //float p1;
RyoheiHagimoto 0:0e0631af0305 168 float time;
RyoheiHagimoto 0:0e0631af0305 169 DistanceType dist;
RyoheiHagimoto 0:0e0631af0305 170
RyoheiHagimoto 0:0e0631af0305 171 p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 172
RyoheiHagimoto 0:0e0631af0305 173 if (p2>precision) {
RyoheiHagimoto 0:0e0631af0305 174 Logger::info("Got as close as I can\n");
RyoheiHagimoto 0:0e0631af0305 175 checks = c2;
RyoheiHagimoto 0:0e0631af0305 176 return time;
RyoheiHagimoto 0:0e0631af0305 177 }
RyoheiHagimoto 0:0e0631af0305 178
RyoheiHagimoto 0:0e0631af0305 179 while (p2<precision) {
RyoheiHagimoto 0:0e0631af0305 180 c1 = c2;
RyoheiHagimoto 0:0e0631af0305 181 //p1 = p2;
RyoheiHagimoto 0:0e0631af0305 182 c2 *=2;
RyoheiHagimoto 0:0e0631af0305 183 p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 184 }
RyoheiHagimoto 0:0e0631af0305 185
RyoheiHagimoto 0:0e0631af0305 186 int cx;
RyoheiHagimoto 0:0e0631af0305 187 float realPrecision;
RyoheiHagimoto 0:0e0631af0305 188 if (fabs(p2-precision)>SEARCH_EPS) {
RyoheiHagimoto 0:0e0631af0305 189 Logger::info("Start linear estimation\n");
RyoheiHagimoto 0:0e0631af0305 190 // after we got to values in the vecinity of the desired precision
RyoheiHagimoto 0:0e0631af0305 191 // use linear approximation get a better estimation
RyoheiHagimoto 0:0e0631af0305 192
RyoheiHagimoto 0:0e0631af0305 193 cx = (c1+c2)/2;
RyoheiHagimoto 0:0e0631af0305 194 realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 195 while (fabs(realPrecision-precision)>SEARCH_EPS) {
RyoheiHagimoto 0:0e0631af0305 196
RyoheiHagimoto 0:0e0631af0305 197 if (realPrecision<precision) {
RyoheiHagimoto 0:0e0631af0305 198 c1 = cx;
RyoheiHagimoto 0:0e0631af0305 199 }
RyoheiHagimoto 0:0e0631af0305 200 else {
RyoheiHagimoto 0:0e0631af0305 201 c2 = cx;
RyoheiHagimoto 0:0e0631af0305 202 }
RyoheiHagimoto 0:0e0631af0305 203 cx = (c1+c2)/2;
RyoheiHagimoto 0:0e0631af0305 204 if (cx==c1) {
RyoheiHagimoto 0:0e0631af0305 205 Logger::info("Got as close as I can\n");
RyoheiHagimoto 0:0e0631af0305 206 break;
RyoheiHagimoto 0:0e0631af0305 207 }
RyoheiHagimoto 0:0e0631af0305 208 realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 209 }
RyoheiHagimoto 0:0e0631af0305 210
RyoheiHagimoto 0:0e0631af0305 211 c2 = cx;
RyoheiHagimoto 0:0e0631af0305 212 p2 = realPrecision;
RyoheiHagimoto 0:0e0631af0305 213
RyoheiHagimoto 0:0e0631af0305 214 }
RyoheiHagimoto 0:0e0631af0305 215 else {
RyoheiHagimoto 0:0e0631af0305 216 Logger::info("No need for linear estimation\n");
RyoheiHagimoto 0:0e0631af0305 217 cx = c2;
RyoheiHagimoto 0:0e0631af0305 218 realPrecision = p2;
RyoheiHagimoto 0:0e0631af0305 219 }
RyoheiHagimoto 0:0e0631af0305 220
RyoheiHagimoto 0:0e0631af0305 221 checks = cx;
RyoheiHagimoto 0:0e0631af0305 222 return time;
RyoheiHagimoto 0:0e0631af0305 223 }
RyoheiHagimoto 0:0e0631af0305 224
RyoheiHagimoto 0:0e0631af0305 225
RyoheiHagimoto 0:0e0631af0305 226 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 227 void test_index_precisions(NNIndex<Distance>& index, const Matrix<typename Distance::ElementType>& inputData,
RyoheiHagimoto 0:0e0631af0305 228 const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches,
RyoheiHagimoto 0:0e0631af0305 229 float* precisions, int precisions_length, const Distance& distance, int nn = 1, int skipMatches = 0, float maxTime = 0)
RyoheiHagimoto 0:0e0631af0305 230 {
RyoheiHagimoto 0:0e0631af0305 231 typedef typename Distance::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 232
RyoheiHagimoto 0:0e0631af0305 233 const float SEARCH_EPS = 0.001;
RyoheiHagimoto 0:0e0631af0305 234
RyoheiHagimoto 0:0e0631af0305 235 // make sure precisions array is sorted
RyoheiHagimoto 0:0e0631af0305 236 std::sort(precisions, precisions+precisions_length);
RyoheiHagimoto 0:0e0631af0305 237
RyoheiHagimoto 0:0e0631af0305 238 int pindex = 0;
RyoheiHagimoto 0:0e0631af0305 239 float precision = precisions[pindex];
RyoheiHagimoto 0:0e0631af0305 240
RyoheiHagimoto 0:0e0631af0305 241 Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
RyoheiHagimoto 0:0e0631af0305 242 Logger::info("---------------------------------------------------------\n");
RyoheiHagimoto 0:0e0631af0305 243
RyoheiHagimoto 0:0e0631af0305 244 int c2 = 1;
RyoheiHagimoto 0:0e0631af0305 245 float p2;
RyoheiHagimoto 0:0e0631af0305 246
RyoheiHagimoto 0:0e0631af0305 247 int c1 = 1;
RyoheiHagimoto 0:0e0631af0305 248 float p1;
RyoheiHagimoto 0:0e0631af0305 249
RyoheiHagimoto 0:0e0631af0305 250 float time;
RyoheiHagimoto 0:0e0631af0305 251 DistanceType dist;
RyoheiHagimoto 0:0e0631af0305 252
RyoheiHagimoto 0:0e0631af0305 253 p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 254
RyoheiHagimoto 0:0e0631af0305 255 // if precision for 1 run down the tree is already
RyoheiHagimoto 0:0e0631af0305 256 // better then some of the requested precisions, then
RyoheiHagimoto 0:0e0631af0305 257 // skip those
RyoheiHagimoto 0:0e0631af0305 258 while (precisions[pindex]<p2 && pindex<precisions_length) {
RyoheiHagimoto 0:0e0631af0305 259 pindex++;
RyoheiHagimoto 0:0e0631af0305 260 }
RyoheiHagimoto 0:0e0631af0305 261
RyoheiHagimoto 0:0e0631af0305 262 if (pindex==precisions_length) {
RyoheiHagimoto 0:0e0631af0305 263 Logger::info("Got as close as I can\n");
RyoheiHagimoto 0:0e0631af0305 264 return;
RyoheiHagimoto 0:0e0631af0305 265 }
RyoheiHagimoto 0:0e0631af0305 266
RyoheiHagimoto 0:0e0631af0305 267 for (int i=pindex; i<precisions_length; ++i) {
RyoheiHagimoto 0:0e0631af0305 268
RyoheiHagimoto 0:0e0631af0305 269 precision = precisions[i];
RyoheiHagimoto 0:0e0631af0305 270 while (p2<precision) {
RyoheiHagimoto 0:0e0631af0305 271 c1 = c2;
RyoheiHagimoto 0:0e0631af0305 272 p1 = p2;
RyoheiHagimoto 0:0e0631af0305 273 c2 *=2;
RyoheiHagimoto 0:0e0631af0305 274 p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 275 if ((maxTime> 0)&&(time > maxTime)&&(p2<precision)) return;
RyoheiHagimoto 0:0e0631af0305 276 }
RyoheiHagimoto 0:0e0631af0305 277
RyoheiHagimoto 0:0e0631af0305 278 int cx;
RyoheiHagimoto 0:0e0631af0305 279 float realPrecision;
RyoheiHagimoto 0:0e0631af0305 280 if (fabs(p2-precision)>SEARCH_EPS) {
RyoheiHagimoto 0:0e0631af0305 281 Logger::info("Start linear estimation\n");
RyoheiHagimoto 0:0e0631af0305 282 // after we got to values in the vecinity of the desired precision
RyoheiHagimoto 0:0e0631af0305 283 // use linear approximation get a better estimation
RyoheiHagimoto 0:0e0631af0305 284
RyoheiHagimoto 0:0e0631af0305 285 cx = (c1+c2)/2;
RyoheiHagimoto 0:0e0631af0305 286 realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 287 while (fabs(realPrecision-precision)>SEARCH_EPS) {
RyoheiHagimoto 0:0e0631af0305 288
RyoheiHagimoto 0:0e0631af0305 289 if (realPrecision<precision) {
RyoheiHagimoto 0:0e0631af0305 290 c1 = cx;
RyoheiHagimoto 0:0e0631af0305 291 }
RyoheiHagimoto 0:0e0631af0305 292 else {
RyoheiHagimoto 0:0e0631af0305 293 c2 = cx;
RyoheiHagimoto 0:0e0631af0305 294 }
RyoheiHagimoto 0:0e0631af0305 295 cx = (c1+c2)/2;
RyoheiHagimoto 0:0e0631af0305 296 if (cx==c1) {
RyoheiHagimoto 0:0e0631af0305 297 Logger::info("Got as close as I can\n");
RyoheiHagimoto 0:0e0631af0305 298 break;
RyoheiHagimoto 0:0e0631af0305 299 }
RyoheiHagimoto 0:0e0631af0305 300 realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches);
RyoheiHagimoto 0:0e0631af0305 301 }
RyoheiHagimoto 0:0e0631af0305 302
RyoheiHagimoto 0:0e0631af0305 303 c2 = cx;
RyoheiHagimoto 0:0e0631af0305 304 p2 = realPrecision;
RyoheiHagimoto 0:0e0631af0305 305
RyoheiHagimoto 0:0e0631af0305 306 }
RyoheiHagimoto 0:0e0631af0305 307 else {
RyoheiHagimoto 0:0e0631af0305 308 Logger::info("No need for linear estimation\n");
RyoheiHagimoto 0:0e0631af0305 309 cx = c2;
RyoheiHagimoto 0:0e0631af0305 310 realPrecision = p2;
RyoheiHagimoto 0:0e0631af0305 311 }
RyoheiHagimoto 0:0e0631af0305 312
RyoheiHagimoto 0:0e0631af0305 313 }
RyoheiHagimoto 0:0e0631af0305 314 }
RyoheiHagimoto 0:0e0631af0305 315
RyoheiHagimoto 0:0e0631af0305 316 }
RyoheiHagimoto 0:0e0631af0305 317
RyoheiHagimoto 0:0e0631af0305 318 #endif //OPENCV_FLANN_INDEX_TESTING_H_