Commit fc713d2ff42b6e72b0f4e741d010dc45ba8c6d85
1 parent
3aa2be93
Added online distance function
Showing
1 changed file
with
28 additions
and
1 deletions
openbr/plugins/distance.cpp
| @@ -298,7 +298,34 @@ class IdenticalDistance : public Distance | @@ -298,7 +298,34 @@ class IdenticalDistance : public Distance | ||
| 298 | 298 | ||
| 299 | BR_REGISTER(Distance, IdenticalDistance) | 299 | BR_REGISTER(Distance, IdenticalDistance) |
| 300 | 300 | ||
| 301 | -} // namespace br | ||
| 302 | 301 | ||
| 302 | +/*! | ||
| 303 | + * \ingroup distances | ||
| 304 | + * \brief Online distance metric to attenuate match scores across multiple frames | ||
| 305 | + * \author Brendan klare \cite bklare | ||
| 306 | + */ | ||
| 307 | +class OnlineDistance : public Distance | ||
| 308 | +{ | ||
| 309 | + Q_OBJECT | ||
| 310 | + Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) | ||
| 311 | + Q_PROPERTY(float alpha READ get_alpha WRITE set_alpha RESET reset_alpha STORED false) | ||
| 312 | + BR_PROPERTY(br::Distance*, distance, NULL) | ||
| 313 | + BR_PROPERTY(float, alpha, 0.1f); | ||
| 314 | + | ||
| 315 | + mutable QHash<QString,float> scoreHash; | ||
| 316 | + mutable QMutex mutex; | ||
| 317 | + | ||
| 318 | + float compare(const Template &target, const Template &query) const | ||
| 319 | + { | ||
| 320 | + float currentScore = distance->compare(target, query); | ||
| 321 | + | ||
| 322 | + QMutexLocker mutexLocker(&mutex); | ||
| 323 | + if (!scoreHash.contains(target.file.name)) scoreHash[target.file.name] = 0.0f; | ||
| 324 | + return (1.0- alpha) * scoreHash[target.file.name] + alpha * currentScore; | ||
| 325 | + } | ||
| 326 | +}; | ||
| 303 | 327 | ||
| 328 | +BR_REGISTER(Distance, OnlineDistance) | ||
| 329 | + | ||
| 330 | +} // namespace br | ||
| 304 | #include "distance.moc" | 331 | #include "distance.moc" |