add scaling
This commit is contained in:
parent
72fc3d5e2c
commit
43de93eb3a
|
@ -175,11 +175,11 @@ void initModel () {
|
|||
|
||||
}
|
||||
|
||||
void updateModel(glm::vec2 headPos, glm::vec2 facePos, bool mouthOpen) {
|
||||
void updateModel(glm::vec2 headPos, glm::vec2 facePos, float scale, bool mouthOpen) {
|
||||
//calculate transforms
|
||||
parts[0].setPosition(headPos);
|
||||
parts[1].setPosition(facePos);
|
||||
parts[2].setPosition(facePos);
|
||||
parts[0].setTransform(headPos, scale);
|
||||
parts[1].setTransform(facePos, scale);
|
||||
parts[2].setTransform(facePos, scale);
|
||||
|
||||
//set mouth texture to open or closed
|
||||
parts[2].selectTexture(mouthOpen ? 1 : 0);
|
||||
|
|
|
@ -16,6 +16,6 @@ void initShader();
|
|||
|
||||
void printShaderCompileLog(GLuint shader);
|
||||
|
||||
void updateModel(glm::vec2 headPos, glm::vec2 facePos, bool mouthOpen);
|
||||
void updateModel(glm::vec2 headPos, glm::vec2 facePos, float scale, bool mouthOpen);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
int main () {
|
||||
initGraphics();
|
||||
|
||||
cv::CascadeClassifier faceDetector ("lbpcascade_frontalface_improved.xml");
|
||||
//TODO: switch to DNN face detection
|
||||
cv::CascadeClassifier faceDetector ("haarcascade_frontalface_alt2.xml");
|
||||
|
||||
cv::Ptr<cv::face::Facemark> facemark = cv::face::FacemarkLBF::create();
|
||||
facemark->loadModel ("lbfmodel.yaml");
|
||||
|
@ -57,6 +58,7 @@ int main () {
|
|||
cv::circle (frame, landmarks[biggestFace][62], 3, cv::Scalar (0, 255, 0));
|
||||
|
||||
//send control information to graphics
|
||||
float faceSize = landmarks[biggestFace][14].x - landmarks[biggestFace][2].x;
|
||||
updateModel(glm::vec2(
|
||||
(landmarks[biggestFace][2].x + landmarks[biggestFace][14].x) / 2
|
||||
* 2 / (float)frame.cols - 1,
|
||||
|
@ -67,7 +69,8 @@ int main () {
|
|||
landmarks[biggestFace][30].x * 2 / (float)frame.cols - 1,
|
||||
landmarks[biggestFace][30].y * 2 / (float)frame.rows - 1
|
||||
),
|
||||
landmarks[biggestFace][66].y - landmarks[biggestFace][62].y > 5);
|
||||
faceSize * 6 / (float)frame.cols,
|
||||
(landmarks[biggestFace][66].y - landmarks[biggestFace][62].y) / faceSize > 0.04f);
|
||||
}
|
||||
|
||||
graphicsFrame ();
|
||||
|
|
|
@ -29,8 +29,9 @@ void ModelPart::bindAndDraw() {
|
|||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
void ModelPart::setPosition(glm::vec2 position) {
|
||||
void ModelPart::setTransform(glm::vec2 position, float scale) {
|
||||
transMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(position.x, -position.y, 0.0f));
|
||||
transMatrix = glm::scale(transMatrix, glm::vec3(scale, scale, scale));
|
||||
}
|
||||
|
||||
void ModelPart::addTexture(const char* texPath, size_t slot) {
|
||||
|
|
|
@ -20,7 +20,7 @@ class ModelPart {
|
|||
|
||||
void bindAndDraw();
|
||||
|
||||
void setPosition(glm::vec2 position);
|
||||
void setTransform(glm::vec2 position, float scale);
|
||||
|
||||
void addTexture(const char* texPath, size_t slot);
|
||||
|
||||
|
|
Loading…
Reference in a new issue