256 |
256 |
// cluster boundary index. Used when searching the kmeans tree
|
257 |
257 |
p["cb_index"] = cb_index;
|
258 |
258 |
}
|
|
259 |
HierarchicalClusteringIndexParams::HierarchicalClusteringIndexParams(int branching ,
|
|
260 |
flann_centers_init_t centers_init,
|
|
261 |
int trees, int leaf_size)
|
|
262 |
{
|
|
263 |
::cvflann::IndexParams& p = get_params(*this);
|
|
264 |
p["algorithm"] = FLANN_INDEX_HIERARCHICAL;
|
|
265 |
// The branching factor used in the hierarchical clustering
|
|
266 |
p["branching"] = branching;
|
|
267 |
// Algorithm used for picking the initial cluster centers
|
|
268 |
p["centers_init"] = centers_init;
|
|
269 |
// number of parallel trees to build
|
|
270 |
p["trees"] = trees;
|
|
271 |
// maximum leaf size
|
|
272 |
p["leaf_size"] = leaf_size;
|
|
273 |
}
|
259 |
274 |
|
260 |
275 |
LshIndexParams::LshIndexParams(int table_number, int key_size, int multi_probe_level)
|
261 |
276 |
{
|
262 |
277 |
::cvflann::IndexParams& p = get_params(*this);
|
263 |
278 |
p["algorithm"] = FLANN_INDEX_LSH;
|
264 |
279 |
// The number of hash tables to use
|
265 |
|
p["table_number"] = (unsigned)table_number;
|
|
280 |
p["table_number"] = (int)table_number;
|
266 |
281 |
// The length of the key in the hash tables
|
267 |
|
p["key_size"] = (unsigned)key_size;
|
|
282 |
p["key_size"] = (int)key_size;
|
268 |
283 |
// Number of levels to use in multi-probe (0 for standard LSH)
|
269 |
|
p["multi_probe_level"] = (unsigned)multi_probe_level;
|
|
284 |
p["multi_probe_level"] = (int)multi_probe_level;
|
270 |
285 |
}
|
271 |
286 |
|
272 |
287 |
SavedIndexParams::SavedIndexParams(const std::string& _filename)
|
... | ... | |
351 |
366 |
featureType = data.type();
|
352 |
367 |
distType = _distType;
|
353 |
368 |
|
354 |
|
if( algo == FLANN_INDEX_LSH )
|
|
369 |
if( algo == FLANN_INDEX_LSH || algo == FLANN_INDEX_HIERARCHICAL )
|
355 |
370 |
{
|
356 |
371 |
buildIndex_<HammingDistance, LshIndex>(index, data, params);
|
357 |
372 |
return;
|
... | ... | |
406 |
421 |
{
|
407 |
422 |
if( !index )
|
408 |
423 |
return;
|
409 |
|
if( algo == FLANN_INDEX_LSH )
|
|
424 |
if( algo == FLANN_INDEX_LSH || algo == FLANN_INDEX_HIERARCHICAL)
|
410 |
425 |
{
|
411 |
426 |
deleteIndex_<LshIndex>(index);
|
412 |
427 |
}
|
... | ... | |
539 |
554 |
OutputArray _dists, int knn, const SearchParams& params)
|
540 |
555 |
{
|
541 |
556 |
Mat query = _query.getMat(), indices, dists;
|
542 |
|
int dtype = algo == FLANN_INDEX_LSH ? CV_32S : CV_32F;
|
|
557 |
int dtype = algo == FLANN_INDEX_LSH? CV_32S : CV_32F;
|
543 |
558 |
|
544 |
559 |
createIndicesDists( _indices, _dists, indices, dists, query.rows, knn, knn, dtype );
|
545 |
560 |
|
546 |
|
if( algo == FLANN_INDEX_LSH )
|
|
561 |
if( algo == FLANN_INDEX_LSH || algo == FLANN_INDEX_HIERARCHICAL )
|
547 |
562 |
{
|
548 |
563 |
runKnnSearch_<HammingDistance, LshIndex>(index, query, indices, dists, knn, params);
|
549 |
564 |
return;
|
... | ... | |
588 |
603 |
CV_Assert( maxResults > 0 );
|
589 |
604 |
createIndicesDists( _indices, _dists, indices, dists, query.rows, maxResults, INT_MAX, dtype );
|
590 |
605 |
|
591 |
|
if( algo == FLANN_INDEX_LSH )
|
|
606 |
if( algo == FLANN_INDEX_LSH || algo == FLANN_INDEX_HIERARCHICAL )
|
592 |
607 |
CV_Error( CV_StsNotImplemented, "LSH index does not support radiusSearch operation" );
|
593 |
608 |
|
594 |
609 |
switch( distType )
|
... | ... | |
647 |
662 |
if (fout == NULL)
|
648 |
663 |
CV_Error_( CV_StsError, ("Can not open file %s for writing FLANN index\n", filename.c_str()) );
|
649 |
664 |
|
650 |
|
if( algo == FLANN_INDEX_LSH )
|
|
665 |
if( algo == FLANN_INDEX_LSH || algo == FLANN_INDEX_HIERARCHICAL)
|
651 |
666 |
{
|
652 |
667 |
saveIndex_<LshIndex>(this, index, fout);
|
653 |
668 |
fclose(fout);
|
... | ... | |
740 |
755 |
}
|
741 |
756 |
|
742 |
757 |
if( !((algo == FLANN_INDEX_LSH && featureType == CV_8U) ||
|
743 |
|
(algo != FLANN_INDEX_LSH && featureType == CV_32F)) )
|
|
758 |
(algo == FLANN_INDEX_HIERARCHICAL && featureType == CV_8U) ||
|
|
759 |
((algo != FLANN_INDEX_LSH || algo != FLANN_INDEX_HIERARCHICAL) && featureType == CV_32F)) )
|
744 |
760 |
{
|
745 |
761 |
fprintf(stderr, "Reading FLANN index error: unsupported feature type %d for the index type %d\n", featureType, algo);
|
746 |
762 |
fclose(fin);
|
... | ... | |
750 |
766 |
::cvflann::load_value(fin, idistType);
|
751 |
767 |
distType = (flann_distance_t)idistType;
|
752 |
768 |
|
753 |
|
if( algo == FLANN_INDEX_LSH )
|
|
769 |
if( algo == FLANN_INDEX_LSH || algo == FLANN_INDEX_HIERARCHICAL)
|
754 |
770 |
{
|
755 |
771 |
loadIndex_<HammingDistance, LshIndex>(this, index, data, fin);
|
756 |
772 |
}
|