Commit 8e8b43707c62c60562eebf1a572675a52dd8afbe
1 parent
b547b559
Made .rr output crossValidation compatible
Showing
9 changed files
with
61 additions
and
43 deletions
3rdparty/stasm4.0.0/stasm/faceroi.cpp
3rdparty/stasm4.0.0/stasm/pinstart.cpp
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | // Copyright (C) 2005-2013, Stephen Milborrow |
| 4 | 4 | |
| 5 | 5 | #include "stasm.h" |
| 6 | +#include <QDebug> | |
| 6 | 7 | |
| 7 | 8 | namespace stasm |
| 8 | 9 | { |
| ... | ... | @@ -267,8 +268,8 @@ void PinnedStartShapeAndRoi( // use the pinned landmarks to init the start sha |
| 267 | 268 | const Shape& pinned) // in: manually pinned landmarks |
| 268 | 269 | { |
| 269 | 270 | double rot, yaw; |
| 270 | - EstRotAndYawFrom5PointShape(rot, yaw, | |
| 271 | - As5PointShape(pinned, mods[0]->MeanShape_())); | |
| 271 | + EstRotAndYawFrom5PointShape(rot, yaw, As5PointShape(pinned, mods[0]->MeanShape_())); | |
| 272 | + | |
| 272 | 273 | const EYAW eyaw = DegreesAsEyaw(yaw, NSIZE(mods)); |
| 273 | 274 | const int imod = EyawAsModIndex(eyaw, mods); // select ASM model based on yaw |
| 274 | 275 | if (trace_g) | ... | ... |
3rdparty/stasm4.0.0/stasm/stasm_lib.cpp
| ... | ... | @@ -244,24 +244,21 @@ int stasm_search_single( // wrapper for stasm_search_auto and friends |
| 244 | 244 | int stasm_search_pinned( // call after the user has pinned some points |
| 245 | 245 | float* landmarks, // out: x0, y0, x1, y1, ..., caller must allocate |
| 246 | 246 | const float* pinned, // in: pinned landmarks (0,0 points not pinned) |
| 247 | - const char* img, // in: gray image data, top left corner at 0,0 | |
| 247 | + const char* data, // in: gray image data, top left corner at 0,0 | |
| 248 | 248 | int width, // in: image width |
| 249 | 249 | int height, // in: image height |
| 250 | 250 | const char* imgpath) // in: image path, used only for err msgs and debug |
| 251 | 251 | { |
| 252 | - (void) img; | |
| 253 | 252 | (void) width; |
| 254 | 253 | (void) height; |
| 255 | 254 | (void) imgpath; |
| 256 | 255 | |
| 257 | 256 | int returnval = 1; // assume success |
| 258 | - CatchOpenCvErrs(); | |
| 259 | 257 | try |
| 260 | 258 | { |
| 261 | - CV_Assert(imgpath && STRNLEN(imgpath, SLEN) < SLEN); | |
| 262 | 259 | CheckStasmInit(); |
| 263 | 260 | |
| 264 | - //img_g = Image(height, width, (unsigned char*)img); | |
| 261 | + Image img = Image(height, width,(unsigned char*)data); | |
| 265 | 262 | |
| 266 | 263 | const Shape pinnedshape(LandmarksAsShape(pinned)); |
| 267 | 264 | |
| ... | ... | @@ -271,8 +268,7 @@ int stasm_search_pinned( // call after the user has pinned some points |
| 271 | 268 | DetPar detpar_roi; // detpar translated to ROI frame |
| 272 | 269 | DetPar detpar; // params returned by pseudo face det, in img frame |
| 273 | 270 | |
| 274 | - /*PinnedStartShapeAndRoi(shape, face_roi, detpar_roi, detpar, pinned_roi, | |
| 275 | - img_g, mods_g, pinnedshape);*/ | |
| 271 | + PinnedStartShapeAndRoi(shape, face_roi, detpar_roi, detpar, pinned_roi, img, mods_g, pinnedshape); | |
| 276 | 272 | |
| 277 | 273 | // now working with maybe flipped ROI and start shape in ROI frame |
| 278 | 274 | const int imod = ABS(EyawAsModIndex(detpar.eyaw, mods_g)); |
| ... | ... | @@ -284,14 +280,11 @@ int stasm_search_pinned( // call after the user has pinned some points |
| 284 | 280 | RoundMat(shape); |
| 285 | 281 | ForcePinnedPoints(shape, pinnedshape); // undo above RoundMat on pinned points |
| 286 | 282 | ShapeToLandmarks(landmarks, shape); |
| 287 | - if (trace_g) | |
| 288 | - lprintf("\n"); | |
| 289 | 283 | } |
| 290 | 284 | catch(...) |
| 291 | 285 | { |
| 292 | 286 | returnval = 0; // a call was made to Err or a CV_Assert failed |
| 293 | 287 | } |
| 294 | - UncatchOpenCvErrs(); | |
| 295 | 288 | return returnval; |
| 296 | 289 | } |
| 297 | 290 | ... | ... |
openbr/core/eval.cpp
| ... | ... | @@ -114,6 +114,8 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv) |
| 114 | 114 | |
| 115 | 115 | float result = -1; |
| 116 | 116 | |
| 117 | + qDebug() << simmat.rows << simmat.cols; | |
| 118 | + | |
| 117 | 119 | // Make comparisons |
| 118 | 120 | QList<Comparison> comparisons; comparisons.reserve(simmat.rows*simmat.cols); |
| 119 | 121 | int genuineCount = 0, impostorCount = 0, numNaNs = 0; | ... | ... |
openbr/core/fuse.cpp
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | #include <QList> |
| 18 | 18 | #include <QStringList> |
| 19 | +#include "openbr/core/opencvutils.h" | |
| 19 | 20 | #include <limits> |
| 20 | 21 | #include <vector> |
| 21 | 22 | #include <opencv2/core/core.hpp> |
| ... | ... | @@ -36,8 +37,8 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) |
| 36 | 37 | for (int j=0; j<matrix.cols; j++) { |
| 37 | 38 | float val = matrix.at<float>(i,j); |
| 38 | 39 | if ((mask.at<BEE::Mask_t>(i,j) == BEE::DontCare) || |
| 39 | - (val == -std::numeric_limits<float>::infinity()) || | |
| 40 | - (val == std::numeric_limits<float>::infinity())) | |
| 40 | + (val == -std::numeric_limits<float>::max()) || | |
| 41 | + (val == std::numeric_limits<float>::max())) | |
| 41 | 42 | continue; |
| 42 | 43 | vals.append(val); |
| 43 | 44 | } |
| ... | ... | @@ -53,8 +54,8 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) |
| 53 | 54 | for (int j=0; j<matrix.cols; j++) { |
| 54 | 55 | if (mask.at<BEE::Mask_t>(i,j) == BEE::DontCare) continue; |
| 55 | 56 | float &val = matrix.at<float>(i,j); |
| 56 | - if (val == -std::numeric_limits<float>::infinity()) val = 0; | |
| 57 | - else if (val == std::numeric_limits<float>::infinity()) val = 1; | |
| 57 | + if (val == -std::numeric_limits<float>::max()) val = 0; | |
| 58 | + else if (val == std::numeric_limits<float>::max()) val = 1; | |
| 58 | 59 | else val = (val - min) / (max - min); |
| 59 | 60 | } |
| 60 | 61 | } |
| ... | ... | @@ -64,8 +65,8 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) |
| 64 | 65 | for (int j=0; j<matrix.cols; j++) { |
| 65 | 66 | if (mask.at<BEE::Mask_t>(i,j) == BEE::DontCare) continue; |
| 66 | 67 | float &val = matrix.at<float>(i,j); |
| 67 | - if (val == -std::numeric_limits<float>::infinity()) val = (min - mean) / stddev; | |
| 68 | - else if (val == std::numeric_limits<float>::infinity()) val = (max - mean) / stddev; | |
| 68 | + if (val == -std::numeric_limits<float>::max()) val = (min - mean) / stddev; | |
| 69 | + else if (val == std::numeric_limits<float>::max()) val = (max - mean) / stddev; | |
| 69 | 70 | else val = (val - mean) / stddev; |
| 70 | 71 | } |
| 71 | 72 | } |
| ... | ... | @@ -80,6 +81,7 @@ void br::Fuse(const QStringList &inputSimmats, File mask, const QString &normali |
| 80 | 81 | QList<Mat> matrices; |
| 81 | 82 | foreach (const QString &simmat, inputSimmats) |
| 82 | 83 | matrices.append(BEE::readSimmat(simmat)); |
| 84 | + | |
| 83 | 85 | if ((matrices.size() < 2) && (fusion != "None")) qFatal("Expected at least two similarity matrices."); |
| 84 | 86 | if ((matrices.size() > 1) && (fusion == "None")) qFatal("Expected exactly one similarity matrix."); |
| 85 | 87 | ... | ... |
openbr/plugins/misc.cpp
| ... | ... | @@ -385,31 +385,25 @@ BR_REGISTER(Transform, RegexPropertyTransform) |
| 385 | 385 | * \brief Calculate metadata statistics |
| 386 | 386 | * \author Scott Klum \cite sklum |
| 387 | 387 | */ |
| 388 | -class MetadataStatisticsTransform : public Transform | |
| 388 | +class MetadataStatisticsTransform : public UntrainableTransform | |
| 389 | 389 | { |
| 390 | 390 | Q_OBJECT |
| 391 | 391 | Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) |
| 392 | 392 | BR_PROPERTY(QStringList, keys, QStringList()) |
| 393 | 393 | |
| 394 | - void train(const TemplateList &data) | |
| 395 | - { | |
| 396 | - QHash<QString,int> statHash; | |
| 397 | - | |
| 398 | - foreach (const Template &t, data) { | |
| 399 | - foreach (const QString &key, keys) { | |
| 400 | - QString value = t.file.get<QString>(key, QString()); | |
| 401 | - | |
| 402 | - if (value.isEmpty()) continue; | |
| 403 | - int count = statHash.value(value,0); | |
| 404 | - statHash.value(value,count+1); | |
| 405 | - } | |
| 406 | - } | |
| 407 | - foreach (const QString &key, statHash.keys()) fprintf(stdout, "%s: %s\n", qPrintable(key), qPrintable(statHash.value(key))); | |
| 408 | - } | |
| 394 | + mutable QHash<QString,int> statHash; | |
| 409 | 395 | |
| 410 | 396 | void project(const Template &src, Template &dst) const |
| 411 | 397 | { |
| 412 | 398 | dst = src; |
| 399 | + foreach (const QString &key, keys) { | |
| 400 | + QString value = src.file.get<QString>(key, QString()); | |
| 401 | + | |
| 402 | + if (value.isEmpty()) continue; | |
| 403 | + int count = statHash.value(value,0); | |
| 404 | + statHash.insert(value,count+1); | |
| 405 | + } | |
| 406 | + foreach (const QString &key, statHash.keys()) qDebug() << key << statHash.value(key); | |
| 413 | 407 | } |
| 414 | 408 | }; |
| 415 | 409 | ... | ... |
openbr/plugins/output.cpp
| ... | ... | @@ -268,15 +268,17 @@ class rrOutput : public MatrixOutput |
| 268 | 268 | |
| 269 | 269 | for (int i=0; i<queryFiles.size(); i++) { |
| 270 | 270 | QStringList files; |
| 271 | - if (!byLine) files.append(queryFiles[i]); | |
| 271 | + files.append(queryFiles[i]); | |
| 272 | 272 | |
| 273 | 273 | typedef QPair<float,int> Pair; |
| 274 | 274 | foreach (const Pair &pair, Common::Sort(OpenCVUtils::matrixToVector<float>(data.row(i)), true, limit)) { |
| 275 | - if (pair.first < threshold) break; | |
| 276 | - File target = targetFiles[pair.second]; | |
| 277 | - target.set("Score", QString::number(pair.first)); | |
| 278 | - if (simple) files.append(target.baseName() + " " + QString::number(pair.first)); | |
| 279 | - else files.append(target.flat()); | |
| 275 | + if (Globals->crossValidate > 0 ? (targetFiles[pair.second].get<int>("Partition",-1) == -1 || targetFiles[pair.second].get<int>("Partition",-1) == queryFiles[i].get<int>("Partition",-1)) : true) { | |
| 276 | + if (pair.first < threshold) break; | |
| 277 | + File target = targetFiles[pair.second]; | |
| 278 | + target.set("Score", QString::number(pair.first)); | |
| 279 | + if (simple) files.append(target.baseName() + " " + QString::number(pair.first)); | |
| 280 | + else files.append(target.flat()); | |
| 281 | + } | |
| 280 | 282 | } |
| 281 | 283 | lines.append(files.join(byLine ? "\n" : ",")); |
| 282 | 284 | } |
| ... | ... | @@ -429,7 +431,7 @@ class rankOutput : public MatrixOutput |
| 429 | 431 | typedef QPair<float,int> Pair; |
| 430 | 432 | int rank = 1; |
| 431 | 433 | foreach (const Pair &pair, Common::Sort(OpenCVUtils::matrixToVector<float>(data.row(i)), true)) { |
| 432 | - if (Globals->crossValidate > 0 ? (targetFiles[pair.second].get<int>("Partition",-1) == queryFiles[i].get<int>("Partition",-1)) : true) { | |
| 434 | + if (Globals->crossValidate > 0 ? (targetFiles[pair.second].get<int>("Partition",-1) == -1 || targetFiles[pair.second].get<int>("Partition",-1) == queryFiles[i].get<int>("Partition",-1)) : true) { | |
| 433 | 435 | if (QString(targetFiles[pair.second]) != QString(queryFiles[i])) { |
| 434 | 436 | if (targetFiles[pair.second].get<QString>("Label") == queryFiles[i].get<QString>("Label")) { |
| 435 | 437 | ranks.append(rank); | ... | ... |
openbr/plugins/regions.cpp
| ... | ... | @@ -348,6 +348,7 @@ class RectFromPointsTransform : public UntrainableTransform |
| 348 | 348 | |
| 349 | 349 | if (crop) dst.m() = src.m()(Rect(std::max(0.0, minX - deltaWidth/2.0), std::max(0.0, minY - deltaHeight/2.0), std::min((double)src.m().cols, width), std::min((double)src.m().rows, height))); |
| 350 | 350 | else { |
| 351 | + qDebug() << QRectF(std::max(0.0, minX - deltaWidth/2.0), std::max(0.0, minY - deltaHeight/2.0), std::min((double)src.m().cols, width), std::min((double)src.m().rows, height)).size(); | |
| 351 | 352 | dst.file.appendRect(QRectF(std::max(0.0, minX - deltaWidth/2.0), std::max(0.0, minY - deltaHeight/2.0), std::min((double)src.m().cols, width), std::min((double)src.m().rows, height))); |
| 352 | 353 | dst.m() = src.m(); |
| 353 | 354 | } | ... | ... |
openbr/plugins/stasm4.cpp
| ... | ... | @@ -78,7 +78,29 @@ class StasmTransform : public UntrainableTransform |
| 78 | 78 | int foundface; |
| 79 | 79 | int nLandmarks = stasm_NLANDMARKS; |
| 80 | 80 | float landmarks[2 * stasm_NLANDMARKS]; |
| 81 | - stasm_search_single(&foundface, landmarks, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); | |
| 81 | + | |
| 82 | + bool pinned = true; | |
| 83 | + | |
| 84 | + if (pinned) { | |
| 85 | + if (src.file.contains("Affine_0")) { | |
| 86 | + float eyes[2 * stasm_NLANDMARKS]; | |
| 87 | + | |
| 88 | + for (int i = 0; i < nLandmarks; i++) { | |
| 89 | + if (i == 38) { eyes[2*i] = 66.24; eyes[2*i+1] = 126; } | |
| 90 | + else if (i == 39) { eyes[2*i] = 125.76; eyes[2*i+1] = 126; } | |
| 91 | + else { eyes[2*i] = 0; eyes[2*i+1] = 0; } | |
| 92 | + } | |
| 93 | + | |
| 94 | + stasm_search_pinned(landmarks, eyes, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, NULL); | |
| 95 | + | |
| 96 | + foundface = 1; | |
| 97 | + } else { | |
| 98 | + qDebug() << "Single search..."; | |
| 99 | + stasm_search_single(&foundface, landmarks, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); | |
| 100 | + } | |
| 101 | + } else { | |
| 102 | + stasm_search_single(&foundface, landmarks, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); | |
| 103 | + } | |
| 82 | 104 | |
| 83 | 105 | if (stasm3Format) { |
| 84 | 106 | nLandmarks = 76; |
| ... | ... | @@ -99,7 +121,7 @@ class StasmTransform : public UntrainableTransform |
| 99 | 121 | QPointF point(landmarks[2 * i], landmarks[2 * i + 1]); |
| 100 | 122 | dst.file.appendPoint(point); |
| 101 | 123 | if (i == 38) dst.file.set("StasmRightEye",point); |
| 102 | - if (i == 39) dst.file.set("StasmLeftEye", point); | |
| 124 | + else if (i == 39) dst.file.set("StasmLeftEye", point); | |
| 103 | 125 | } |
| 104 | 126 | } |
| 105 | 127 | ... | ... |