Commit 8b0c89841871208836d96877405f918ab31032ca
1 parent
f4a9384b
changes suggested by Charles and Scott
Showing
6 changed files
with
13 additions
and
75 deletions
openbr/openbr_plugin.cpp
| ... | ... | @@ -1386,6 +1386,16 @@ QList<float> Distance::compare(const TemplateList &targets, const Template &quer |
| 1386 | 1386 | return scores; |
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | +float compare(const Template &a, const Template &b) const | |
| 1390 | +{ | |
| 1391 | + return compare(a.m(), b.m()); | |
| 1392 | +} | |
| 1393 | + | |
| 1394 | +float compare(const cv::Mat &, const cv::Mat &) const | |
| 1395 | +{ | |
| 1396 | + qFatal("Logic error: distance metric did not implement a comparison function or was accessed at an unsupported level of abstraction."); | |
| 1397 | +} | |
| 1398 | + | |
| 1389 | 1399 | /* Distance - private methods */ |
| 1390 | 1400 | void Distance::compareBlock(const TemplateList &target, const TemplateList &query, Output *output, int targetOffset, int queryOffset) const |
| 1391 | 1401 | { | ... | ... |
openbr/openbr_plugin.h
| ... | ... | @@ -1324,8 +1324,8 @@ public: |
| 1324 | 1324 | virtual void train(const TemplateList &src) { (void) src; } /*!< \brief Train the distance. */ |
| 1325 | 1325 | virtual void compare(const TemplateList &target, const TemplateList &query, Output *output) const; /*!< \brief Compare two template lists. */ |
| 1326 | 1326 | virtual QList<float> compare(const TemplateList &targets, const Template &query) const; /*!< \brief Compute the normalized distance between a template and a template list. */ |
| 1327 | - virtual float compare(const Template &a, const Template &b) const { return compare(a.m(), b.m()); } /*!< \brief Compute the distance between two templates. */ | |
| 1328 | - virtual float compare(const cv::Mat &a, const cv::Mat &b) const = 0; | |
| 1327 | + virtual float compare(const Template &a, const Template &b) const; /*!< \brief Compute the distance between two templates. */ | |
| 1328 | + virtual float compare(const cv::Mat &a, const cv::Mat &b) const; /*!< \brief Compute the distance between two biometric signatures. */ | |
| 1329 | 1329 | |
| 1330 | 1330 | protected: |
| 1331 | 1331 | inline Distance *make(const QString &description) { return make(description, this); } /*!< \brief Make a subdistance. */ | ... | ... |
openbr/plugins/distance.cpp
| ... | ... | @@ -224,11 +224,6 @@ private: |
| 224 | 224 | distances[i]->train(partitionedSrc[i]); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - float compare(const Mat &a, const Mat &b) const | |
| 228 | - { | |
| 229 | - return distances.first()->compare(a, b); | |
| 230 | - } | |
| 231 | - | |
| 232 | 227 | float compare(const Template &a, const Template &b) const |
| 233 | 228 | { |
| 234 | 229 | if (a.size() != b.size()) qFatal("Comparison size mismatch"); |
| ... | ... | @@ -237,7 +232,7 @@ private: |
| 237 | 232 | for (int i=0; i<distances.size(); i++) { |
| 238 | 233 | float weight; |
| 239 | 234 | weights.isEmpty() ? weight = 1. : weight = weights[i]; |
| 240 | - scores.append(weight*distances[i]->compare(a[i], b[i])); | |
| 235 | + scores.append(weight*distances[i]->compare(Template(a.file, a[i]),Template(b.file, b[i]))); | |
| 241 | 236 | } |
| 242 | 237 | |
| 243 | 238 | switch (operation) { |
| ... | ... | @@ -328,11 +323,6 @@ class NegativeLogPlusOneDistance : public Distance |
| 328 | 323 | distance->train(src); |
| 329 | 324 | } |
| 330 | 325 | |
| 331 | - float compare(const cv::Mat &a, const cv::Mat &b) const | |
| 332 | - { | |
| 333 | - return compare(Template(a), Template(b)); | |
| 334 | - } | |
| 335 | - | |
| 336 | 326 | float compare(const Template &a, const Template &b) const |
| 337 | 327 | { |
| 338 | 328 | return -log(distance->compare(a,b)+1); |
| ... | ... | @@ -388,11 +378,6 @@ class OnlineDistance : public Distance |
| 388 | 378 | mutable QHash<QString,float> scoreHash; |
| 389 | 379 | mutable QMutex mutex; |
| 390 | 380 | |
| 391 | - float compare(const Mat &a, const Mat &b) const | |
| 392 | - { | |
| 393 | - return compare(Template(a), Template(b)); | |
| 394 | - } | |
| 395 | - | |
| 396 | 381 | float compare(const Template &target, const Template &query) const |
| 397 | 382 | { |
| 398 | 383 | float currentScore = distance->compare(target, query); |
| ... | ... | @@ -415,12 +400,6 @@ class AttributeDistance : public Distance |
| 415 | 400 | Q_PROPERTY(QString attribute READ get_attribute WRITE set_attribute RESET reset_attribute STORED false) |
| 416 | 401 | BR_PROPERTY(QString, attribute, QString()) |
| 417 | 402 | |
| 418 | - float compare(const cv::Mat &, const cv::Mat &) const | |
| 419 | - { | |
| 420 | - qFatal("Logic error."); | |
| 421 | - return 0; | |
| 422 | - } | |
| 423 | - | |
| 424 | 403 | float compare(const Template &target, const Template &query) const |
| 425 | 404 | { |
| 426 | 405 | float queryValue = query.file.get<float>(attribute); |
| ... | ... | @@ -455,11 +434,6 @@ class SumDistance : public Distance |
| 455 | 434 | futures.waitForFinished(); |
| 456 | 435 | } |
| 457 | 436 | |
| 458 | - float compare(const Mat &a, const Mat &b) const | |
| 459 | - { | |
| 460 | - return compare(Template(a), Template(b)); | |
| 461 | - } | |
| 462 | - | |
| 463 | 437 | float compare(const Template &target, const Template &query) const |
| 464 | 438 | { |
| 465 | 439 | float result = 0; | ... | ... |
openbr/plugins/quality.cpp
| ... | ... | @@ -246,11 +246,6 @@ class ZScoreDistance : public Distance |
| 246 | 246 | if (stddev == 0) qFatal("Stddev is 0."); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - float compare(const cv::Mat &a, const cv::Mat &b) const | |
| 250 | - { | |
| 251 | - return compare(Template(a), Template(b)); | |
| 252 | - } | |
| 253 | - | |
| 254 | 249 | float compare(const Template &target, const Template &query) const |
| 255 | 250 | { |
| 256 | 251 | float score = distance->compare(target,query); |
| ... | ... | @@ -406,11 +401,6 @@ class UnitDistance : public Distance |
| 406 | 401 | qDebug("a = %f, b = %f", a, b); |
| 407 | 402 | } |
| 408 | 403 | |
| 409 | - float compare(const cv::Mat &a, const cv::Mat &b) const | |
| 410 | - { | |
| 411 | - return compare(Template(a), Template(b)); | |
| 412 | - } | |
| 413 | - | |
| 414 | 404 | float compare(const Template &target, const Template &query) const |
| 415 | 405 | { |
| 416 | 406 | return a * (distance->compare(target, query) - b); | ... | ... |
openbr/plugins/quantize.cpp
| ... | ... | @@ -257,12 +257,6 @@ class ProductQuantizationDistance : public Distance |
| 257 | 257 | Q_PROPERTY(bool bayesian READ get_bayesian WRITE set_bayesian RESET reset_bayesian STORED false) |
| 258 | 258 | BR_PROPERTY(bool, bayesian, false) |
| 259 | 259 | |
| 260 | - float compare(const cv::Mat &, const cv::Mat &) const | |
| 261 | - { | |
| 262 | - qFatal("Logic error."); | |
| 263 | - return 0; | |
| 264 | - } | |
| 265 | - | |
| 266 | 260 | float compare(const Template &a, const Template &b) const |
| 267 | 261 | { |
| 268 | 262 | float distance = 0; |
| ... | ... | @@ -303,12 +297,6 @@ class RecursiveProductQuantizationDistance : public Distance |
| 303 | 297 | Q_PROPERTY(float t READ get_t WRITE set_t RESET reset_t STORED false) |
| 304 | 298 | BR_PROPERTY(float, t, -std::numeric_limits<float>::max()) |
| 305 | 299 | |
| 306 | - float compare(const cv::Mat &, const cv::Mat &) const | |
| 307 | - { | |
| 308 | - qFatal("Logic error."); | |
| 309 | - return 0; | |
| 310 | - } | |
| 311 | - | |
| 312 | 300 | float compare(const Template &a, const Template &b) const |
| 313 | 301 | { |
| 314 | 302 | return compareRecursive(a, b, 0, a.size(), 0); | ... | ... |
openbr/plugins/validate.cpp
| ... | ... | @@ -143,12 +143,6 @@ class CrossValidateDistance : public Distance |
| 143 | 143 | { |
| 144 | 144 | Q_OBJECT |
| 145 | 145 | |
| 146 | - float compare(const cv::Mat &, const cv::Mat &) const | |
| 147 | - { | |
| 148 | - qFatal("Logic error"); | |
| 149 | - return 0; | |
| 150 | - } | |
| 151 | - | |
| 152 | 146 | float compare(const Template &a, const Template &b) const |
| 153 | 147 | { |
| 154 | 148 | static const QString key("Partition"); // More efficient to preallocate this |
| ... | ... | @@ -169,12 +163,6 @@ class FilterDistance : public Distance |
| 169 | 163 | { |
| 170 | 164 | Q_OBJECT |
| 171 | 165 | |
| 172 | - float compare(const cv::Mat &, const cv::Mat &) const | |
| 173 | - { | |
| 174 | - qFatal("Logic error."); | |
| 175 | - return 0; | |
| 176 | - } | |
| 177 | - | |
| 178 | 166 | float compare(const Template &a, const Template &b) const |
| 179 | 167 | { |
| 180 | 168 | (void) b; // Query template isn't checked |
| ... | ... | @@ -209,12 +197,6 @@ class MetadataDistance : public Distance |
| 209 | 197 | Q_PROPERTY(QStringList filters READ get_filters WRITE set_filters RESET reset_filters STORED false) |
| 210 | 198 | BR_PROPERTY(QStringList, filters, QStringList()) |
| 211 | 199 | |
| 212 | - float compare(const cv::Mat &, const cv::Mat &) const | |
| 213 | - { | |
| 214 | - qFatal("Logic error."); | |
| 215 | - return 0; | |
| 216 | - } | |
| 217 | - | |
| 218 | 200 | float compare(const Template &a, const Template &b) const |
| 219 | 201 | { |
| 220 | 202 | foreach (const QString &key, filters) { |
| ... | ... | @@ -268,12 +250,6 @@ class RejectDistance : public Distance |
| 268 | 250 | Q_PROPERTY(bool rejectIfContains READ get_rejectIfContains WRITE set_rejectIfContains RESET reset_rejectIfContains STORED false) |
| 269 | 251 | BR_PROPERTY(bool, rejectIfContains, false) |
| 270 | 252 | |
| 271 | - float compare(const cv::Mat &, const cv::Mat &) const | |
| 272 | - { | |
| 273 | - qFatal("Logic error."); | |
| 274 | - return 0; | |
| 275 | - } | |
| 276 | - | |
| 277 | 253 | float compare(const Template &a, const Template &b) const |
| 278 | 254 | { |
| 279 | 255 | // We don't look at the query | ... | ... |