Commit e6e03bfd994c11c0d860e06ea04ad155ce6600b8
1 parent
48d184af
Allows a color image to be maintained after landmark extraction
Showing
1 changed file
with
7 additions
and
4 deletions
openbr/plugins/stasm4.cpp
| @@ -75,8 +75,11 @@ class StasmTransform : public UntrainableTransform | @@ -75,8 +75,11 @@ class StasmTransform : public UntrainableTransform | ||
| 75 | 75 | ||
| 76 | void project(const Template &src, Template &dst) const | 76 | void project(const Template &src, Template &dst) const |
| 77 | { | 77 | { |
| 78 | - if (src.m().channels() != 1) qFatal("Stasm expects single channel matrices."); | ||
| 79 | - | 78 | + Mat stasmSrc(src); |
| 79 | + if (src.m().channels() == 3) | ||
| 80 | + cvtColor(src, stasmSrc, CV_BGR2GRAY); | ||
| 81 | + else if (src.m().channels() != 1) | ||
| 82 | + qFatal("Stasm expects single channel matrices."); | ||
| 80 | dst = src; | 83 | dst = src; |
| 81 | 84 | ||
| 82 | StasmCascadeClassifier *stasmCascade = stasmCascadeResource.acquire(); | 85 | StasmCascadeClassifier *stasmCascade = stasmCascadeResource.acquire(); |
| @@ -117,14 +120,14 @@ class StasmTransform : public UntrainableTransform | @@ -117,14 +120,14 @@ class StasmTransform : public UntrainableTransform | ||
| 117 | else if (i == 39) /*Stasm Left Eye*/ { eyes[2*i] = leftEye.x(); eyes[2*i+1] = leftEye.y(); } | 120 | else if (i == 39) /*Stasm Left Eye*/ { eyes[2*i] = leftEye.x(); eyes[2*i+1] = leftEye.y(); } |
| 118 | else { eyes[2*i] = 0; eyes[2*i+1] = 0; } | 121 | else { eyes[2*i] = 0; eyes[2*i+1] = 0; } |
| 119 | } | 122 | } |
| 120 | - stasm_search_pinned(landmarks, eyes, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, NULL); | 123 | + stasm_search_pinned(landmarks, eyes, reinterpret_cast<const char*>(stasmSrc.data), stasmSrc.cols, stasmSrc.rows, NULL); |
| 121 | 124 | ||
| 122 | // The ASM in Stasm is guaranteed to converge in this case | 125 | // The ASM in Stasm is guaranteed to converge in this case |
| 123 | foundFace = 1; | 126 | foundFace = 1; |
| 124 | } | 127 | } |
| 125 | } | 128 | } |
| 126 | 129 | ||
| 127 | - if (!foundFace) stasm_search_single(&foundFace, landmarks, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); | 130 | + if (!foundFace) stasm_search_single(&foundFace, landmarks, reinterpret_cast<const char*>(stasmSrc.data), stasmSrc.cols, stasmSrc.rows, *stasmCascade, NULL, NULL); |
| 128 | 131 | ||
| 129 | if (stasm3Format) { | 132 | if (stasm3Format) { |
| 130 | nLandmarks = 76; | 133 | nLandmarks = 76; |