| 267 | } |
| 268 | |
| 269 | py::list chinese_whispers_clustering(py::list descriptors, float threshold) |
| 270 | { |
| 271 | DLIB_CASSERT(threshold > 0); |
| 272 | py::list clusters; |
| 273 | |
| 274 | size_t num_descriptors = py::len(descriptors); |
| 275 | |
| 276 | // This next bit of code creates a graph of connected objects and then uses the Chinese |
| 277 | // whispers graph clustering algorithm to identify how many objects there are and which |
| 278 | // objects belong to which cluster. |
| 279 | std::vector<sample_pair> edges; |
| 280 | std::vector<unsigned long> labels; |
| 281 | for (size_t i = 0; i < num_descriptors; ++i) |
| 282 | { |
| 283 | for (size_t j = i; j < num_descriptors; ++j) |
| 284 | { |
| 285 | matrix<double,0,1>& first_descriptor = descriptors[i].cast<matrix<double,0,1>&>(); |
| 286 | matrix<double,0,1>& second_descriptor = descriptors[j].cast<matrix<double,0,1>&>(); |
| 287 | |
| 288 | if (length(first_descriptor-second_descriptor) < threshold) |
| 289 | edges.push_back(sample_pair(i,j)); |
| 290 | } |
| 291 | } |
| 292 | chinese_whispers(edges, labels); |
| 293 | for (size_t i = 0; i < labels.size(); ++i) |
| 294 | { |
| 295 | clusters.append(labels[i]); |
| 296 | } |
| 297 | return clusters; |
| 298 | } |
| 299 | |
| 300 | py::list chinese_whispers_raw(py::list edges) |
| 301 | { |
nothing calls this directly
no test coverage detected