NNIndex<Distance>* load_saved_index(const Matrix<typename Distance::ElementType>& dataset, const std::string& filename, Distance distance) { typedef typename Distance::ElementType ElementType; FILE* fin = fopen(filename.c_str(), "rb"); if (fin == NULL) { return NULL; } IndexHeader header = load_header(fin); if (header.data_type != flann_datatype<ElementType>::value) { throw FLANNException("Datatype of saved index is different than of the one to be created."); } // We cannot make this check now, because the index and the dataset might be of different size // some entries of the dataset might not be used in the index /* if ((size_t(header.rows) != dataset.rows)||(size_t(header.cols) != dataset.cols)) { throw FLANNException("The index saved belongs to a different dataset"); } */ IndexParams params; params["algorithm"] = header.index_type; NNIndex<Distance>* nnIndex = create_index_by_type<Distance>(dataset, params, distance); nnIndex->loadIndex(fin); fclose(fin); return nnIndex; }
NNIndex<Distance>* load_saved_index(const Matrix<typename Distance::ElementType>& dataset, const cv::String& filename, Distance distance) { typedef typename Distance::ElementType ElementType; FILE* fin = fopen(filename.c_str(), "rb"); if (fin == NULL) { return NULL; } IndexHeader header = load_header(fin); /*if (header.data_type != Datatype<ElementType>::type()) { throw FLANNException("Datatype of saved index is different than of the one to be created."); } if ((size_t(header.rows) != dataset.rows)||(size_t(header.cols) != dataset.cols)) { throw FLANNException("The index saved belongs to a different dataset"); }*/ IndexParams params; params["algorithm"] = header.index_type; NNIndex<Distance>* nnIndex = create_index_by_type<Distance>(dataset, params, distance); nnIndex->loadIndex(fin); fclose(fin); return nnIndex; }