Commit 98a8bc75835e4256244990c0003703fb1ab47c2d
1 parent
3de17d86
Naming face points in dlib
Showing
1 changed file
with
19 additions
and
0 deletions
openbr/plugins/classification/dlib.cpp
| ... | ... | @@ -42,6 +42,23 @@ private: |
| 42 | 42 | shapeResource.setResourceMaker(new DLibShapeResourceMaker()); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | + QPointF averagePoints(const QList<QPointF> &points, int rangeBegin, int rangeEnd) const | |
| 46 | + { | |
| 47 | + QPointF point; | |
| 48 | + for (int i=rangeBegin; i<rangeEnd; i++) | |
| 49 | + point += points[i]; | |
| 50 | + point /= (rangeEnd-rangeBegin); | |
| 51 | + return point; | |
| 52 | + } | |
| 53 | + | |
| 54 | + void setFacePoints(Template &dst) const | |
| 55 | + { | |
| 56 | + const QList<QPointF> points = dst.file.points(); | |
| 57 | + dst.file.set("LeftEye",averagePoints(points,36,42)); | |
| 58 | + dst.file.set("RightEye",averagePoints(points,42,48)); | |
| 59 | + dst.file.set("Chin",points[8]); | |
| 60 | + } | |
| 61 | + | |
| 45 | 62 | void project(const Template &src, Template &dst) const |
| 46 | 63 | { |
| 47 | 64 | dst = src; |
| ... | ... | @@ -61,6 +78,7 @@ private: |
| 61 | 78 | full_object_detection shape = (*sp)(image, r); |
| 62 | 79 | for (size_t i = 0; i < shape.num_parts(); i++) |
| 63 | 80 | dst.file.appendPoint(QPointF(shape.part(i)(0),shape.part(i)(1))); |
| 81 | + setFacePoints(dst); | |
| 64 | 82 | } |
| 65 | 83 | else { // Crop the image on the rects |
| 66 | 84 | for (int j=0; j<src.file.rects().size(); ++j) |
| ... | ... | @@ -70,6 +88,7 @@ private: |
| 70 | 88 | full_object_detection shape = (*sp)(image, r); |
| 71 | 89 | for (size_t i=0; i<shape.num_parts(); i++) |
| 72 | 90 | dst.file.appendPoint(QPointF(shape.part(i)(0),shape.part(i)(1))); |
| 91 | + setFacePoints(dst); | |
| 73 | 92 | } |
| 74 | 93 | } |
| 75 | 94 | ... | ... |