且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C ++中使用OpenCV检测多个对象?

更新时间:2021-12-13 22:29:57

我不知道您的问题的解决方案,但是以下内容可能有助于回答您提出的问题.

I don't know a solution to your problem, but the following might help answer the questions you've asked.

在注释中说,您可能需要opencv已经具有的meanshift实现. 此处例如,

In the comments it says that you might need an implementation of meanshift, which opencv already has. Here an example, here the documentation with a tutorial.

  1. kmeansclusterCount是您要创建的集群的数量

  1. The clusterCount for kmeansis the number of clusters you want to create link. I don't know how to estimate the number you want to create, but I guess you could know.

您只能使用一个元素来初始化descriptors_scene_clusters:

You initialize descriptors_scene_clusters only with one element:

Mat descriptors_scene_clusters[3] = { Mat(descriptors_scene.rows, descriptors_scene.cols, CV_8U, Scalar(0)) };

当您对其进行迭代时:

for (int i=0; i<labels.rows; i++) {
    int clusterIndex = labels.at<int>(i);
    Point2f pt = keypoints_scene_points.at<Point2f>(i);
    descriptors_scene_clusters[clusterIndex].at<uchar>(pt) = descriptors_scene.at<uchar>(pt);  // ?????? error
}

clusterIndex为2,您访问数组中未初始化的元素,结果为EXEC_BAD_ACCESS error.

clusterIndex is 2 and you access an uninitialized element in the array, which results in the EXEC_BAD_ACCESS error.

我希望这有助于进一步调查!

I hope this helps for further investigation!