explanation on new cvspilltree in opencv subversion
2009-01-14 14:20
337 查看
checkout the new opencv.
in real world data, in lower dimension, spill tree outperform bbf by an order of computing time.
spill tree approximation result in 4 ms
best-bin-first approximation result in 20 ms
naive search result in 61 ms
test data can be found in: http://kdd.ics.uci.edu/databases/CorelFeatures/CorelFeatures.html
the test was done with LayoutHistogram.asc file.
in real world data, in lower dimension, spill tree outperform bbf by an order of computing time.
spill tree approximation result in 4 ms
best-bin-first approximation result in 20 ms
naive search result in 61 ms
test data can be found in: http://kdd.ics.uci.edu/databases/CorelFeatures/CorelFeatures.html
the test was done with LayoutHistogram.asc file.
#include "cv.h" #include <iostream> int main() { int n = 66615;//68039; int d = 32; int k = 10; CvRNG rng_state = cvRNG(0xffffffff); CvMat* toy = cvCreateMat( n, d, CV_64FC1 ); CvMat* vector = cvCreateMat( 1, d, CV_64FC1 ); //cvRandArr( &rng_state, toy, CV_RAND_UNI, cvRealScalar(0), cvRealScalar(1) ); //cvRandArr( &rng_state, vector, CV_RAND_UNI, cvRealScalar(0), cvRealScalar(1) ); freopen( "LayoutHistogram.asc", "r", stdin ); double* toyv = toy->data.db; int rn = cvRandInt( &rng_state ) % (n+1); double tmp; for ( int i = 0; i <= n; i++ ) { int id; std::cin>>id; if ( rn == i ) { double* vev = vector->data.db; for ( int j = 0; j < d; j++ ) { std::cin>>tmp; *vev = tmp; vev++; } } else { for ( int j = 0; j < d; j++ ) { std::cin>>tmp; *toyv = tmp; toyv++; } } } printf( "data generated/n" ); long long t; t = cvGetTickCount(); CvFeatureTree* tr = cvCreateSpillTree( toy, 2, .7, .1 ); t = cvGetTickCount() - t; printf( "spill tree created in %lld ms./n", t/1000000 ); double* vv = vector->data.db; printf( "test drive: " ); for ( int i = 0; i < d-1; i++ ) printf( "%f ", vv[i] ); printf( "%f/n", vv[d-1] ); CvMat* res = cvCreateMat( 1, k, CV_32SC1 ); CvMat* dist = cvCreateMat( 1, k, CV_64FC1 ); t = cvGetTickCount(); cvFindFeatures( tr, vector, res, dist, k, 0 ); t = cvGetTickCount() - t; printf( "spill tree approximation result in %lld ms:/n", t/1000000 ); vv = dist->data.db; int* idx = res->data.i; for ( int i = 0; i < k; i++ ) printf( "---sim: %f---i: %d---/n", vv[i], idx[i] ); cvReleaseFeatureTree( tr ); t = cvGetTickCount(); CvFeatureTree* bbf = cvCreateKDTree( toy ); t = cvGetTickCount() - t; printf( "kd tree created in %lld ms./n", t/1000000 ); t = cvGetTickCount(); cvFindFeatures( bbf, vector, res, dist, k, 20 ); t = cvGetTickCount() - t; printf( "best-bin-first approximation result in %lld ms:/n", t/1000000 ); vv = dist->data.db; idx = res->data.i; for ( int i = 0; i < k; i++ ) printf( "---sim: %f---i: %d---/n", vv[i], idx[i] ); CvMat** data = (CvMat**)cvAlloc( sizeof(CvMat*)*n ); for ( int i = 0; i < n; i++ ) { data[i] = cvCreateMatHeader( 1, d, CV_64FC1 ); cvSetData( data[i], toy->data.db+i*d, toy->step ); } double* norms = (double*)cvAlloc( sizeof(double)*n ); t = cvGetTickCount(); for ( int i = 0; i < n; i++ ) norms[i] = cvNorm( data[i], vector ); for ( int i = 0; i < k; i++ ) { int l = i; for ( int j = i+1; j < n; j++ ) if ( norms[j] < norms[l] ) l = j; double c; CV_SWAP( norms[l], norms[i], c ); } t = cvGetTickCount() - t; printf( "naive search result in %lld ms/n", t/1000000 ); for ( int i = 0; i < k; i++ ) printf( "---sim: %f---/n", norms[i] ); return 0; }
相关文章推荐
- Tips on using hierarchicalClustering in OpenCV
- What's New in J2SE 1.5 ? -- Interview on Joshua Bloch
- Vim – Open file in existing window new tab on Windows
- 奇葩问题:This file could not be checked in because the original version of the file on the server was moved or deleted. A new version of this file has been saved to the server, but your check-in comments were not saved
- Travel on the TranzAlpine Rail Line in New Zealand
- Install OpenCV-3.1.0 fails on Ubuntu 16.04 (‘memcpy’ was not declared in this scope)
- A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python)
- Restore n Recover Production DB to Point In Time on new machine
- A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python)
- install opencv on mac and use it in xcode
- Keep an eye on these 5 new features in RHEL 7
- A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python)
- Hwo to Open Navigation Item in New Window on SharePoint Portal
- New in Xdebug 2.2: Colours on the command line
- Get XML tree format based on the tree data in SQL server table
- New Findings on Sleep in Children, Older Adults
- Using Subversion and ViewCVS on Solaris 10
- On a new installed FreeBSD server, when you try to SSH to the server as root, you will end up in the
- SharePoint 2007 User Re-created in AD with new SID issue on MySite
- On Creating New Project in VS2013: Failed to Initialize the Powershell Host