gpt4 book ai didi

opencv - opencv flann 库是否支持整数数据?

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:00 24 4
gpt4 key购买 nike

您好,我正在尝试对整数数据进行最近邻查询。似乎 cv::flann 不支持这个。这是真的吗?

最佳答案

是的,可以对整数数据使用 FLANN 最近邻搜索。您需要对整数使用距离度量。一些距离度量是模板,根据数据类型进行参数化(如下例所示),其他度量具有硬编码类型(例如 HammingLUT 具有 unsigned char 元素类型和 int 结果(距离)类型)。您还可以实现自己的距离测量,请参阅 <opencv2/flann/dist.h>了解详情。

示例 - 来自使用 unsigned char 的代码的引用数据:

// we use euclidean distances on unsigned chars:
typedef cv::flann::L2<unsigned char> Distance_U8;
cv::flann::GenericIndex< Distance_U8 > * m_flann;

// ...
// we have 3d features
cv::Mat features( features_count, 3, CV_8UC1 );

// ... fill the features matrix ...

// ... build the index ...
m_flann = new cv::flann::GenericIndex< Distance_U8 > (features, params);

// ...

// how many neighbours per query?
in knn = 5;
// search params - see documentation
cvflann::SearchParams params;

// prepare the matrices
// query data - unsigned chars, 3d (like features)
cv::Mat input_1( n_pixels, 3, CV_8UC1 ),
// indices into features array - integers
indices_1( n_pixels, knn, CV_32S ),
// distances - floats (even with integer data distances are floats)
dists_1( n_pixels, knn, CV_32F );

m_flann->knnSearch( input_1, indices_1, dists_1, 1, params);

关于opencv - opencv flann 库是否支持整数数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7390897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com