当我在OpenCV ++ kmeans中使用此标志时(请参阅示例代码),该函数根本不会更改标签。使用KMEANS_RANDOM_CENTERS或KMEANS_PP_CENTERS确实有效,问题出现在我使用此标志时。增加尝试次数不会改变任何东西。我正在使用OpenCV版本3.45(不允许更高)和Visual Studio Community 17来编译此代码。 (C ++标准未指定。)
int main() {
//voxelReconstruct();
vector<Point2f> ground_voxels;
for (int i = 0; i < 20; i++) ground_voxels.push_back(Point2f(rand() % 100, rand() % 100));
vector<int> voxel_labels;
for (int i = 0; i < 20; i++) voxel_labels.push_back(rand() % 4);
vector<int> old_labels;
for (int i = 0; i < 20; i++) old_labels.push_back(voxel_labels[i]);
kmeans(ground_voxels, 4, voxel_labels, TermCriteria(2, 5000, 0.0001), 1, KMEANS_USE_INITIAL_LABELS);
for (int i = 0; i < 20; i++) if (voxel_labels[i] != old_labels[i]) cout << "okay\n";
cout << "done\n";
waitKey(100000);
return 0;
}