Commit 906a36e9ae7587e1e9824f6fd8e890941ebee9f2
1 parent
9f1f38db
misc improvements to stasm plugin
Showing
1 changed file
with
14 additions
and
9 deletions
openbr/plugins/stasm4.cpp
| @@ -85,9 +85,12 @@ class StasmTransform : public UntrainableTransform | @@ -85,9 +85,12 @@ class StasmTransform : public UntrainableTransform | ||
| 85 | else if (src.m().channels() != 1) | 85 | else if (src.m().channels() != 1) |
| 86 | qFatal("Stasm expects single channel matrices."); | 86 | qFatal("Stasm expects single channel matrices."); |
| 87 | 87 | ||
| 88 | - dst = src; | 88 | + // Because we pass stasmSrc.data as a pointer to a function that has no |
| 89 | + // knowledge of OpenCV regions of interest. | ||
| 90 | + if (!stasmSrc.isContinuous()) | ||
| 91 | + qFatal("Stasm expects continuous matrix data."); | ||
| 89 | 92 | ||
| 90 | - StasmCascadeClassifier *stasmCascade = stasmCascadeResource.acquire(); | 93 | + dst = src; |
| 91 | 94 | ||
| 92 | int foundFace = 0; | 95 | int foundFace = 0; |
| 93 | int nLandmarks = stasm_NLANDMARKS; | 96 | int nLandmarks = stasm_NLANDMARKS; |
| @@ -114,29 +117,31 @@ class StasmTransform : public UntrainableTransform | @@ -114,29 +117,31 @@ class StasmTransform : public UntrainableTransform | ||
| 114 | } | 117 | } |
| 115 | 118 | ||
| 116 | if (searchPinned) { | 119 | if (searchPinned) { |
| 117 | - float pins[2 * stasm_NLANDMARKS]; | 120 | + float pins[2 * stasm_NLANDMARKS]; |
| 118 | 121 | ||
| 119 | for (int i = 0; i < nLandmarks; i++) { | 122 | for (int i = 0; i < nLandmarks; i++) { |
| 120 | - if (i == 38) /*Stasm Right Eye*/ { pins[2*i] = rightEye.x(); pins[2*i+1] = rightEye.y(); } | ||
| 121 | - else if (i == 39) /*Stasm Left Eye*/ { pins[2*i] = leftEye.x(); pins[2*i+1] = leftEye.y(); } | 123 | + if (i == 38) /* Stasm Right Eye */ { pins[2*i] = rightEye.x(); pins[2*i+1] = rightEye.y(); } |
| 124 | + else if (i == 39) /* Stasm Left Eye */ { pins[2*i] = leftEye.x(); pins[2*i+1] = leftEye.y(); } | ||
| 122 | else { pins[2*i] = 0; pins[2*i+1] = 0; } | 125 | else { pins[2*i] = 0; pins[2*i+1] = 0; } |
| 123 | } | 126 | } |
| 124 | 127 | ||
| 125 | - stasm_search_pinned(landmarks, pins, reinterpret_cast<const char*>(stasmSrc.data), stasmSrc.cols, stasmSrc.rows, NULL); | 128 | + stasm_search_pinned(landmarks, pins, reinterpret_cast<const char*>(stasmSrc.data), stasmSrc.cols, stasmSrc.rows, NULL); |
| 126 | 129 | ||
| 127 | // The ASM in Stasm is guaranteed to converge in this case | 130 | // The ASM in Stasm is guaranteed to converge in this case |
| 128 | foundFace = 1; | 131 | foundFace = 1; |
| 129 | } | 132 | } |
| 130 | 133 | ||
| 131 | - if (!foundFace) stasm_search_single(&foundFace, landmarks, reinterpret_cast<const char*>(stasmSrc.data), stasmSrc.cols, stasmSrc.rows, *stasmCascade, NULL, NULL); | 134 | + if (!foundFace) { |
| 135 | + StasmCascadeClassifier *stasmCascade = stasmCascadeResource.acquire(); | ||
| 136 | + stasm_search_single(&foundFace, landmarks, reinterpret_cast<const char*>(stasmSrc.data), stasmSrc.cols, stasmSrc.rows, *stasmCascade, NULL, NULL); | ||
| 137 | + stasmCascadeResource.release(stasmCascade); | ||
| 138 | + } | ||
| 132 | 139 | ||
| 133 | if (stasm3Format) { | 140 | if (stasm3Format) { |
| 134 | nLandmarks = 76; | 141 | nLandmarks = 76; |
| 135 | stasm_convert_shape(landmarks, nLandmarks); | 142 | stasm_convert_shape(landmarks, nLandmarks); |
| 136 | } | 143 | } |
| 137 | 144 | ||
| 138 | - stasmCascadeResource.release(stasmCascade); | ||
| 139 | - | ||
| 140 | // For convenience, if these are the only points/rects we want to deal with as the algorithm progresses | 145 | // For convenience, if these are the only points/rects we want to deal with as the algorithm progresses |
| 141 | if (clearLandmarks) { | 146 | if (clearLandmarks) { |
| 142 | dst.file.clearPoints(); | 147 | dst.file.clearPoints(); |