Commit bbd30628e027efc7e59bebf71b3e6037c8129fd5
1 parent
fae02bb0
Finished heatmap distance and output
Showing
2 changed files
with
54 additions
and
16 deletions
openbr/plugins/distance.cpp
| ... | ... | @@ -303,8 +303,10 @@ class HeatMapDistance : public Distance |
| 303 | 303 | Q_OBJECT |
| 304 | 304 | Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) |
| 305 | 305 | BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) |
| 306 | - Q_PROPERTY(int rowSize READ get_rowSize WRITE set_rowSize RESET reset_rowSize STORED false) | |
| 307 | - BR_PROPERTY(int, rowSize, 1) | |
| 306 | + Q_PROPERTY(int rows READ get_rows WRITE set_rows RESET reset_rows STORED false) | |
| 307 | + BR_PROPERTY(int, rows, -1) | |
| 308 | + Q_PROPERTY(int cols READ get_cols WRITE set_cols RESET reset_cols STORED false) | |
| 309 | + BR_PROPERTY(int, cols, -1) | |
| 308 | 310 | |
| 309 | 311 | void train(const TemplateList &src) |
| 310 | 312 | { |
| ... | ... | @@ -319,21 +321,17 @@ class HeatMapDistance : public Distance |
| 319 | 321 | (void) a; (void) b; |
| 320 | 322 | } |
| 321 | 323 | |
| 322 | - void compare(const TemplateList &target, const TemplateList &query, Output *output) const | |
| 324 | + void compare(const TemplateList &target, const TemplateList &query, Output *output) const | |
| 323 | 325 | { |
| 324 | - int i = 0; | |
| 325 | - int j = 0; | |
| 326 | - for (int index = 0; index < target.size(); index++) { | |
| 327 | - float score = distance->compare(target[index],query[index]); | |
| 328 | - | |
| 329 | - if (j >= rowSize) { | |
| 330 | - i++; | |
| 331 | - j = 0; | |
| 326 | + if (rows*cols > target.size()) qFatal("Incompatible heatmap comparison dimensionality"); | |
| 327 | + | |
| 328 | + int index = 0; | |
| 329 | + for (int col = 0; col < cols; col++) { | |
| 330 | + for (int row = 0; row < rows; row++) { | |
| 331 | + float score = distance->compare(target[index],query[index]); | |
| 332 | + output->setRelative(score, row, col); | |
| 333 | + index++; | |
| 332 | 334 | } |
| 333 | - | |
| 334 | - output->setRelative(score, i, j); | |
| 335 | - | |
| 336 | - j++; | |
| 337 | 335 | } |
| 338 | 336 | } |
| 339 | 337 | }; | ... | ... |
openbr/plugins/output.cpp
| ... | ... | @@ -80,7 +80,7 @@ class csvOutput : public MatrixOutput |
| 80 | 80 | for (int i=0; i<queryFiles.size(); i++) { |
| 81 | 81 | QStringList words; |
| 82 | 82 | for (int j=0; j<targetFiles.size(); j++) |
| 83 | - words.append(toString(i,j)); | |
| 83 | + words.append(toString(i,j)); // The toString idiom is used to output match scores - see MatrixOutput | |
| 84 | 84 | lines.append(queryFiles[i].name+","+words.join(",")); |
| 85 | 85 | } |
| 86 | 86 | QtUtils::writeFile(file, lines); |
| ... | ... | @@ -91,6 +91,46 @@ BR_REGISTER(Output, csvOutput) |
| 91 | 91 | |
| 92 | 92 | /*! |
| 93 | 93 | * \ingroup outputs |
| 94 | + * \brief Matrix-like output for heat maps. | |
| 95 | + * \author Scott Klum \cite sklum | |
| 96 | + */ | |
| 97 | +class heatOutput : public MatrixOutput | |
| 98 | +{ | |
| 99 | + Q_OBJECT | |
| 100 | + Q_PROPERTY(int rows READ get_rows WRITE set_rows RESET reset_rows STORED false) | |
| 101 | + BR_PROPERTY(int, rows, -1) | |
| 102 | + Q_PROPERTY(int cols READ get_cols WRITE set_cols RESET reset_cols STORED false) | |
| 103 | + BR_PROPERTY(int, cols, -1) | |
| 104 | + | |
| 105 | + ~heatOutput() | |
| 106 | + { | |
| 107 | + if (file.isNull() || targetFiles.isEmpty() || queryFiles.isEmpty()) return; | |
| 108 | + | |
| 109 | + if (rows*cols > targetFiles.size()) qFatal("Incompatible heatmap output dimensionality"); | |
| 110 | + | |
| 111 | + QStringList lines; | |
| 112 | + for (int col = 0; col < cols; col++) { | |
| 113 | + QStringList words; | |
| 114 | + for (int row = 0; row < rows; row++) | |
| 115 | + words.append(toString(row,col)); | |
| 116 | + lines.append(words.join(",")); | |
| 117 | + } | |
| 118 | + QtUtils::writeFile(file, lines); | |
| 119 | + } | |
| 120 | + | |
| 121 | + void initialize(const FileList &targetFiles, const FileList &queryFiles) | |
| 122 | + { | |
| 123 | + if (rows == -1 || cols == -1) qFatal("heatOutput requires dimensionality"); | |
| 124 | + | |
| 125 | + Output::initialize(targetFiles, queryFiles); | |
| 126 | + data.create(rows, cols, CV_32FC1); | |
| 127 | + } | |
| 128 | +}; | |
| 129 | + | |
| 130 | +BR_REGISTER(Output, heatOutput) | |
| 131 | + | |
| 132 | +/*! | |
| 133 | + * \ingroup outputs | |
| 94 | 134 | * \brief One score per row. |
| 95 | 135 | * \author Josh Klontz \cite jklontz |
| 96 | 136 | */ | ... | ... |