Skip to content

Commit

Permalink
Merge pull request #48 from micuat/010
Browse files Browse the repository at this point in the history
0.10 and various fixes
  • Loading branch information
HalfdanJ authored Sep 4, 2018
2 parents c6de289 + a235257 commit 4319ac7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 49 deletions.
17 changes: 9 additions & 8 deletions addon_config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,32 @@ common:
# a specific platform

ADDON_SOURCES_EXCLUDE = libs/dlib/include/*
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/*
ADDON_INCLUDES_EXCLUDE += libs/dlib/include/%
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/dlib
#ADDON_INCLUDES_EXCLUDE += libs/dlib/include/%
ADDON_INCLUDES = libs/dlib/include/
ADDON_INCLUDES += src

osx:
ADDON_SOURCES_EXCLUDE = libs/dlib/include/%
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/%
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/dlib
ADDON_LIBS = libs/dlib/lib/osx/libdlib.a

android/armeabi-v7a:
ADDON_SOURCES_EXCLUDE = libs/dlib/include/*
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/*
ADDON_INCLUDES_EXCLUDE += libs/dlib/include/%
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/dlib
#ADDON_INCLUDES_EXCLUDE += libs/dlib/include/%
ADDON_LIBS = libs/dlib/lib/android/armeabi-v7a/libdlib.a

android/x86:
ADDON_SOURCES_EXCLUDE = libs/dlib/include/*
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/*
ADDON_INCLUDES_EXCLUDE += libs/dlib/include/%
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/dlib
#ADDON_INCLUDES_EXCLUDE += libs/dlib/include/%
ADDON_LIBS = libs/dlib/lib/android/x86/libdlib.a

vs:
ADDON_SOURCES_EXCLUDE = libs/dlib/include/%
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/%
ADDON_INCLUDES_EXCLUDE = libs/dlib/include/dlib
ADDON_LIBS = libs/dlib/lib/win/Release/dlib.lib
ADDON_CFLAGS = "/D _USE_MATH_DEFINES"


2 changes: 1 addition & 1 deletion src/ofxFaceTracker2.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ofxFaceTracker2 : public ofThread {
void rotate_90n(cv::Mat &src, cv::Mat &dst, int angle);

bool threaded;
ofMutex mutex;
std::mutex mutex;
bool imageDirty;

dlib::frontal_face_detector faceDetector;
Expand Down
43 changes: 26 additions & 17 deletions src/ofxFaceTracker2InputInfo.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "ofConstants.h"
#include "ofMatrix4x4.h"
#include "glm/glm.hpp"

#include "ofxCv.h"

Expand All @@ -12,7 +12,7 @@ class ofxFaceTracker2InputInfo {
int imageRotation;

// Parameters calculated automatically
ofMatrix4x4 rotationMatrix;
glm::mat4 rotationMatrix;
ofxCv::Intrinsics intrinsics;

// Constructor
Expand All @@ -26,23 +26,32 @@ class ofxFaceTracker2InputInfo {
, imageRotation(imageRotation) {
// Calculate rotation matrix
if(imageRotation == 90){
rotationMatrix.makeIdentityMatrix();
rotationMatrix.translate(-landmarkWidth,0,0);
rotationMatrix.scale(((float)inputWidth / landmarkHeight), ((float)inputWidth / landmarkHeight), 1);
rotationMatrix.rotate(-90, 0,0,1);
rotationMatrix = glm::mat4(1.f);
rotationMatrix = glm::translate(rotationMatrix, glm::vec3((float)-landmarkWidth, 0.f, 0.f));
rotationMatrix = glm::scale(rotationMatrix, glm::vec3((float)inputWidth / landmarkHeight,
(float)inputWidth / landmarkHeight,
1.f));
rotationMatrix = glm::rotate(rotationMatrix, (float)-M_PI/2.0f, glm::vec3(0.f, 0.f, 1.f));
} else if(imageRotation == 270){
rotationMatrix.makeIdentityMatrix();
rotationMatrix.translate(0, -landmarkHeight,0);
rotationMatrix.scale(((float)inputWidth / landmarkHeight), ((float)inputWidth / landmarkHeight), 1);
rotationMatrix.rotate(90, 0,0,1);
rotationMatrix = glm::mat4(1.f);
rotationMatrix = glm::translate(rotationMatrix, glm::vec3(0.f, (float)-landmarkHeight, 0.f));
rotationMatrix = glm::scale(rotationMatrix, glm::vec3((float)inputWidth / landmarkHeight,
(float)inputWidth / landmarkHeight,
1.f));
rotationMatrix = glm::rotate(rotationMatrix, (float)M_PI/2.0f, glm::vec3(0.f, 0.f, 1.f));
} else if(imageRotation == 180){
rotationMatrix.makeIdentityMatrix();
rotationMatrix.translate(-landmarkWidth, -landmarkHeight,0);
rotationMatrix.scale(((float)inputWidth / landmarkWidth), ((float)inputWidth / landmarkWidth), 1);
rotationMatrix.rotate(180, 0,0,1);
rotationMatrix = glm::mat4(1.f);
rotationMatrix = glm::translate(rotationMatrix, glm::vec3((float)-landmarkWidth,
(float)-landmarkHeight, 0.f));
rotationMatrix = glm::scale(rotationMatrix, glm::vec3((float)inputWidth / landmarkWidth,
(float)inputWidth / landmarkWidth,
1.f));
rotationMatrix = glm::rotate(rotationMatrix, (float)M_PI, glm::vec3(0.f, 0.f, 1.f));
} else {
rotationMatrix.makeIdentityMatrix();
rotationMatrix.scale(((float)inputWidth / landmarkWidth), ((float)inputWidth / landmarkWidth), 1);
rotationMatrix = glm::mat4(1.f);
rotationMatrix = glm::scale(rotationMatrix, glm::vec3((float)inputWidth / landmarkWidth,
(float)inputWidth / landmarkWidth,
1.f));
}


Expand All @@ -62,4 +71,4 @@ class ofxFaceTracker2InputInfo {
cv::Size2i imageSize(inputWidth, inputHeight);
intrinsics.setup(projectionMat, imageSize);
}
};
};
8 changes: 4 additions & 4 deletions src/ofxFaceTracker2Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ ofxFaceTracker2Landmarks & ofxFaceTracker2Instance::getLandmarks(){
}

ofRectangle ofxFaceTracker2Instance::getBoundingBox() const {
ofVec3f tl = ofVec3f(rectangle.tl_corner().x(), rectangle.tl_corner().y(), 0) * info.rotationMatrix;
ofVec3f br = ofVec3f(rectangle.br_corner().x(), rectangle.br_corner().y(), 0) * info.rotationMatrix;
ofVec3f delta = br-tl;
glm::vec4 tl = info.rotationMatrix * glm::vec4(rectangle.tl_corner().x(), rectangle.tl_corner().y(), 0.f, 1.f);
glm::vec4 br = info.rotationMatrix * glm::vec4(rectangle.br_corner().x(), rectangle.br_corner().y(), 0.f, 1.f);
glm::vec4 delta = br-tl;
if(delta.x < 0){
tl.x += delta.x;
delta.x *= -1;
Expand All @@ -42,7 +42,7 @@ int ofxFaceTracker2Instance::getLabel(){
return label;
}

ofVec2f ofxFaceTracker2Instance::transformPosePosition(ofVec3f p){
glm::vec2 ofxFaceTracker2Instance::transformPosePosition(glm::vec3 p){
if(!poseCalculated){
calculatePoseMatrix();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ofxFaceTracker2Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ofxFaceTracker2Instance {
int getLabel();

/// Transforms a 3D point in pose coordinate space to 2D point in screen space
ofVec2f transformPosePosition(ofVec3f p);
glm::vec2 transformPosePosition(glm::vec3 p);

/// Load the pose matrix into OpenGL, this allows you to draw 3D objects in the heads coordinate system
void loadPoseMatrix();
Expand Down
24 changes: 11 additions & 13 deletions src/ofxFaceTracker2Landmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ ofxFaceTracker2Landmarks::ofxFaceTracker2Landmarks(dlib::full_object_detection s



ofVec2f ofxFaceTracker2Landmarks::getImagePoint(int i) const {
ofVec3f p = ofVec3f(shape.part(i).x(),
shape.part(i).y(), 0);
p = p * info.rotationMatrix;

return ofVec2f(p);
glm::vec2 ofxFaceTracker2Landmarks::getImagePoint(int i) const {
glm::vec4 p = glm::vec4(shape.part(i).x(), shape.part(i).y(), 0.f, 1.f);
p = info.rotationMatrix * p;

return glm::vec2(p.x, p.y);
}

vector<ofVec2f> ofxFaceTracker2Landmarks::getImagePoints() const {
vector<glm::vec2> ofxFaceTracker2Landmarks::getImagePoints() const {
int n = shape.num_parts();
vector<ofVec2f> imagePoints(n);
vector<glm::vec2> imagePoints(n);
for(int i = 0; i < n; i++) {
imagePoints[i] = getImagePoint(i);
}
Expand Down Expand Up @@ -75,7 +74,7 @@ ofPolyline ofxFaceTracker2Landmarks::getFeature(Feature feature, vector<T> point
for(int i = 0; i < indices.size(); i++) {
int cur = indices[i];
glm::vec2 pt = toGlm(points[cur]);
polyline.addVertex(pt.x, pt.y, 0);
polyline.addVertex({points[cur].x, points[cur].y, 0.f});
}
switch(feature) {
case LEFT_EYE:
Expand Down Expand Up @@ -133,10 +132,9 @@ ofMesh ofxFaceTracker2Landmarks::getMesh(vector<T> points) const {
glm::vec2 pt2V = ofxCv::toOf(pt2);
glm::vec2 pt3V = ofxCv::toOf(pt3);

mesh.addVertex(glm::vec3(pt1V.x, pt1V.y, 0));
mesh.addVertex(glm::vec3(pt2V.x, pt2V.y, 0));
mesh.addVertex(glm::vec3(pt3V.x, pt3V.y, 0));

mesh.addVertex({pt1.x, pt1.y, 0.f});
mesh.addVertex({pt2.x, pt2.y, 0.f});
mesh.addVertex({pt3.x, pt3.y, 0.f});
}
}
return mesh;
Expand Down
11 changes: 6 additions & 5 deletions src/ofxFaceTracker2Landmarks.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "ofConstants.h"
#include "ofGraphics.h"
//#include "ofConstants.h"
//#include "ofGraphics.h"
#include "ofMain.h"
#include "ofxCv.h"

#include "ofxFaceTracker2InputInfo.h"
Expand All @@ -25,11 +26,11 @@ class ofxFaceTracker2Landmarks {

/// Get specific 2D image point from the 68 landmarks coordinates
/// Coordinate is returned in input image size
ofVec2f getImagePoint(int i) const;
glm::vec2 getImagePoint(int i) const;

/// Get a list of 2D points with all 68 face landmarks found.
/// Coordinates are returned in input image size
std::vector<ofVec2f> getImagePoints() const;
std::vector<glm::vec2> getImagePoints() const;

/// Like getImagePoints, just returns the points as cv:Point2f
std::vector<cv::Point2f> getCvImagePoints() const;
Expand All @@ -51,4 +52,4 @@ class ofxFaceTracker2Landmarks {
template <class T>
ofPolyline getFeature(Feature feature, std::vector<T> points) const;

};
};

0 comments on commit 4319ac7

Please sign in to comment.