Commit 17a93ada0d26ddd83757b122d475320a4fa6fb21
Merge branch 'master' of https://github.com/biometrics/openbr into events
Showing
2 changed files
with
22 additions
and
27 deletions
openbr/plugins/landmarks.cpp
| ... | ... | @@ -21,11 +21,7 @@ class ProcrustesTransform : public Transform |
| 21 | 21 | { |
| 22 | 22 | Q_OBJECT |
| 23 | 23 | |
| 24 | - Q_PROPERTY(float normReduction READ get_normReduction WRITE set_normReduction RESET reset_normReduction STORED false) | |
| 25 | - Q_PROPERTY(bool center READ get_center WRITE set_center RESET reset_center STORED false) | |
| 26 | 24 | Q_PROPERTY(bool warp READ get_warp WRITE set_warp RESET reset_warp STORED false) |
| 27 | - BR_PROPERTY(float, normReduction, 1) | |
| 28 | - BR_PROPERTY(bool, center, true) | |
| 29 | 25 | BR_PROPERTY(bool, warp, true) |
| 30 | 26 | |
| 31 | 27 | Eigen::MatrixXf meanShape; |
| ... | ... | @@ -53,10 +49,7 @@ class ProcrustesTransform : public Transform |
| 53 | 49 | |
| 54 | 50 | // Remove scale component |
| 55 | 51 | float norm = cv::norm(OpenCVUtils::toPoints(points).toVector().toStdVector()); |
| 56 | - for (int i = 0; i < points.size(); i++) { | |
| 57 | - points[i] /= (norm/normReduction); | |
| 58 | - if (center) points[i] += QPointF(datum.m().cols/2,datum.m().rows/2); | |
| 59 | - } | |
| 52 | + for (int i = 0; i < points.size(); i++) points[i] /= norm; | |
| 60 | 53 | |
| 61 | 54 | normalizedPoints.append(points); |
| 62 | 55 | } |
| ... | ... | @@ -106,8 +99,7 @@ class ProcrustesTransform : public Transform |
| 106 | 99 | Eigen::MatrixXf srcMat(points.size(), 2); |
| 107 | 100 | float norm = cv::norm(OpenCVUtils::toPoints(points).toVector().toStdVector()); |
| 108 | 101 | for (int i = 0; i < points.size(); i++) { |
| 109 | - points[i] /= (norm/normReduction); | |
| 110 | - if (center) points[i] += QPointF(src.m().cols/2,src.m().rows/2); | |
| 102 | + points[i] /= norm; | |
| 111 | 103 | srcMat(i,0) = points[i].x(); |
| 112 | 104 | srcMat(i,1) = points[i].y(); |
| 113 | 105 | } |
| ... | ... | @@ -156,10 +148,14 @@ class DelaunayTransform : public UntrainableTransform |
| 156 | 148 | { |
| 157 | 149 | Q_OBJECT |
| 158 | 150 | |
| 159 | - Q_PROPERTY(float normReduction READ get_normReduction WRITE set_normReduction RESET reset_normReduction STORED false) | |
| 151 | + Q_PROPERTY(float scaleFactor READ get_scaleFactor WRITE set_scaleFactor RESET reset_scaleFactor STORED false) | |
| 152 | + Q_PROPERTY(QString widthCrop READ get_widthCrop WRITE set_widthCrop RESET reset_widthCrop STORED false) | |
| 153 | + Q_PROPERTY(QString heightCrop READ get_heightCrop WRITE set_heightCrop RESET reset_heightCrop STORED false) | |
| 160 | 154 | Q_PROPERTY(bool warp READ get_warp WRITE set_warp RESET reset_warp STORED false) |
| 161 | 155 | Q_PROPERTY(bool draw READ get_draw WRITE set_draw RESET reset_draw STORED false) |
| 162 | - BR_PROPERTY(float, normReduction, 1) | |
| 156 | + BR_PROPERTY(float, scaleFactor, 1) | |
| 157 | + BR_PROPERTY(QString, widthCrop, QString()) | |
| 158 | + BR_PROPERTY(QString, heightCrop, QString()) | |
| 163 | 159 | BR_PROPERTY(bool, warp, true) |
| 164 | 160 | BR_PROPERTY(bool, draw, false) |
| 165 | 161 | |
| ... | ... | @@ -205,7 +201,7 @@ class DelaunayTransform : public UntrainableTransform |
| 205 | 201 | |
| 206 | 202 | bool inside = true; |
| 207 | 203 | for (int j = 0; j < 3; j++) { |
| 208 | - if (pt[j].x > src.m().cols || pt[j].y > src.m().rows || pt[j].x <= 0 || pt[j].y <= 0) inside = false; | |
| 204 | + if (pt[j].x > src.m().cols || pt[j].y > src.m().rows || pt[j].x < 0 || pt[j].y < 0) inside = false; | |
| 209 | 205 | } |
| 210 | 206 | |
| 211 | 207 | if (inside) validTriangles.append(QList<Point>()<< pt[0] << pt[1] << pt[2]); |
| ... | ... | @@ -221,8 +217,6 @@ class DelaunayTransform : public UntrainableTransform |
| 221 | 217 | } |
| 222 | 218 | } |
| 223 | 219 | |
| 224 | - bool warp = true; | |
| 225 | - | |
| 226 | 220 | if (warp) { |
| 227 | 221 | Eigen::MatrixXf R(2,2); |
| 228 | 222 | R(0,0) = src.file.get<float>("Procrustes_0_0"); |
| ... | ... | @@ -243,9 +237,9 @@ class DelaunayTransform : public UntrainableTransform |
| 243 | 237 | for (int i = 0; i < validTriangles.size(); i++) { |
| 244 | 238 | Eigen::MatrixXf srcMat(validTriangles[i].size(), 2); |
| 245 | 239 | |
| 246 | - for (int j = 0; j < validTriangles[i].size(); j++) { | |
| 247 | - srcMat(j,0) = (validTriangles[i][j].x-mean[0])/(norm/normReduction)+src.m().cols/2; | |
| 248 | - srcMat(j,1) = (validTriangles[i][j].y-mean[1])/(norm/normReduction)+src.m().rows/2; | |
| 240 | + for (int j = 0; j < 3; j++) { | |
| 241 | + srcMat(j,0) = (validTriangles[i][j].x-mean[0])/norm; | |
| 242 | + srcMat(j,1) = (validTriangles[i][j].y-mean[1])/norm; | |
| 249 | 243 | } |
| 250 | 244 | |
| 251 | 245 | Eigen::MatrixXf dstMat = srcMat*R; |
| ... | ... | @@ -255,8 +249,10 @@ class DelaunayTransform : public UntrainableTransform |
| 255 | 249 | |
| 256 | 250 | Point2f dstPoints[3]; |
| 257 | 251 | for (int j = 0; j < 3; j++) { |
| 258 | - dstPoints[j] = Point2f(dstMat(j,0),dstMat(j,1)); | |
| 259 | - mappedPoints.append(dstPoints[j]); | |
| 252 | + // Scale and shift destination points | |
| 253 | + Point2f warpedPoint = Point2f(dstMat(j,0)*scaleFactor+src.m().cols/2,dstMat(j,1)*scaleFactor+src.m().rows/2); | |
| 254 | + dstPoints[j] = warpedPoint; | |
| 255 | + mappedPoints.append(warpedPoint); | |
| 260 | 256 | } |
| 261 | 257 | |
| 262 | 258 | Mat buffer(src.m().rows,src.m().cols,src.m().type()); |
| ... | ... | @@ -274,7 +270,7 @@ class DelaunayTransform : public UntrainableTransform |
| 274 | 270 | |
| 275 | 271 | Mat output(src.m().rows,src.m().cols,src.m().type()); |
| 276 | 272 | |
| 277 | - // Optimize | |
| 273 | + // Optimization needed | |
| 278 | 274 | if (i > 0) { |
| 279 | 275 | Mat overlap; |
| 280 | 276 | bitwise_and(dst.m(),mask,overlap); |
| ... | ... | @@ -294,12 +290,10 @@ class DelaunayTransform : public UntrainableTransform |
| 294 | 290 | |
| 295 | 291 | Rect boundingBox = boundingRect(mappedPoints.toVector().toStdVector()); |
| 296 | 292 | |
| 297 | - boundingBox.x += 0; //boundingBox.width * .05; | |
| 298 | - boundingBox.y += boundingBox.height * .1; // 0.025 for nose, .05 for mouth, .10 for brow | |
| 299 | - boundingBox.width *= 1;//.975; | |
| 300 | - boundingBox.height *= .80; // .975 for nose, .95 for mouth, .925 for brow | |
| 301 | - | |
| 302 | - qDebug() << boundingBox; | |
| 293 | + boundingBox.x += boundingBox.width * QtUtils::toPoint(widthCrop).x(); | |
| 294 | + boundingBox.y += boundingBox.height * QtUtils::toPoint(heightCrop).x(); | |
| 295 | + boundingBox.width *= 1-QtUtils::toPoint(widthCrop).y(); | |
| 296 | + boundingBox.height *= 1-QtUtils::toPoint(heightCrop).y(); | |
| 303 | 297 | |
| 304 | 298 | dst.m() = Mat(dst.m(), boundingBox); |
| 305 | 299 | } | ... | ... |
openbr/plugins/regions.cpp
| ... | ... | @@ -230,6 +230,7 @@ class RectFromPointsTransform : public UntrainableTransform |
| 230 | 230 | if (src.file.points()[index].y() > maxY) maxY = src.file.points()[index].y(); |
| 231 | 231 | points.append(src.file.points()[index]); |
| 232 | 232 | } |
| 233 | + else qFatal("Incorrect indices"); | |
| 233 | 234 | } |
| 234 | 235 | |
| 235 | 236 | double width = maxX-minX; | ... | ... |