Commit 0b850ff54b4722ac9d29d4b280979bac6ab19a4c
1 parent
0d5390bb
Finished stasm4
Showing
2 changed files
with
21 additions
and
31 deletions
3rdparty/stasm4.0.0/stasm/stasmhash.h
0 → 100644
openbr/plugins/stasm4.cpp
| 1 | #include <stasm_lib.h> | 1 | #include <stasm_lib.h> |
| 2 | +#include <stasmcascadeclassifier.h> | ||
| 2 | #include <opencv2/objdetect/objdetect.hpp> | 3 | #include <opencv2/objdetect/objdetect.hpp> |
| 3 | #include "openbr_internal.h" | 4 | #include "openbr_internal.h" |
| 4 | 5 | ||
| @@ -7,28 +8,15 @@ using namespace cv; | @@ -7,28 +8,15 @@ using namespace cv; | ||
| 7 | namespace br | 8 | namespace br |
| 8 | { | 9 | { |
| 9 | 10 | ||
| 10 | -class CascadeResourceMaker : public ResourceMaker<CascadeClassifier> | 11 | +class StasmResourceMaker : public ResourceMaker<StasmCascadeClassifier> |
| 11 | { | 12 | { |
| 12 | - QString file; | ||
| 13 | - | ||
| 14 | -public: | ||
| 15 | - CascadeResourceMaker(const QString &model) | ||
| 16 | - { | ||
| 17 | - file = Globals->sdkPath + "/share/openbr/models/"; | ||
| 18 | - if (model == "Ear") file += "haarcascades/haarcascade_ear.xml"; | ||
| 19 | - else if (model == "Eye") file += "haarcascades/haarcascade_eye_tree_eyeglasses.xml"; | ||
| 20 | - else if (model == "FrontalFace") file += "haarcascades/haarcascade_frontalface_alt2.xml"; | ||
| 21 | - else if (model == "ProfileFace") file += "haarcascades/haarcascade_profileface.xml"; | ||
| 22 | - else qFatal("Invalid model."); | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | private: | 13 | private: |
| 26 | - CascadeClassifier *make() const | 14 | + StasmCascadeClassifier *make() const |
| 27 | { | 15 | { |
| 28 | - CascadeClassifier *cascade = new CascadeClassifier(); | ||
| 29 | - if (!cascade->load(file.toStdString())) | ||
| 30 | - qFatal("Failed to load: %s", qPrintable(file)); | ||
| 31 | - return cascade; | 16 | + StasmCascadeClassifier *stasmCascade = new StasmCascadeClassifier(); |
| 17 | + if (!stasmCascade->load(Globals->sdkPath.toStdString() + "/share/openbr/models/")) | ||
| 18 | + qFatal("Failed to load Stasm Cascade"); | ||
| 19 | + return stasmCascade; | ||
| 32 | } | 20 | } |
| 33 | }; | 21 | }; |
| 34 | 22 | ||
| @@ -61,31 +49,25 @@ class StasmTransform : public UntrainableTransform | @@ -61,31 +49,25 @@ class StasmTransform : public UntrainableTransform | ||
| 61 | { | 49 | { |
| 62 | Q_OBJECT | 50 | Q_OBJECT |
| 63 | 51 | ||
| 64 | - //QList<ASM_MODEL> models; | ||
| 65 | - mutable QMutex mutex; | ||
| 66 | - | ||
| 67 | - Resource<CascadeClassifier> cascadeResource; | 52 | + Resource<StasmCascadeClassifier> stasmCascadeResource; |
| 68 | 53 | ||
| 69 | void init() | 54 | void init() |
| 70 | { | 55 | { |
| 71 | if (!stasm_init(qPrintable(Globals->sdkPath + "/share/openbr/models/stasm"), 0)) qFatal("Failed to initalize stasm."); | 56 | if (!stasm_init(qPrintable(Globals->sdkPath + "/share/openbr/models/stasm"), 0)) qFatal("Failed to initalize stasm."); |
| 72 | - cascadeResource.setResourceMaker(new CascadeResourceMaker("FrontalFace")); | 57 | + stasmCascadeResource.setResourceMaker(new StasmResourceMaker()); |
| 73 | } | 58 | } |
| 74 | 59 | ||
| 75 | void project(const Template &src, Template &dst) const | 60 | void project(const Template &src, Template &dst) const |
| 76 | { | 61 | { |
| 77 | - QMutexLocker locker(&mutex); | ||
| 78 | - | ||
| 79 | - CascadeClassifier *cascade = cascadeResource.acquire(); | 62 | + StasmCascadeClassifier *stasmCascade = stasmCascadeResource.acquire(); |
| 80 | 63 | ||
| 81 | int foundface; | 64 | int foundface; |
| 82 | float landmarks[2 * stasm_NLANDMARKS]; // x,y coords (note the 2) | 65 | float landmarks[2 * stasm_NLANDMARKS]; // x,y coords (note the 2) |
| 83 | - stasm_search_single(&foundface, landmarks, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, *cascade, NULL, NULL); | 66 | + stasm_search_single(&foundface, landmarks, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); |
| 84 | 67 | ||
| 85 | - cascadeResource.release(cascade); | 68 | + stasmCascadeResource.release(stasmCascade); |
| 86 | 69 | ||
| 87 | - if (!foundface) | ||
| 88 | - qDebug() << "No face found in " << qPrintable("/Users/scottklum/facesketchid/data/img/" + src.file.path() + "/" + src.file.fileName()); | 70 | + if (!foundface) qDebug() << "No face found in " << src.file.fileName(); |
| 89 | 71 | ||
| 90 | for (int i = 0; i < stasm_NLANDMARKS; i++) { | 72 | for (int i = 0; i < stasm_NLANDMARKS; i++) { |
| 91 | dst.file.appendPoint(QPointF(landmarks[2 * i], landmarks[2 * i + 1])); | 73 | dst.file.appendPoint(QPointF(landmarks[2 * i], landmarks[2 * i + 1])); |