Commit bb82e2dbc507292e0c8d564836c922924c23f69e

Authored by Scott Klum
1 parent 85ee2f90

Switched to using two variables

Showing 1 changed file with 33 additions and 35 deletions
openbr/plugins/stasm4.cpp
@@ -64,8 +64,10 @@ class StasmTransform : public UntrainableTransform @@ -64,8 +64,10 @@ class StasmTransform : public UntrainableTransform
64 BR_PROPERTY(bool, stasm3Format, false) 64 BR_PROPERTY(bool, stasm3Format, false)
65 Q_PROPERTY(bool clearLandmarks READ get_clearLandmarks WRITE set_clearLandmarks RESET reset_clearLandmarks STORED false) 65 Q_PROPERTY(bool clearLandmarks READ get_clearLandmarks WRITE set_clearLandmarks RESET reset_clearLandmarks STORED false)
66 BR_PROPERTY(bool, clearLandmarks, false) 66 BR_PROPERTY(bool, clearLandmarks, false)
67 - Q_PROPERTY(QStringList pinEyes READ get_pinEyes WRITE set_pinEyes RESET reset_pinEyes STORED false)  
68 - BR_PROPERTY(QStringList, pinEyes, QStringList()) 67 + Q_PROPERTY(QList<float> pinPoints READ get_pinPoints WRITE set_pinPoints RESET reset_pinPoints STORED false)
  68 + BR_PROPERTY(QList<float>, pinPoints, QList<float>())
  69 + Q_PROPERTY(QStringList pinLabels READ get_pinLabels WRITE set_pinLabels RESET reset_pinLabels STORED false)
  70 + BR_PROPERTY(QStringList, pinLabels, QStringList())
69 71
70 Resource<StasmCascadeClassifier> stasmCascadeResource; 72 Resource<StasmCascadeClassifier> stasmCascadeResource;
71 73
@@ -91,43 +93,39 @@ class StasmTransform : public UntrainableTransform @@ -91,43 +93,39 @@ class StasmTransform : public UntrainableTransform
91 int nLandmarks = stasm_NLANDMARKS; 93 int nLandmarks = stasm_NLANDMARKS;
92 float landmarks[2 * stasm_NLANDMARKS]; 94 float landmarks[2 * stasm_NLANDMARKS];
93 95
94 - if (!pinEyes.isEmpty()) {  
95 - // Two use cases are accounted for:  
96 - // 1. Pin eyes without normalization: in this case the string list should contain the KEYS for right then left eyes, respectively.  
97 - // 2. Pin eyes with normalization: in this case the string list should contain the COORDINATES of the right then left eyes, respectively.  
98 - // If both cases fail, we default to stasm_search_single. 96 + bool searchPinned = false;
  97 +
  98 + QPointF rightEye, leftEye;
  99 + /* Two use cases are accounted for:
  100 + * 1. Pin eyes without normalization: in this case the string list should contain the KEYS for right then left eyes, respectively.
  101 + * 2. Pin eyes with normalization: in this case the string list should contain the COORDINATES of the right then left eyes, respectively.
  102 + * Currently, we only support normalization with a transformation such that the src file contains Affine_0 and Affine_1. Checking for
  103 + * these keys prevents us from pinning eyes on a face that wasn't actually transformed (see AffineTransform).
  104 + * If both cases fail, we default to stasm_search_single. */
  105 +
  106 + if (!pinPoints.isEmpty() && src.file.contains("Affine_0") && src.file.contains("Affine_1")) {
  107 + rightEye = QPointF(pinPoints.at(0), pinPoints.at(1));
  108 + leftEye = QPointF(pinPoints.at(2), pinPoints.at(3));
  109 + searchPinned = true;
  110 + } else if (!pinLabels.isEmpty()) {
  111 + rightEye = src.file.get<QPointF>(pinLabels.at(0), QPointF());
  112 + leftEye = src.file.get<QPointF>(pinLabels.at(1), QPointF());
  113 + searchPinned = true;
  114 + }
  115 +
  116 + if (searchPinned) {
  117 + float pins[2 * stasm_NLANDMARKS];
99 118
100 - bool ok = false;  
101 - QPointF rightEye;  
102 - QPointF leftEye;  
103 -  
104 - if (src.file.contains("Affine_0") && src.file.contains("Affine_1")) {  
105 - rightEye = QtUtils::toPoint(pinEyes.at(0),&ok);  
106 - leftEye = QtUtils::toPoint(pinEyes.at(1),&ok);  
107 - }  
108 -  
109 - if (!ok) {  
110 - if (src.file.contains(pinEyes.at(0)) && src.file.contains(pinEyes.at(1)))  
111 - {  
112 - rightEye = src.file.get<QPointF>(pinEyes.at(0), QPointF());  
113 - leftEye = src.file.get<QPointF>(pinEyes.at(1), QPointF());  
114 - ok = true;  
115 - } 119 + 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(); }
  122 + else { pins[2*i] = 0; pins[2*i+1] = 0; }
116 } 123 }
117 124
118 - float eyes[2 * stasm_NLANDMARKS];  
119 -  
120 - if (ok) {  
121 - for (int i = 0; i < nLandmarks; i++) {  
122 - if (i == 38) /*Stasm Right Eye*/ { eyes[2*i] = rightEye.x(); eyes[2*i+1] = rightEye.y(); }  
123 - else if (i == 39) /*Stasm Left Eye*/ { eyes[2*i] = leftEye.x(); eyes[2*i+1] = leftEye.y(); }  
124 - else { eyes[2*i] = 0; eyes[2*i+1] = 0; }  
125 - }  
126 - stasm_search_pinned(landmarks, eyes, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, NULL); 125 + stasm_search_pinned(landmarks, pins, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, NULL);
127 126
128 - // The ASM in Stasm is guaranteed to converge in this case  
129 - foundFace = 1;  
130 - } 127 + // The ASM in Stasm is guaranteed to converge in this case
  128 + foundFace = 1;
131 } 129 }
132 130
133 if (!foundFace) stasm_search_single(&foundFace, landmarks, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL); 131 if (!foundFace) stasm_search_single(&foundFace, landmarks, reinterpret_cast<const char*>(src.m().data), src.m().cols, src.m().rows, *stasmCascade, NULL, NULL);