diff --git a/3rdparty/stasm4.0.0/stasm/faceroi.cpp b/3rdparty/stasm4.0.0/stasm/faceroi.cpp index b7f9120..e999cfd 100755 --- a/3rdparty/stasm4.0.0/stasm/faceroi.cpp +++ b/3rdparty/stasm4.0.0/stasm/faceroi.cpp @@ -3,6 +3,7 @@ // Copyright (C) 2005-2013, Stephen Milborrow #include "stasm.h" +#include namespace stasm { diff --git a/3rdparty/stasm4.0.0/stasm/pinstart.cpp b/3rdparty/stasm4.0.0/stasm/pinstart.cpp index c22e122..55c14ec 100755 --- a/3rdparty/stasm4.0.0/stasm/pinstart.cpp +++ b/3rdparty/stasm4.0.0/stasm/pinstart.cpp @@ -3,6 +3,7 @@ // Copyright (C) 2005-2013, Stephen Milborrow #include "stasm.h" +#include namespace stasm { @@ -267,8 +268,8 @@ void PinnedStartShapeAndRoi( // use the pinned landmarks to init the start sha const Shape& pinned) // in: manually pinned landmarks { double rot, yaw; - EstRotAndYawFrom5PointShape(rot, yaw, - As5PointShape(pinned, mods[0]->MeanShape_())); + EstRotAndYawFrom5PointShape(rot, yaw, As5PointShape(pinned, mods[0]->MeanShape_())); + const EYAW eyaw = DegreesAsEyaw(yaw, NSIZE(mods)); const int imod = EyawAsModIndex(eyaw, mods); // select ASM model based on yaw if (trace_g) diff --git a/3rdparty/stasm4.0.0/stasm/stasm_lib.cpp b/3rdparty/stasm4.0.0/stasm/stasm_lib.cpp index fa4b26c..6295fa8 100755 --- a/3rdparty/stasm4.0.0/stasm/stasm_lib.cpp +++ b/3rdparty/stasm4.0.0/stasm/stasm_lib.cpp @@ -244,24 +244,21 @@ int stasm_search_single( // wrapper for stasm_search_auto and friends int stasm_search_pinned( // call after the user has pinned some points float* landmarks, // out: x0, y0, x1, y1, ..., caller must allocate const float* pinned, // in: pinned landmarks (0,0 points not pinned) - const char* img, // in: gray image data, top left corner at 0,0 + const char* data, // in: gray image data, top left corner at 0,0 int width, // in: image width int height, // in: image height const char* imgpath) // in: image path, used only for err msgs and debug { - (void) img; (void) width; (void) height; (void) imgpath; int returnval = 1; // assume success - CatchOpenCvErrs(); try { - CV_Assert(imgpath && STRNLEN(imgpath, SLEN) < SLEN); CheckStasmInit(); - //img_g = Image(height, width, (unsigned char*)img); + Image img = Image(height, width,(unsigned char*)data); const Shape pinnedshape(LandmarksAsShape(pinned)); @@ -271,8 +268,7 @@ int stasm_search_pinned( // call after the user has pinned some points DetPar detpar_roi; // detpar translated to ROI frame DetPar detpar; // params returned by pseudo face det, in img frame - /*PinnedStartShapeAndRoi(shape, face_roi, detpar_roi, detpar, pinned_roi, - img_g, mods_g, pinnedshape);*/ + PinnedStartShapeAndRoi(shape, face_roi, detpar_roi, detpar, pinned_roi, img, mods_g, pinnedshape); // now working with maybe flipped ROI and start shape in ROI frame 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 RoundMat(shape); ForcePinnedPoints(shape, pinnedshape); // undo above RoundMat on pinned points ShapeToLandmarks(landmarks, shape); - if (trace_g) - lprintf("\n"); } catch(...) { returnval = 0; // a call was made to Err or a CV_Assert failed } - UncatchOpenCvErrs(); return returnval; } diff --git a/openbr/core/eval.cpp b/openbr/core/eval.cpp index 9bb9886..4d9b4a7 100644 --- a/openbr/core/eval.cpp +++ b/openbr/core/eval.cpp @@ -114,6 +114,8 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv) float result = -1; + qDebug() << simmat.rows << simmat.cols; + // Make comparisons QList comparisons; comparisons.reserve(simmat.rows*simmat.cols); int genuineCount = 0, impostorCount = 0, numNaNs = 0; diff --git a/openbr/core/fuse.cpp b/openbr/core/fuse.cpp index 4a91c46..36ca782 100644 --- a/openbr/core/fuse.cpp +++ b/openbr/core/fuse.cpp @@ -16,6 +16,7 @@ #include #include +#include "openbr/core/opencvutils.h" #include #include #include @@ -36,8 +37,8 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) for (int j=0; j(i,j); if ((mask.at(i,j) == BEE::DontCare) || - (val == -std::numeric_limits::infinity()) || - (val == std::numeric_limits::infinity())) + (val == -std::numeric_limits::max()) || + (val == std::numeric_limits::max())) continue; vals.append(val); } @@ -53,8 +54,8 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) for (int j=0; j(i,j) == BEE::DontCare) continue; float &val = matrix.at(i,j); - if (val == -std::numeric_limits::infinity()) val = 0; - else if (val == std::numeric_limits::infinity()) val = 1; + if (val == -std::numeric_limits::max()) val = 0; + else if (val == std::numeric_limits::max()) val = 1; else val = (val - min) / (max - min); } } @@ -64,8 +65,8 @@ static void normalizeMatrix(Mat &matrix, const Mat &mask, const QString &method) for (int j=0; j(i,j) == BEE::DontCare) continue; float &val = matrix.at(i,j); - if (val == -std::numeric_limits::infinity()) val = (min - mean) / stddev; - else if (val == std::numeric_limits::infinity()) val = (max - mean) / stddev; + if (val == -std::numeric_limits::max()) val = (min - mean) / stddev; + else if (val == std::numeric_limits::max()) val = (max - mean) / stddev; else val = (val - mean) / stddev; } } @@ -80,6 +81,7 @@ void br::Fuse(const QStringList &inputSimmats, File mask, const QString &normali QList matrices; foreach (const QString &simmat, inputSimmats) matrices.append(BEE::readSimmat(simmat)); + if ((matrices.size() < 2) && (fusion != "None")) qFatal("Expected at least two similarity matrices."); if ((matrices.size() > 1) && (fusion == "None")) qFatal("Expected exactly one similarity matrix."); diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index e7c6007..0516731 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -385,31 +385,25 @@ BR_REGISTER(Transform, RegexPropertyTransform) * \brief Calculate metadata statistics * \author Scott Klum \cite sklum */ -class MetadataStatisticsTransform : public Transform +class MetadataStatisticsTransform : public UntrainableTransform { Q_OBJECT Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) BR_PROPERTY(QStringList, keys, QStringList()) - void train(const TemplateList &data) - { - QHash statHash; - - foreach (const Template &t, data) { - foreach (const QString &key, keys) { - QString value = t.file.get(key, QString()); - - if (value.isEmpty()) continue; - int count = statHash.value(value,0); - statHash.value(value,count+1); - } - } - foreach (const QString &key, statHash.keys()) fprintf(stdout, "%s: %s\n", qPrintable(key), qPrintable(statHash.value(key))); - } + mutable QHash statHash; void project(const Template &src, Template &dst) const { dst = src; + foreach (const QString &key, keys) { + QString value = src.file.get(key, QString()); + + if (value.isEmpty()) continue; + int count = statHash.value(value,0); + statHash.insert(value,count+1); + } + foreach (const QString &key, statHash.keys()) qDebug() << key << statHash.value(key); } }; diff --git a/openbr/plugins/output.cpp b/openbr/plugins/output.cpp index 6417244..7b643a6 100644 --- a/openbr/plugins/output.cpp +++ b/openbr/plugins/output.cpp @@ -268,15 +268,17 @@ class rrOutput : public MatrixOutput for (int i=0; i Pair; foreach (const Pair &pair, Common::Sort(OpenCVUtils::matrixToVector(data.row(i)), true, limit)) { - if (pair.first < threshold) break; - File target = targetFiles[pair.second]; - target.set("Score", QString::number(pair.first)); - if (simple) files.append(target.baseName() + " " + QString::number(pair.first)); - else files.append(target.flat()); + if (Globals->crossValidate > 0 ? (targetFiles[pair.second].get("Partition",-1) == -1 || targetFiles[pair.second].get("Partition",-1) == queryFiles[i].get("Partition",-1)) : true) { + if (pair.first < threshold) break; + File target = targetFiles[pair.second]; + target.set("Score", QString::number(pair.first)); + if (simple) files.append(target.baseName() + " " + QString::number(pair.first)); + else files.append(target.flat()); + } } lines.append(files.join(byLine ? "\n" : ",")); } @@ -429,7 +431,7 @@ class rankOutput : public MatrixOutput typedef QPair Pair; int rank = 1; foreach (const Pair &pair, Common::Sort(OpenCVUtils::matrixToVector(data.row(i)), true)) { - if (Globals->crossValidate > 0 ? (targetFiles[pair.second].get("Partition",-1) == queryFiles[i].get("Partition",-1)) : true) { + if (Globals->crossValidate > 0 ? (targetFiles[pair.second].get("Partition",-1) == -1 || targetFiles[pair.second].get("Partition",-1) == queryFiles[i].get("Partition",-1)) : true) { if (QString(targetFiles[pair.second]) != QString(queryFiles[i])) { if (targetFiles[pair.second].get("Label") == queryFiles[i].get("Label")) { ranks.append(rank); diff --git a/openbr/plugins/regions.cpp b/openbr/plugins/regions.cpp index bd850aa..4eda497 100644 --- a/openbr/plugins/regions.cpp +++ b/openbr/plugins/regions.cpp @@ -348,6 +348,7 @@ class RectFromPointsTransform : public UntrainableTransform 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))); else { + 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(); 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))); dst.m() = src.m(); } diff --git a/openbr/plugins/stasm4.cpp b/openbr/plugins/stasm4.cpp index c26df92..cfb4951 100644 --- a/openbr/plugins/stasm4.cpp +++ b/openbr/plugins/stasm4.cpp @@ -78,7 +78,29 @@ class StasmTransform : public UntrainableTransform int foundface; int nLandmarks = stasm_NLANDMARKS; float landmarks[2 * stasm_NLANDMARKS]; - stasm_search_single(&foundface, landmarks, reinterpret_cast(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); + + bool pinned = true; + + if (pinned) { + if (src.file.contains("Affine_0")) { + float eyes[2 * stasm_NLANDMARKS]; + + for (int i = 0; i < nLandmarks; i++) { + if (i == 38) { eyes[2*i] = 66.24; eyes[2*i+1] = 126; } + else if (i == 39) { eyes[2*i] = 125.76; eyes[2*i+1] = 126; } + else { eyes[2*i] = 0; eyes[2*i+1] = 0; } + } + + stasm_search_pinned(landmarks, eyes, reinterpret_cast(src.m().data), src.m().cols, src.m().rows, NULL); + + foundface = 1; + } else { + qDebug() << "Single search..."; + stasm_search_single(&foundface, landmarks, reinterpret_cast(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); + } + } else { + stasm_search_single(&foundface, landmarks, reinterpret_cast(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); + } if (stasm3Format) { nLandmarks = 76; @@ -99,7 +121,7 @@ class StasmTransform : public UntrainableTransform QPointF point(landmarks[2 * i], landmarks[2 * i + 1]); dst.file.appendPoint(point); if (i == 38) dst.file.set("StasmRightEye",point); - if (i == 39) dst.file.set("StasmLeftEye", point); + else if (i == 39) dst.file.set("StasmLeftEye", point); } }