Commit 1d6d0144ae4492e025ee2c858773666bdde317d6
1 parent
7359515b
Documentation and minor fixes
Showing
1 changed file
with
13 additions
and
3 deletions
openbr/plugins/cluster/meanshift.cpp
| @@ -6,6 +6,15 @@ using namespace cv; | @@ -6,6 +6,15 @@ using namespace cv; | ||
| 6 | namespace br | 6 | namespace br |
| 7 | { | 7 | { |
| 8 | 8 | ||
| 9 | +/*! | ||
| 10 | + * \brief A transform implementing the mean shift clustering algorithm. | ||
| 11 | + * \author Jordan Cheney \cite JordanCheney | ||
| 12 | + * \br_property br::Distance* distance The distance used to compute the distance between templates | ||
| 13 | + * \br_property int kernelBandwidth The size of the kernel used to converge points to a cluster center | ||
| 14 | + * \br_property float shiftThreshold The cutoff threshold distance for a shifted point. A value lower then this threshold indicates a point has finished shifting to a cluster center. | ||
| 15 | + * \br_property float distanceThreshold The distance threshold for a point to join a cluster. A point must be at least this close to another point to be included in the same cluster as that point. | ||
| 16 | + * \br_link http://spin.atomicobject.com/2015/05/26/mean-shift-clustering/ | ||
| 17 | + */ | ||
| 9 | class MeanShiftClusteringTransform : public TimeVaryingTransform | 18 | class MeanShiftClusteringTransform : public TimeVaryingTransform |
| 10 | { | 19 | { |
| 11 | Q_OBJECT | 20 | Q_OBJECT |
| @@ -65,11 +74,11 @@ private: | @@ -65,11 +74,11 @@ private: | ||
| 65 | for (int i = 0; i < original_points.size(); i++) | 74 | for (int i = 0; i < original_points.size(); i++) |
| 66 | distances.at<float>(0, i) = distance->compare(point, original_points[i]); | 75 | distances.at<float>(0, i) = distance->compare(point, original_points[i]); |
| 67 | 76 | ||
| 68 | - Mat weights = gaussian_kernel(distances, kernelBandwidth); | 77 | + Mat weights = gaussianKernel(distances, kernelBandwidth); |
| 69 | point = (weights * OpenCVUtils::toMat(original_points)) / sum(weights)[0]; | 78 | point = (weights * OpenCVUtils::toMat(original_points)) / sum(weights)[0]; |
| 70 | } | 79 | } |
| 71 | 80 | ||
| 72 | - inline Mat gaussian_kernel(const Mat &distance, const float bandwidth) | 81 | + inline Mat gaussianKernel(const Mat &distance, const float bandwidth) |
| 73 | { | 82 | { |
| 74 | Mat p, e; | 83 | Mat p, e; |
| 75 | pow(distance / bandwidth, 2, p); | 84 | pow(distance / bandwidth, 2, p); |
| @@ -89,7 +98,8 @@ private: | @@ -89,7 +98,8 @@ private: | ||
| 89 | groups.append(group); | 98 | groups.append(group); |
| 90 | } | 99 | } |
| 91 | 100 | ||
| 92 | - qDebug("created %d clusters from %d templates", newGroupIdx, points.size()); | 101 | + if (Globals->verbose) |
| 102 | + qDebug("created %d clusters from %d templates", newGroupIdx, points.size()); | ||
| 93 | 103 | ||
| 94 | return groups; | 104 | return groups; |
| 95 | } | 105 | } |