mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
merged all the latest changes from 2.4 to trunk
This commit is contained in:
@@ -268,13 +268,15 @@ static Mat readMatFromBin( const string& filename )
|
||||
if( f )
|
||||
{
|
||||
int rows, cols, type, dataSize;
|
||||
fread( (void*)&rows, sizeof(int), 1, f );
|
||||
fread( (void*)&cols, sizeof(int), 1, f );
|
||||
fread( (void*)&type, sizeof(int), 1, f );
|
||||
fread( (void*)&dataSize, sizeof(int), 1, f );
|
||||
size_t elements_read1 = fread( (void*)&rows, sizeof(int), 1, f );
|
||||
size_t elements_read2 = fread( (void*)&cols, sizeof(int), 1, f );
|
||||
size_t elements_read3 = fread( (void*)&type, sizeof(int), 1, f );
|
||||
size_t elements_read4 = fread( (void*)&dataSize, sizeof(int), 1, f );
|
||||
CV_Assert(elements_read1 == 1 && elements_read2 == 1 && elements_read3 == 1 && elements_read4 == 1);
|
||||
|
||||
uchar* data = (uchar*)cvAlloc(dataSize);
|
||||
fread( (void*)data, 1, dataSize, f );
|
||||
size_t elements_read = fread( (void*)data, 1, dataSize, f );
|
||||
CV_Assert(elements_read == (size_t)(dataSize));
|
||||
fclose(f);
|
||||
|
||||
return Mat( rows, cols, type, data );
|
||||
@@ -1026,3 +1028,53 @@ TEST( Features2d_DescriptorExtractor_Calonder_float, regression )
|
||||
test.safe_run();
|
||||
}
|
||||
#endif*/ // CV_SSE2
|
||||
|
||||
TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression)
|
||||
{
|
||||
const int sz = 100;
|
||||
const int k = 3;
|
||||
|
||||
Ptr<DescriptorExtractor> ext = DescriptorExtractor::create("SURF");
|
||||
ASSERT_TRUE(ext != NULL);
|
||||
|
||||
Ptr<FeatureDetector> det = FeatureDetector::create("SURF");
|
||||
//"%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"
|
||||
ASSERT_TRUE(det != NULL);
|
||||
|
||||
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce");
|
||||
ASSERT_TRUE(matcher != NULL);
|
||||
|
||||
Mat imgT(sz, sz, CV_8U, Scalar(255));
|
||||
line(imgT, Point(20, sz/2), Point(sz-21, sz/2), Scalar(100), 2);
|
||||
line(imgT, Point(sz/2, 20), Point(sz/2, sz-21), Scalar(100), 2);
|
||||
vector<KeyPoint> kpT;
|
||||
kpT.push_back( KeyPoint(50, 50, 16, 0, 20000, 1, -1) );
|
||||
kpT.push_back( KeyPoint(42, 42, 16, 160, 10000, 1, -1) );
|
||||
Mat descT;
|
||||
ext->compute(imgT, kpT, descT);
|
||||
|
||||
Mat imgQ(sz, sz, CV_8U, Scalar(255));
|
||||
line(imgQ, Point(30, sz/2), Point(sz-31, sz/2), Scalar(100), 3);
|
||||
line(imgQ, Point(sz/2, 30), Point(sz/2, sz-31), Scalar(100), 3);
|
||||
vector<KeyPoint> kpQ;
|
||||
det->detect(imgQ, kpQ);
|
||||
Mat descQ;
|
||||
ext->compute(imgQ, kpQ, descQ);
|
||||
|
||||
vector<vector<DMatch> > matches;
|
||||
|
||||
matcher->knnMatch(descQ, descT, matches, k);
|
||||
|
||||
//cout << "\nBest " << k << " matches to " << descT.rows << " train desc-s." << endl;
|
||||
ASSERT_EQ(descQ.rows, matches.size());
|
||||
for(size_t i = 0; i<matches.size(); i++)
|
||||
{
|
||||
//cout << "\nmatches[" << i << "].size()==" << matches[i].size() << endl;
|
||||
ASSERT_GT(min(k, descT.rows), static_cast<int>(matches[i].size()));
|
||||
for(size_t j = 0; j<matches[i].size(); j++)
|
||||
{
|
||||
//cout << "\t" << matches[i][j].queryIdx << " -> " << matches[i][j].trainIdx << endl;
|
||||
ASSERT_EQ(matches[i][j].queryIdx, static_cast<int>(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user