1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #3126 from avdmitry:move_KDTree_to_ml

This commit is contained in:
Vadim Pisarevsky
2014-09-14 18:57:23 +00:00
9 changed files with 288 additions and 185 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
set(the_description "2D Features Framework")
ocv_define_module(features2d opencv_imgproc opencv_flann OPTIONAL opencv_highgui)
ocv_define_module(features2d opencv_imgproc opencv_ml opencv_flann OPTIONAL opencv_highgui)
@@ -12,6 +12,7 @@
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2014, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
@@ -156,91 +157,6 @@ void NearestNeighborTest::run( int /*start_from*/ ) {
ts->set_failed_test_info( code );
}
//--------------------------------------------------------------------------------
class CV_KDTreeTest_CPP : public NearestNeighborTest
{
public:
CV_KDTreeTest_CPP() {}
protected:
virtual void createModel( const Mat& data );
virtual int checkGetPoins( const Mat& data );
virtual int findNeighbors( Mat& points, Mat& neighbors );
virtual int checkFindBoxed();
virtual void releaseModel();
KDTree* tr;
};
void CV_KDTreeTest_CPP::createModel( const Mat& data )
{
tr = new KDTree( data, false );
}
int CV_KDTreeTest_CPP::checkGetPoins( const Mat& data )
{
Mat res1( data.size(), data.type() ),
res3( data.size(), data.type() );
Mat idxs( 1, data.rows, CV_32SC1 );
for( int pi = 0; pi < data.rows; pi++ )
{
idxs.at<int>(0, pi) = pi;
// 1st way
const float* point = tr->getPoint(pi);
for( int di = 0; di < data.cols; di++ )
res1.at<float>(pi, di) = point[di];
}
// 3d way
tr->getPoints( idxs, res3 );
if( cvtest::norm( res1, data, NORM_L1) != 0 ||
cvtest::norm( res3, data, NORM_L1) != 0)
return cvtest::TS::FAIL_BAD_ACCURACY;
return cvtest::TS::OK;
}
int CV_KDTreeTest_CPP::checkFindBoxed()
{
vector<float> min( dims, static_cast<float>(minValue)), max(dims, static_cast<float>(maxValue));
vector<int> indices;
tr->findOrthoRange( min, max, indices );
// TODO check indices
if( (int)indices.size() != featuresCount)
return cvtest::TS::FAIL_BAD_ACCURACY;
return cvtest::TS::OK;
}
int CV_KDTreeTest_CPP::findNeighbors( Mat& points, Mat& neighbors )
{
const int emax = 20;
Mat neighbors2( neighbors.size(), CV_32SC1 );
int j;
for( int pi = 0; pi < points.rows; pi++ )
{
// 1st way
Mat nrow = neighbors.row(pi);
tr->findNearest( points.row(pi), neighbors.cols, emax, nrow );
// 2nd way
vector<int> neighborsIdx2( neighbors2.cols, 0 );
tr->findNearest( points.row(pi), neighbors2.cols, emax, neighborsIdx2 );
vector<int>::const_iterator it2 = neighborsIdx2.begin();
for( j = 0; it2 != neighborsIdx2.end(); ++it2, j++ )
neighbors2.at<int>(pi,j) = *it2;
}
// compare results
if( cvtest::norm( neighbors, neighbors2, NORM_L1 ) != 0 )
return cvtest::TS::FAIL_BAD_ACCURACY;
return cvtest::TS::OK;
}
void CV_KDTreeTest_CPP::releaseModel()
{
delete tr;
}
//--------------------------------------------------------------------------------
class CV_FlannTest : public NearestNeighborTest
{
@@ -402,7 +318,6 @@ void CV_FlannSavedIndexTest::createModel(const cv::Mat &data)
remove( filename.c_str() );
}
TEST(Features2d_KDTree_CPP, regression) { CV_KDTreeTest_CPP test; test.safe_run(); }
TEST(Features2d_FLANN_Linear, regression) { CV_FlannLinearIndexTest test; test.safe_run(); }
TEST(Features2d_FLANN_KMeans, regression) { CV_FlannKMeansIndexTest test; test.safe_run(); }
TEST(Features2d_FLANN_KDTree, regression) { CV_FlannKDTreeIndexTest test; test.safe_run(); }
+1
View File
@@ -13,6 +13,7 @@
#include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/ml.hpp"
#include <iostream>
#endif