问题描述
我对opencv flann :: Index有一些问题 -
我正在创建索引
Mat samples = Mat :: zeros(vfv_net_quie.size(),24,CV_32F);
for(int i = 0; i< vfv_net_quie.size(); i ++)
{
for(int j = 0; j {
samples.at< float>(i,j)=(float)vfv_net_quie [i] .vfv [j]
}
}
cv :: flann :: Index flann_index(
samples,
cv :: flann :: KDTreeIndexParams(4),
cvflann: :FLANN_DIST_EUCLIDEAN
);
flann_index.save(c:\\index.fln);
这是我试图加载它并找到最近的neiborhoods
cv :: flann :: Index flann_index(Mat(),
cv :: flann :: SavedIndexParams(c:\\index .fln),
cvflann :: FLANN_DIST_EUCLIDEAN
);
cv :: Mat resps(vfv_reg_quie.size(),K,CV_32F);
cv :: Mat nresps(vfv_reg_quie.size(),K,CV_32S);
cv :: Mat dists(vfv_reg_quie.size(),K,CV_32F);
flann_index.knnSearch(sample,nresps,dists,K,cv :: flann :: SearchParams(64));
在miniflann.cpp行中存在违规行
((IndexType *)index) - > knnSearch(_query,_indices,_dists,knn,
(const :: cvflann :: SearchParams&)get_params ));
请帮助
不应将flann文件加载到 Mat()
中,因为它是存储索引的位置。它是在调用构造函数之后销毁的临时对象。这就是为什么当你调用 knnSearch()
时,索引不指向任何有用的原因。
/ p>
cv :: Mat indexMat;
cv :: flann :: Index flann_index(
indexMat,
cv :: flann :: SavedIndexParams(c:\\index.fln),
cvflann: :FLANN_DIST_EUCLIDEAN
);
导致:
读取FLANN索引错误:保存的数据大小(100,64)或类型(5)不同于传递的(0,0),0
这意味着矩阵必须以正确的维度初始化(对我来说似乎很蠢,因为我不一定知道,有多少元素存储在我的索引中)。
cv :: Mat indexMat(samples.size(),CV_32FC1);
cv :: flann :: Index flann_index(
indexMat,
cv :: flann :: SavedIndexParams(c:\\index.fln),
cvflann: :FLANN_DIST_EUCLIDEAN
);
I have some problems with opencv flann::Index -
I'm creating index
Mat samples = Mat::zeros(vfv_net_quie.size(),24,CV_32F);
for (int i =0; i < vfv_net_quie.size();i++)
{
for (int j = 0;j<24;j++)
{
samples.at<float>(i,j)=(float)vfv_net_quie[i].vfv[j];
}
}
cv::flann::Index flann_index(
samples,
cv::flann::KDTreeIndexParams(4),
cvflann::FLANN_DIST_EUCLIDEAN
);
flann_index.save("c:\\index.fln");
A fter that I'm tryin to load it and find nearest neiborhoods
cv::flann::Index flann_index(Mat(),
cv::flann::SavedIndexParams("c:\\index.fln"),
cvflann::FLANN_DIST_EUCLIDEAN
);
cv::Mat resps(vfv_reg_quie.size(), K, CV_32F);
cv::Mat nresps(vfv_reg_quie.size(), K, CV_32S);
cv::Mat dists(vfv_reg_quie.size(), K, CV_32F);
flann_index.knnSearch(sample,nresps,dists,K,cv::flann::SearchParams(64));
And have access violation in miniflann.cpp in line
((IndexType*)index)->knnSearch(_query, _indices, _dists, knn,
(const ::cvflann::SearchParams&)get_params(params));
Please help
You should not load the flann-file into a Mat()
, as it is the place where the index is stored. It is a temporary object destroyed after the constructor was called. That's why the index isn't pointing anywhere useful when you call knnSearch()
.
I tried following:
cv::Mat indexMat;
cv::flann::Index flann_index(
indexMat,
cv::flann::SavedIndexParams("c:\\index.fln"),
cvflann::FLANN_DIST_EUCLIDEAN
);
resulting in:
Reading FLANN index error: the saved data size (100, 64) or type (5) is different from the passed one (0, 0), 0
which means, that the matrix has to be initialized with the correct dimensions (seems very stupid to me, as I don't necessarily know, how many elements are stored in my index).
cv::Mat indexMat(samples.size(), CV_32FC1);
cv::flann::Index flann_index(
indexMat,
cv::flann::SavedIndexParams("c:\\index.fln"),
cvflann::FLANN_DIST_EUCLIDEAN
);
does the trick.
这篇关于如何使用opencv flann :: Index?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!