From e6e03bfd994c11c0d860e06ea04ad155ce6600b8 Mon Sep 17 00:00:00 2001 From: Brendan Klare Date: Fri, 18 Jul 2014 12:36:25 -0400 Subject: [PATCH] Allows a color image to be maintained after landmark extraction --- openbr/plugins/stasm4.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/openbr/plugins/stasm4.cpp b/openbr/plugins/stasm4.cpp index 81c3d27..2d0a1fe 100644 --- a/openbr/plugins/stasm4.cpp +++ b/openbr/plugins/stasm4.cpp @@ -75,8 +75,11 @@ class StasmTransform : public UntrainableTransform void project(const Template &src, Template &dst) const { - if (src.m().channels() != 1) qFatal("Stasm expects single channel matrices."); - + Mat stasmSrc(src); + if (src.m().channels() == 3) + cvtColor(src, stasmSrc, CV_BGR2GRAY); + else if (src.m().channels() != 1) + qFatal("Stasm expects single channel matrices."); dst = src; StasmCascadeClassifier *stasmCascade = stasmCascadeResource.acquire(); @@ -117,14 +120,14 @@ class StasmTransform : public UntrainableTransform else if (i == 39) /*Stasm Left Eye*/ { eyes[2*i] = leftEye.x(); eyes[2*i+1] = leftEye.y(); } 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); + stasm_search_pinned(landmarks, eyes, reinterpret_cast(stasmSrc.data), stasmSrc.cols, stasmSrc.rows, NULL); // The ASM in Stasm is guaranteed to converge in this case foundFace = 1; } } - if (!foundFace) stasm_search_single(&foundFace, landmarks, reinterpret_cast(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); + if (!foundFace) stasm_search_single(&foundFace, landmarks, reinterpret_cast(stasmSrc.data), stasmSrc.cols, stasmSrc.rows, *stasmCascade, NULL, NULL); if (stasm3Format) { nLandmarks = 76; -- libgit2 0.21.4