|
|
@ -140,13 +140,12 @@ public: |
|
|
|
String getModelName() const CV_OVERRIDE { return NAME_BRUTE_FORCE; } |
|
|
|
String getModelName() const CV_OVERRIDE { return NAME_BRUTE_FORCE; } |
|
|
|
int getType() const CV_OVERRIDE { return ml::KNearest::BRUTE_FORCE; } |
|
|
|
int getType() const CV_OVERRIDE { return ml::KNearest::BRUTE_FORCE; } |
|
|
|
|
|
|
|
|
|
|
|
void findNearestCore( const Mat& _samples, int k0, const Range& range, |
|
|
|
void findNearestCore( const Mat& _samples, int k, const Range& range, |
|
|
|
Mat* results, Mat* neighbor_responses, |
|
|
|
Mat* results, Mat* neighbor_responses, |
|
|
|
Mat* dists, float* presult ) const |
|
|
|
Mat* dists, float* presult ) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
int testidx, baseidx, i, j, d = samples.cols, nsamples = samples.rows; |
|
|
|
int testidx, baseidx, i, j, d = samples.cols, nsamples = samples.rows; |
|
|
|
int testcount = range.end - range.start; |
|
|
|
int testcount = range.end - range.start; |
|
|
|
int k = std::min(k0, nsamples); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AutoBuffer<float> buf(testcount*k*2); |
|
|
|
AutoBuffer<float> buf(testcount*k*2); |
|
|
|
float* dbuf = buf.data(); |
|
|
|
float* dbuf = buf.data(); |
|
|
@ -215,7 +214,7 @@ public: |
|
|
|
float* nr = neighbor_responses->ptr<float>(testidx + range.start); |
|
|
|
float* nr = neighbor_responses->ptr<float>(testidx + range.start); |
|
|
|
for( j = 0; j < k; j++ ) |
|
|
|
for( j = 0; j < k; j++ ) |
|
|
|
nr[j] = rbuf[testidx*k + j]; |
|
|
|
nr[j] = rbuf[testidx*k + j]; |
|
|
|
for( ; j < k0; j++ ) |
|
|
|
for( ; j < k; j++ ) |
|
|
|
nr[j] = 0.f; |
|
|
|
nr[j] = 0.f; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -224,7 +223,7 @@ public: |
|
|
|
float* dptr = dists->ptr<float>(testidx + range.start); |
|
|
|
float* dptr = dists->ptr<float>(testidx + range.start); |
|
|
|
for( j = 0; j < k; j++ ) |
|
|
|
for( j = 0; j < k; j++ ) |
|
|
|
dptr[j] = dbuf[testidx*k + j]; |
|
|
|
dptr[j] = dbuf[testidx*k + j]; |
|
|
|
for( ; j < k0; j++ ) |
|
|
|
for( ; j < k; j++ ) |
|
|
|
dptr[j] = 0.f; |
|
|
|
dptr[j] = 0.f; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -307,6 +306,7 @@ public: |
|
|
|
{ |
|
|
|
{ |
|
|
|
float result = 0.f; |
|
|
|
float result = 0.f; |
|
|
|
CV_Assert( 0 < k ); |
|
|
|
CV_Assert( 0 < k ); |
|
|
|
|
|
|
|
k = std::min(k, samples.rows); |
|
|
|
|
|
|
|
|
|
|
|
Mat test_samples = _samples.getMat(); |
|
|
|
Mat test_samples = _samples.getMat(); |
|
|
|
CV_Assert( test_samples.type() == CV_32F && test_samples.cols == samples.cols ); |
|
|
|
CV_Assert( test_samples.type() == CV_32F && test_samples.cols == samples.cols ); |
|
|
@ -363,6 +363,7 @@ public: |
|
|
|
{ |
|
|
|
{ |
|
|
|
float result = 0.f; |
|
|
|
float result = 0.f; |
|
|
|
CV_Assert( 0 < k ); |
|
|
|
CV_Assert( 0 < k ); |
|
|
|
|
|
|
|
k = std::min(k, samples.rows); |
|
|
|
|
|
|
|
|
|
|
|
Mat test_samples = _samples.getMat(); |
|
|
|
Mat test_samples = _samples.getMat(); |
|
|
|
CV_Assert( test_samples.type() == CV_32F && test_samples.cols == samples.cols ); |
|
|
|
CV_Assert( test_samples.type() == CV_32F && test_samples.cols == samples.cols ); |
|
|
|