std::vector<int> neighbors(1); std::vector<float> squaredDistances(1);
时间: 2024-05-18 14:13:02 浏览: 3
这段代码声明了两个长度为1的向量neighbors和squaredDistances,类型分别为int和float。这两个向量通常用于存储与查询点相邻的点的索引和它们之间的距离。在这段代码中,它们可能被用于K近邻搜索算法,即查询点的最近邻居点。每当调用K近邻搜索算法时,这两个向量都将被更新以反映最近邻居点的索引和距离。
相关问题
std::vector<float> squaredDistances(1);如果是计算汉明距离,这个怎么改
如果你要计算汉明距离,那么你需要将 `squaredDistances` 的类型从 `std::vector<float>` 改为 `std::vector<int>`,因为汉明距离是一个整数,而不是浮点数。同时,你需要将 `nearestKSearch` 函数的第三个参数从 `squaredDistances` 改为 `hammingDistances`,它是一个 `std::vector<int>` 类型的变量,用于存储汉明距离。修改后的代码如下所示:
```
std::vector<int> hammingDistances(1);
if (pcl_isfinite(scene_descriptors->at(i).descriptor[0])) {
int neighborCount = matching.nearestKSearch(scene_descriptors->at(i), 1, neighbors, hammingDistances);
if (neighborCount == 1 && hammingDistances[0] < threshold) {
pcl::Correspondence correspondence(neighbors[0], static_cast<int>(i), hammingDistances[0]);
model_scene_corrs->push_back(correspondence);
}
}
```
其中,`threshold` 是你根据实际数据特征设置的汉明距离的阈值。
void find_match_shot(pcl::PointCloud<pcl::BINARY>::Ptr shot1, pcl::PointCloud<pcl::BINARY>::Ptr shot2, pcl::CorrespondencesPtr model_scene_corrs) { clock_t start = clock(); pcl::KdTreeFLANNpcl::BINARY matching; matching.setInputCloud(shot1); for (size_t i = 0; i < shot2->size(); ++i) { std::vector<int> neighbors(1); std::vector<int> hammingDistances(1); int neighborCount = matching.nearestKSearch(shot2->at(i), 1, neighbors, hammingDistances); if (neighborCount == 1 && hammingDistances[0] < 0.05f) { pcl::Correspondence correspondence(neighbors[0], static_cast<int>(i), hammingDistances[0]); model_scene_corrs->push_back(correspondence); } }这样是对的吧
是的,对于二进制描述子,不需要判断是否是有限值,因此你可以直接删除原先的那行 `if` 语句,修改后的代码如下:
```
void find_match_shot(pcl::PointCloud<pcl::BINARY>::Ptr shot1, pcl::PointCloud<pcl::BINARY>::Ptr shot2, pcl::CorrespondencesPtr model_scene_corrs) {
clock_t start = clock();
pcl::KdTreeFLANN<pcl::BINARY> matching;
matching.setInputCloud(shot1);
for (size_t i = 0; i < shot2->size(); ++i) {
std::vector<int> neighbors(1);
std::vector<int> hammingDistances(1);
int neighborCount = matching.nearestKSearch(shot2->at(i), 1, neighbors, hammingDistances);
if (neighborCount == 1 && hammingDistances[0] < 0.05f) {
pcl::Correspondence correspondence(neighbors[0], static_cast<int>(i), hammingDistances[0]);
model_scene_corrs->push_back(correspondence);
}
}
}
```
这段代码现在逻辑上是正确的。