Commit d7e2f8fccacd4e2e5ce88b16ffe20bfb6195b5ea
1 parent
6119ee17
cleaned up BEE
Showing
6 changed files
with
104 additions
and
119 deletions
openbr/core/bee.cpp
| ... | ... | @@ -14,17 +14,10 @@ |
| 14 | 14 | * limitations under the License. * |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | -#include <QFile> | |
| 18 | -#include <QFileInfo> | |
| 19 | -#include <QHash> | |
| 20 | -#include <QMap> | |
| 21 | -#include <QRegExp> | |
| 17 | +#include <QtCore> | |
| 22 | 18 | #ifndef BR_EMBEDDED |
| 23 | 19 | #include <QtXml> |
| 24 | 20 | #endif // BR_EMBEDDED |
| 25 | -#include <algorithm> | |
| 26 | -#include <limits> | |
| 27 | -#include <openbr/openbr_plugin.h> | |
| 28 | 21 | |
| 29 | 22 | #include "bee.h" |
| 30 | 23 | #include "opencvutils.h" |
| ... | ... | @@ -33,23 +26,21 @@ |
| 33 | 26 | using namespace cv; |
| 34 | 27 | using namespace br; |
| 35 | 28 | |
| 36 | -/**** BEE ****/ | |
| 37 | -FileList BEE::readSigset(const File &sigset, bool ignoreMetadata) | |
| 29 | +namespace BEE | |
| 30 | +{ | |
| 31 | + | |
| 32 | +FileList readSigset(const File &sigset, bool ignoreMetadata) | |
| 38 | 33 | { |
| 39 | 34 | FileList fileList; |
| 40 | 35 | |
| 41 | 36 | #ifndef BR_EMBEDDED |
| 42 | 37 | QDomDocument doc(sigset.fileName()); |
| 43 | - QFile file(sigset.resolved()); | |
| 44 | - bool success; | |
| 45 | - success = file.open(QIODevice::ReadOnly); if (!success) qFatal("Unable to open %s for reading.", qPrintable(sigset)); | |
| 46 | - success = doc.setContent(&file); | |
| 47 | - | |
| 48 | - file.close(); | |
| 49 | - | |
| 50 | - if (!success) { | |
| 51 | - qWarning("Unable to parse %s.", qPrintable(sigset)); | |
| 52 | - return fileList; | |
| 38 | + { | |
| 39 | + QFile file(sigset.resolved()); | |
| 40 | + if (!file.open(QIODevice::ReadOnly)) | |
| 41 | + qFatal("Unable to open %s for reading.", qPrintable(sigset)); | |
| 42 | + if (!doc.setContent(&file)) | |
| 43 | + qFatal("Unable to parse %s.", qPrintable(sigset)); | |
| 53 | 44 | } |
| 54 | 45 | |
| 55 | 46 | QDomElement docElem = doc.documentElement(); |
| ... | ... | @@ -105,7 +96,7 @@ FileList BEE::readSigset(const File &sigset, bool ignoreMetadata) |
| 105 | 96 | return fileList; |
| 106 | 97 | } |
| 107 | 98 | |
| 108 | -void BEE::writeSigset(const QString &sigset, const br::FileList &files, bool ignoreMetadata) | |
| 99 | +void writeSigset(const QString &sigset, const FileList &files, bool ignoreMetadata) | |
| 109 | 100 | { |
| 110 | 101 | QStringList lines; lines.reserve(3*files.size()+3); |
| 111 | 102 | lines.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| ... | ... | @@ -137,7 +128,7 @@ void BEE::writeSigset(const QString &sigset, const br::FileList &files, bool ign |
| 137 | 128 | QtUtils::writeFile(sigset, lines); |
| 138 | 129 | } |
| 139 | 130 | |
| 140 | -Mat BEE::readMat(const br::File &matrix, QString *targetSigset, QString *querySigset) | |
| 131 | +Mat readMatrix(const File &matrix, QString *targetSigset, QString *querySigset) | |
| 141 | 132 | { |
| 142 | 133 | QFile file(matrix); |
| 143 | 134 | bool success = file.open(QFile::ReadOnly); |
| ... | ... | @@ -148,7 +139,6 @@ Mat BEE::readMat(const br::File &matrix, QString *targetSigset, QString *querySi |
| 148 | 139 | bool isDistance = (format[0] == 'D'); |
| 149 | 140 | if (format[1] != '2') qFatal("Invalid matrix header."); |
| 150 | 141 | |
| 151 | - | |
| 152 | 142 | // Read sigsets |
| 153 | 143 | if (targetSigset != NULL) *targetSigset = file.readLine().simplified(); |
| 154 | 144 | else file.readLine(); |
| ... | ... | @@ -156,57 +146,52 @@ Mat BEE::readMat(const br::File &matrix, QString *targetSigset, QString *querySi |
| 156 | 146 | else file.readLine(); |
| 157 | 147 | |
| 158 | 148 | // Get matrix size |
| 159 | - QStringList words = QString(file.readLine()).split(" "); | |
| 160 | - int rows = words[1].toInt(); | |
| 161 | - int cols = words[2].toInt(); | |
| 162 | - | |
| 163 | - bool isMask = words[0][1] == 'B'; | |
| 164 | - int typeSize = isMask ? sizeof(BEE::Mask_t) : sizeof(BEE::Simmat_t); | |
| 149 | + const QStringList words = QString(file.readLine()).split(" "); | |
| 150 | + const int rows = words[1].toInt(); | |
| 151 | + const int cols = words[2].toInt(); | |
| 152 | + const bool isMask = words[0][1] == 'B'; | |
| 153 | + const int typeSize = isMask ? sizeof(BEE::MaskValue) : sizeof(BEE::SimmatValue); | |
| 165 | 154 | |
| 166 | 155 | // Get matrix data |
| 167 | 156 | Mat m; |
| 168 | 157 | if (isMask) |
| 169 | - m.create(rows, cols, OpenCVType<BEE::Mask_t,1>::make()); | |
| 158 | + m.create(rows, cols, OpenCVType<BEE::MaskValue,1>::make()); | |
| 170 | 159 | else |
| 171 | - m.create(rows, cols, OpenCVType<BEE::Simmat_t,1>::make()); | |
| 160 | + m.create(rows, cols, OpenCVType<BEE::SimmatValue,1>::make()); | |
| 172 | 161 | |
| 173 | - qint64 bytesPerRow = m.cols * typeSize; | |
| 174 | - | |
| 175 | - for (int i=0; i < m.rows;i++) | |
| 176 | - { | |
| 177 | - cv::Mat aRow = m.row(i); | |
| 162 | + const qint64 bytesPerRow = m.cols * typeSize; | |
| 163 | + for (int i=0; i<m.rows; i++) { | |
| 164 | + Mat aRow = m.row(i); | |
| 178 | 165 | qint64 bytesRead = file.read((char *)aRow.data, bytesPerRow); |
| 179 | 166 | if (bytesRead != bytesPerRow) |
| 180 | - { | |
| 181 | 167 | qFatal("Didn't read complete row!"); |
| 182 | - } | |
| 183 | 168 | } |
| 184 | 169 | if (!file.atEnd()) |
| 185 | 170 | qFatal("Expected matrix end of file."); |
| 186 | 171 | file.close(); |
| 187 | 172 | |
| 188 | 173 | Mat result = m; |
| 189 | - if (isDistance ^ matrix.get<bool>("negate", false)) m.convertTo(result, -1, -1); | |
| 190 | - | |
| 174 | + if (isDistance ^ matrix.get<bool>("negate", false)) | |
| 175 | + m.convertTo(result, -1, -1); | |
| 191 | 176 | return result; |
| 192 | 177 | } |
| 193 | 178 | |
| 194 | -void BEE::writeMat(const Mat &m, const QString &matrix, const QString &targetSigset, const QString &querySigset) | |
| 179 | +void writeMatrix(const Mat &m, const QString &fileName, const QString &targetSigset, const QString &querySigset) | |
| 195 | 180 | { |
| 196 | 181 | bool isMask = false; |
| 197 | - if (m.type() == OpenCVType<BEE::Mask_t,1>::make()) | |
| 182 | + if (m.type() == OpenCVType<BEE::MaskValue,1>::make()) | |
| 198 | 183 | isMask = true; |
| 199 | - else if (m.type() != OpenCVType<BEE::Simmat_t,1>::make()) | |
| 184 | + else if (m.type() != OpenCVType<BEE::SimmatValue,1>::make()) | |
| 200 | 185 | qFatal("Invalid matrix type, .mtx files can only contain single channel float or uchar matrices."); |
| 201 | 186 | |
| 202 | - int elemSize = isMask ? sizeof(BEE::Mask_t) : sizeof(BEE::Simmat_t); | |
| 203 | - | |
| 204 | - QString matrixType = isMask ? "B" : "F"; | |
| 187 | + const int elemSize = isMask ? sizeof(BEE::MaskValue) : sizeof(BEE::SimmatValue); | |
| 188 | + const QString matrixType = isMask ? "B" : "F"; | |
| 205 | 189 | |
| 206 | 190 | char buff[4]; |
| 207 | - QFile file(matrix); | |
| 191 | + QFile file(fileName); | |
| 208 | 192 | QtUtils::touchDir(file); |
| 209 | - bool success = file.open(QFile::WriteOnly); if (!success) qFatal("Unable to open %s for writing.", qPrintable(matrix)); | |
| 193 | + if (!file.open(QFile::WriteOnly)) | |
| 194 | + qFatal("Unable to open %s for writing.", qPrintable(fileName)); | |
| 210 | 195 | file.write("S2\n"); |
| 211 | 196 | file.write(qPrintable(targetSigset)); |
| 212 | 197 | file.write("\n"); |
| ... | ... | @@ -219,7 +204,7 @@ void BEE::writeMat(const Mat &m, const QString &matrix, const QString &targetSig |
| 219 | 204 | file.write(" "); |
| 220 | 205 | file.write(qPrintable(QString::number(m.cols))); |
| 221 | 206 | file.write(" "); |
| 222 | - int endian = 0x12345678; | |
| 207 | + const int endian = 0x12345678; | |
| 223 | 208 | memcpy(&buff, &endian, 4); |
| 224 | 209 | file.write(buff, 4); |
| 225 | 210 | file.write("\n"); |
| ... | ... | @@ -227,57 +212,58 @@ void BEE::writeMat(const Mat &m, const QString &matrix, const QString &targetSig |
| 227 | 212 | file.close(); |
| 228 | 213 | } |
| 229 | 214 | |
| 230 | -void BEE::readMatrixHeader(const QString &matrix, QString *targetSigset, QString *querySigset) | |
| 215 | +void readMatrixHeader(const QString &matrix, QString *targetSigset, QString *querySigset) | |
| 231 | 216 | { |
| 232 | 217 | qDebug("Reading %s header.", qPrintable(matrix)); |
| 233 | - readMat(matrix, targetSigset, querySigset); | |
| 218 | + readMatrix(matrix, targetSigset, querySigset); | |
| 234 | 219 | } |
| 235 | 220 | |
| 236 | -void BEE::writeMatrixHeader(const QString &matrix, const QString &targetSigset, const QString &querySigset) | |
| 221 | +void writeMatrixHeader(const QString &matrix, const QString &targetSigset, const QString &querySigset) | |
| 237 | 222 | { |
| 238 | 223 | qDebug("Writing %s header to %s %s.", qPrintable(matrix), qPrintable(targetSigset), qPrintable(querySigset)); |
| 239 | - | |
| 240 | - writeMat(readMat(matrix), matrix, targetSigset, querySigset); | |
| 224 | + writeMatrix(readMatrix(matrix), matrix, targetSigset, querySigset); | |
| 241 | 225 | } |
| 242 | 226 | |
| 243 | -void BEE::makeMask(const QString &targetInput, const QString &queryInput, const QString &mask) | |
| 227 | +void makeMask(const QString &targetInput, const QString &queryInput, const QString &mask) | |
| 244 | 228 | { |
| 245 | 229 | qDebug("Making mask from %s and %s to %s", qPrintable(targetInput), qPrintable(queryInput), qPrintable(mask)); |
| 246 | - FileList targets = TemplateList::fromGallery(targetInput).files(); | |
| 247 | - FileList queries = (queryInput == ".") ? targets : TemplateList::fromGallery(queryInput).files(); | |
| 248 | - int partitions = targets.first().get<int>("crossValidate"); | |
| 249 | - if (partitions == 0) writeMat(makeMask(targets, queries), mask, targetInput, queryInput); | |
| 250 | - else { | |
| 230 | + const FileList targets = TemplateList::fromGallery(targetInput).files(); | |
| 231 | + const FileList queries = (queryInput == ".") ? targets : TemplateList::fromGallery(queryInput).files(); | |
| 232 | + const int partitions = targets.first().get<int>("crossValidate"); | |
| 233 | + if (partitions == 0) { | |
| 234 | + writeMatrix(makeMask(targets, queries), mask, targetInput, queryInput); | |
| 235 | + } else { | |
| 251 | 236 | if (!mask.contains("%1")) qFatal("Mask file name missing partition number place marker (%%1)"); |
| 252 | 237 | for (int i=0; i<partitions; i++) { |
| 253 | - writeMat(makeMask(targets, queries, i), mask.arg(i), targetInput, queryInput); | |
| 238 | + writeMatrix(makeMask(targets, queries, i), mask.arg(i), targetInput, queryInput); | |
| 254 | 239 | } |
| 255 | 240 | } |
| 256 | 241 | } |
| 257 | 242 | |
| 258 | -void BEE::makePairwiseMask(const QString &targetInput, const QString &queryInput, const QString &mask) | |
| 243 | +void makePairwiseMask(const QString &targetInput, const QString &queryInput, const QString &mask) | |
| 259 | 244 | { |
| 260 | - FileList targets = TemplateList::fromGallery(targetInput).files(); | |
| 261 | - FileList queries = (queryInput == ".") ? targets : TemplateList::fromGallery(queryInput).files(); | |
| 262 | - int partitions = targets.first().get<int>("crossValidate"); | |
| 263 | - if (partitions == 0) writeMat(makePairwiseMask(targets, queries), mask, targetInput, queryInput); | |
| 264 | - else { | |
| 245 | + qDebug("Making pairwise mask from %s and %s to %s", qPrintable(targetInput), qPrintable(queryInput), qPrintable(mask)); | |
| 246 | + const FileList targets = TemplateList::fromGallery(targetInput).files(); | |
| 247 | + const FileList queries = (queryInput == ".") ? targets : TemplateList::fromGallery(queryInput).files(); | |
| 248 | + const int partitions = targets.first().get<int>("crossValidate"); | |
| 249 | + if (partitions == 0) { | |
| 250 | + writeMatrix(makePairwiseMask(targets, queries), mask, targetInput, queryInput); | |
| 251 | + } else { | |
| 265 | 252 | if (!mask.contains("%1")) qFatal("Mask file name missing partition number place marker (%%1)"); |
| 266 | 253 | for (int i=0; i<partitions; i++) { |
| 267 | - writeMat(makePairwiseMask(targets, queries, i), mask.arg(i), targetInput, queryInput); | |
| 254 | + writeMatrix(makePairwiseMask(targets, queries, i), mask.arg(i), targetInput, queryInput); | |
| 268 | 255 | } |
| 269 | 256 | } |
| 270 | 257 | } |
| 271 | 258 | |
| 272 | -cv::Mat BEE::makePairwiseMask(const br::FileList &targets, const br::FileList &queries, int partition) | |
| 259 | +Mat makePairwiseMask(const FileList &targets, const FileList &queries, int partition) | |
| 273 | 260 | { |
| 274 | - // Direct use of "Label" isn't general, also would prefer to use indexProperty, rather than | |
| 261 | + // TODO: Direct use of "Label" isn't general, also would prefer to use indexProperty, rather than | |
| 275 | 262 | // doing string comparisons (but that isn't implemented yet for FileList) -cao |
| 276 | - QList<QString> targetLabels = File::get<QString>(targets, "Label", "-1"); | |
| 277 | - QList<QString> queryLabels = File::get<QString>(queries, "Label", "-1"); | |
| 278 | - | |
| 279 | - QList<int> targetPartitions = targets.crossValidationPartitions(); | |
| 280 | - QList<int> queryPartitions = queries.crossValidationPartitions(); | |
| 263 | + const QStringList targetLabels = File::get<QString>(targets, "Label", "-1"); | |
| 264 | + const QStringList queryLabels = File::get<QString>(queries, "Label", "-1"); | |
| 265 | + const QList<int> targetPartitions = targets.crossValidationPartitions(); | |
| 266 | + const QList<int> queryPartitions = queries.crossValidationPartitions(); | |
| 281 | 267 | |
| 282 | 268 | Mat mask(queries.size(), 1, CV_8UC1); |
| 283 | 269 | for (int i=0; i<queries.size(); i++) { |
| ... | ... | @@ -289,7 +275,7 @@ cv::Mat BEE::makePairwiseMask(const br::FileList &targets, const br::FileList &q |
| 289 | 275 | const QString labelB = targetLabels[i]; |
| 290 | 276 | const int partitionB = targetPartitions[i]; |
| 291 | 277 | |
| 292 | - Mask_t val; | |
| 278 | + MaskValue val; | |
| 293 | 279 | if (fileA == fileB) val = DontCare; |
| 294 | 280 | else if (labelA == "-1") val = DontCare; |
| 295 | 281 | else if (labelB == "-1") val = DontCare; |
| ... | ... | @@ -298,23 +284,21 @@ cv::Mat BEE::makePairwiseMask(const br::FileList &targets, const br::FileList &q |
| 298 | 284 | else if (partitionB != partition) val = DontCare; |
| 299 | 285 | else if (labelA == labelB) val = Match; |
| 300 | 286 | else val = NonMatch; |
| 301 | - mask.at<Mask_t>(i,0) = val; | |
| 287 | + mask.at<MaskValue>(i,0) = val; | |
| 302 | 288 | } |
| 303 | 289 | |
| 304 | 290 | return mask; |
| 305 | 291 | } |
| 306 | 292 | |
| 307 | -cv::Mat BEE::makeMask(const br::FileList &targets, const br::FileList &queries, int partition) | |
| 293 | +Mat makeMask(const FileList &targets, const FileList &queries, int partition) | |
| 308 | 294 | { |
| 309 | - // Direct use of "Label" isn't general, also would prefer to use indexProperty, rather than | |
| 295 | + // TODO: Direct use of "Label" isn't general, also would prefer to use indexProperty, rather than | |
| 310 | 296 | // doing string comparisons (but that isn't implemented yet for FileList) -cao |
| 311 | - QList<QString> targetLabels = File::get<QString>(targets, "Label", "-1"); | |
| 312 | - QList<QString> queryLabels = File::get<QString>(queries, "Label", "-1"); | |
| 313 | - | |
| 314 | - QList<int> targetPartitions = targets.crossValidationPartitions(); | |
| 315 | - QList<int> queryPartitions = queries.crossValidationPartitions(); | |
| 316 | - | |
| 317 | - QList<bool> targetsOnly = File::get<bool>(queries, "targetOnly", false); | |
| 297 | + const QStringList targetLabels = File::get<QString>(targets, "Label", "-1"); | |
| 298 | + const QStringList queryLabels = File::get<QString>(queries, "Label", "-1"); | |
| 299 | + const QList<int> targetPartitions = targets.crossValidationPartitions(); | |
| 300 | + const QList<int> queryPartitions = queries.crossValidationPartitions(); | |
| 301 | + const QList<bool> targetsOnly = File::get<bool>(queries, "targetOnly", false); | |
| 318 | 302 | |
| 319 | 303 | Mat mask(queries.size(), targets.size(), CV_8UC1); |
| 320 | 304 | for (int i=0; i<queries.size(); i++) { |
| ... | ... | @@ -328,7 +312,7 @@ cv::Mat BEE::makeMask(const br::FileList &targets, const br::FileList &queries, |
| 328 | 312 | const QString labelB = targetLabels[j]; |
| 329 | 313 | const int partitionB = targetPartitions[j]; |
| 330 | 314 | |
| 331 | - Mask_t val; | |
| 315 | + MaskValue val; | |
| 332 | 316 | if (fileA == fileB) val = DontCare; |
| 333 | 317 | else if (targetOnly) val = DontCare; |
| 334 | 318 | else if (labelA == "-1") val = DontCare; |
| ... | ... | @@ -338,14 +322,14 @@ cv::Mat BEE::makeMask(const br::FileList &targets, const br::FileList &queries, |
| 338 | 322 | else if (partitionB != partition) val = DontCare; |
| 339 | 323 | else if (labelA == labelB) val = Match; |
| 340 | 324 | else val = NonMatch; |
| 341 | - mask.at<Mask_t>(i,j) = val; | |
| 325 | + mask.at<MaskValue>(i,j) = val; | |
| 342 | 326 | } |
| 343 | 327 | } |
| 344 | 328 | |
| 345 | 329 | return mask; |
| 346 | 330 | } |
| 347 | 331 | |
| 348 | -void BEE::combineMasks(const QStringList &inputMasks, const QString &outputMask, const QString &method) | |
| 332 | +void combineMasks(const QStringList &inputMasks, const QString &outputMask, const QString &method) | |
| 349 | 333 | { |
| 350 | 334 | qDebug("Combining %d masks to %s with method %s", inputMasks.size(), qPrintable(outputMask), qPrintable(method)); |
| 351 | 335 | |
| ... | ... | @@ -356,12 +340,12 @@ void BEE::combineMasks(const QStringList &inputMasks, const QString &outputMask, |
| 356 | 340 | |
| 357 | 341 | QList<Mat> masks; |
| 358 | 342 | foreach (const QString &inputMask, inputMasks) |
| 359 | - masks.append(readMat(inputMask)); | |
| 360 | - if (masks.size() < 2) qFatal("Expected at least two masks."); | |
| 343 | + masks.append(readMatrix(inputMask)); | |
| 344 | + if (masks.size() < 2) | |
| 345 | + qFatal("Expected at least two masks."); | |
| 361 | 346 | |
| 362 | 347 | const int rows = masks.first().rows; |
| 363 | 348 | const int columns = masks.first().cols; |
| 364 | - | |
| 365 | 349 | Mat combinedMask(rows, columns, CV_8UC1); |
| 366 | 350 | for (int i=0; i<rows; i++) { |
| 367 | 351 | for (int j=0; j<columns; j++) { |
| ... | ... | @@ -369,7 +353,7 @@ void BEE::combineMasks(const QStringList &inputMasks, const QString &outputMask, |
| 369 | 353 | int imposterCount = 0; |
| 370 | 354 | int dontcareCount = 0; |
| 371 | 355 | for (int k=0; k<masks.size(); k++) { |
| 372 | - switch (masks[k].at<Mask_t>(i,j)) { | |
| 356 | + switch (masks[k].at<MaskValue>(i,j)) { | |
| 373 | 357 | case Match: |
| 374 | 358 | genuineCount++; |
| 375 | 359 | break; |
| ... | ... | @@ -383,14 +367,16 @@ void BEE::combineMasks(const QStringList &inputMasks, const QString &outputMask, |
| 383 | 367 | } |
| 384 | 368 | if ((genuineCount != 0) && (imposterCount != 0)) qFatal("Comparison is both a genuine and an imposter."); |
| 385 | 369 | |
| 386 | - Mask_t val; | |
| 370 | + MaskValue val; | |
| 387 | 371 | if (genuineCount > 0) val = Match; |
| 388 | 372 | else if (imposterCount > 0) val = NonMatch; |
| 389 | 373 | else val = DontCare; |
| 390 | 374 | if (AND && (dontcareCount > 0)) val = DontCare; |
| 391 | - combinedMask.at<Mask_t>(i,j) = val; | |
| 375 | + combinedMask.at<MaskValue>(i,j) = val; | |
| 392 | 376 | } |
| 393 | 377 | } |
| 394 | 378 | |
| 395 | - writeMat(combinedMask, outputMask, "Combined_Targets", "Combined_Queries"); | |
| 379 | + writeMatrix(combinedMask, outputMask, "Combined_Targets", "Combined_Queries"); | |
| 396 | 380 | } |
| 381 | + | |
| 382 | +} // namespace BEE | ... | ... |
openbr/core/bee.h
| ... | ... | @@ -17,30 +17,29 @@ |
| 17 | 17 | #ifndef BEE_BEE_H |
| 18 | 18 | #define BEE_BEE_H |
| 19 | 19 | |
| 20 | -#include <QList> | |
| 21 | -#include <QPair> | |
| 22 | -#include <QHash> | |
| 23 | 20 | #include <QString> |
| 24 | 21 | #include <QStringList> |
| 25 | 22 | #include <opencv2/core/core.hpp> |
| 26 | 23 | #include <openbr/openbr_plugin.h> |
| 27 | 24 | |
| 28 | -/*** Functions for parsing BEE style data structures. ***/ | |
| 25 | +/*! | |
| 26 | + * Functions for parsing NIST BEE data structures. | |
| 27 | + */ | |
| 29 | 28 | namespace BEE |
| 30 | 29 | { |
| 31 | - const uchar Match(0xff); | |
| 32 | - const uchar NonMatch(0x7f); | |
| 33 | - const uchar DontCare(0x00); | |
| 34 | - typedef float Simmat_t; | |
| 35 | - typedef uchar Mask_t; | |
| 30 | + typedef float SimmatValue; | |
| 31 | + typedef uchar MaskValue; | |
| 32 | + const MaskValue Match(0xff); | |
| 33 | + const MaskValue NonMatch(0x7f); | |
| 34 | + const MaskValue DontCare(0x00); | |
| 36 | 35 | |
| 37 | 36 | // Sigset |
| 38 | 37 | br::FileList readSigset(const br::File &sigset, bool ignoreMetadata = false); |
| 39 | 38 | void writeSigset(const QString &sigset, const br::FileList &files, bool ignoreMetadata = false); |
| 40 | 39 | |
| 41 | 40 | // Matrix |
| 42 | - cv::Mat readMat(const br::File & mat, QString * targetSigset = NULL, QString * querySigset = NULL); | |
| 43 | - void writeMat(const cv::Mat &m, const QString &simmat, const QString &targetSigset = "Unknown_Target", const QString &querySigset = "Unknown_Query"); | |
| 41 | + cv::Mat readMatrix(const br::File &mat, QString *targetSigset = NULL, QString *querySigset = NULL); | |
| 42 | + void writeMatrix(const cv::Mat &m, const QString &fileName, const QString &targetSigset = "Unknown_Target", const QString &querySigset = "Unknown_Query"); | |
| 44 | 43 | void readMatrixHeader(const QString &matrix, QString *targetSigset, QString *querySigset); |
| 45 | 44 | void writeMatrixHeader(const QString &matrix, const QString &targetSigset, const QString &querySigset); |
| 46 | 45 | ... | ... |
openbr/core/core.cpp
| ... | ... | @@ -672,7 +672,7 @@ void br::Convert(const File &fileType, const File &inputFile, const File &output |
| 672 | 672 | while (!done) after->writeBlock(before->readBlock(&done)); |
| 673 | 673 | } else if (fileType == "Output") { |
| 674 | 674 | QString target, query; |
| 675 | - cv::Mat m = BEE::readMat(inputFile, &target, &query); | |
| 675 | + cv::Mat m = BEE::readMatrix(inputFile, &target, &query); | |
| 676 | 676 | const FileList targetFiles = TemplateList::fromGallery(target).files(); |
| 677 | 677 | const FileList queryFiles = TemplateList::fromGallery(query).files(); |
| 678 | 678 | ... | ... |
openbr/core/eval.cpp
| ... | ... | @@ -99,7 +99,7 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv) |
| 99 | 99 | QString target, query; |
| 100 | 100 | Mat scores; |
| 101 | 101 | if (simmat.endsWith(".mtx")) { |
| 102 | - scores = BEE::readMat(simmat, &target, &query); | |
| 102 | + scores = BEE::readMatrix(simmat, &target, &query); | |
| 103 | 103 | } else { |
| 104 | 104 | QScopedPointer<Format> format(Factory<Format>::make(simmat)); |
| 105 | 105 | scores = format->read(); |
| ... | ... | @@ -144,8 +144,8 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv) |
| 144 | 144 | int genuineCount = 0, impostorCount = 0, numNaNs = 0; |
| 145 | 145 | for (int i=0; i<simmat.rows; i++) { |
| 146 | 146 | for (int j=0; j<simmat.cols; j++) { |
| 147 | - const BEE::Mask_t mask_val = mask.at<BEE::Mask_t>(i,j); | |
| 148 | - const BEE::Simmat_t simmat_val = simmat.at<BEE::Simmat_t>(i,j); | |
| 147 | + const BEE::MaskValue mask_val = mask.at<BEE::MaskValue>(i,j); | |
| 148 | + const BEE::SimmatValue simmat_val = simmat.at<BEE::SimmatValue>(i,j); | |
| 149 | 149 | if (mask_val == BEE::DontCare) continue; |
| 150 | 150 | if (simmat_val != simmat_val) { numNaNs++; continue; } |
| 151 | 151 | comparisons.append(Comparison(simmat_val, j, i, mask_val == BEE::Match)); |
| ... | ... | @@ -315,7 +315,7 @@ float InplaceEval(const QString & simmat, const QString & target, const QString |
| 315 | 315 | qint64 cols = words[2].toLongLong(); |
| 316 | 316 | |
| 317 | 317 | bool isMask = words[0][1] == 'B'; |
| 318 | - qint64 typeSize = isMask ? sizeof(BEE::Mask_t) : sizeof(BEE::Simmat_t); | |
| 318 | + qint64 typeSize = isMask ? sizeof(BEE::MaskValue) : sizeof(BEE::SimmatValue); | |
| 319 | 319 | |
| 320 | 320 | // Get matrix data |
| 321 | 321 | qint64 rowSize = cols * typeSize; | ... | ... |
openbr/core/fuse.cpp
| ... | ... | @@ -39,7 +39,7 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) |
| 39 | 39 | for (int i=0; i<matrix.rows; i++) { |
| 40 | 40 | for (int j=0; j<matrix.cols; j++) { |
| 41 | 41 | float val = matrix.at<float>(i,j); |
| 42 | - if ((mask.at<BEE::Mask_t>(i,j) == BEE::DontCare) || | |
| 42 | + if ((mask.at<BEE::MaskValue>(i,j) == BEE::DontCare) || | |
| 43 | 43 | (val == -std::numeric_limits<float>::max()) || |
| 44 | 44 | (val == std::numeric_limits<float>::max())) |
| 45 | 45 | continue; |
| ... | ... | @@ -55,7 +55,7 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) |
| 55 | 55 | if (method == "MinMax") { |
| 56 | 56 | for (int i=0; i<matrix.rows; i++) { |
| 57 | 57 | for (int j=0; j<matrix.cols; j++) { |
| 58 | - if (mask.at<BEE::Mask_t>(i,j) == BEE::DontCare) continue; | |
| 58 | + if (mask.at<BEE::MaskValue>(i,j) == BEE::DontCare) continue; | |
| 59 | 59 | float &val = matrix.at<float>(i,j); |
| 60 | 60 | if (val == -std::numeric_limits<float>::max()) val = 0; |
| 61 | 61 | else if (val == std::numeric_limits<float>::max()) val = 1; |
| ... | ... | @@ -66,7 +66,7 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) |
| 66 | 66 | if (stddev == 0) qFatal("Stddev is 0."); |
| 67 | 67 | for (int i=0; i<matrix.rows; i++) { |
| 68 | 68 | for (int j=0; j<matrix.cols; j++) { |
| 69 | - if (mask.at<BEE::Mask_t>(i,j) == BEE::DontCare) continue; | |
| 69 | + if (mask.at<BEE::MaskValue>(i,j) == BEE::DontCare) continue; | |
| 70 | 70 | float &val = matrix.at<float>(i,j); |
| 71 | 71 | if (val == -std::numeric_limits<float>::max()) val = (min - mean) / stddev; |
| 72 | 72 | else if (val == std::numeric_limits<float>::max()) val = (max - mean) / stddev; |
| ... | ... | @@ -85,7 +85,7 @@ void br::Fuse(const QStringList &inputSimmats, const QString &normalization, con |
| 85 | 85 | QString target, query, previousTarget, previousQuery; |
| 86 | 86 | QList<Mat> originalMatrices; |
| 87 | 87 | foreach (const QString &simmat, inputSimmats) { |
| 88 | - originalMatrices.append(BEE::readMat(simmat,&target,&query)); | |
| 88 | + originalMatrices.append(BEE::readMatrix(simmat,&target,&query)); | |
| 89 | 89 | // Make we're fusing score matrices for the same set of targets and querys |
| 90 | 90 | if (!previousTarget.isEmpty() && !previousQuery.isEmpty() && (previousTarget != target || previousQuery != query)) |
| 91 | 91 | qFatal("Target or query files are not the same across fused matrices."); |
| ... | ... | @@ -163,5 +163,5 @@ void br::Fuse(const QStringList &inputSimmats, const QString &normalization, con |
| 163 | 163 | |
| 164 | 164 | } while (partition < crossValidate); |
| 165 | 165 | |
| 166 | - BEE::writeMat(buffer, outputSimmat); | |
| 166 | + BEE::writeMatrix(buffer, outputSimmat); | |
| 167 | 167 | } | ... | ... |
openbr/plugins/format.cpp
| ... | ... | @@ -293,12 +293,12 @@ class mtxFormat : public Format |
| 293 | 293 | |
| 294 | 294 | Template read() const |
| 295 | 295 | { |
| 296 | - return BEE::readMat(file); | |
| 296 | + return BEE::readMatrix(file); | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | void write(const Template &t) const |
| 300 | 300 | { |
| 301 | - BEE::writeMat(t, file); | |
| 301 | + BEE::writeMatrix(t, file); | |
| 302 | 302 | } |
| 303 | 303 | }; |
| 304 | 304 | ... | ... |