Created
May 31, 2017 02:23
-
-
Save kurnianggoro/6507f0fa451c14bc6d233c3febf98b7c to your computer and use it in GitHub Desktop.
Test file for the development of facelandmark API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <opencv2/opencv.hpp> | |
#include <opencv2/face.hpp> | |
#include <iostream> | |
using namespace std; | |
using namespace cv; | |
bool getFaces( const Mat image, std::vector<Rect> & faces ); | |
int main(int argc, char** argv ) | |
{ | |
if ( argc != 2 ) | |
{ | |
printf("usage: DisplayImage.out <Image_Path>\n"); | |
return -1; | |
} | |
Mat image; | |
image = imread( argv[1], 1 ); | |
if ( !image.data ) | |
{ | |
printf("No image data \n"); | |
return -1; | |
} | |
/*the user can choose one of the following*/ | |
// Ptr<FacemarkAAM> facemark = FacemarkAAM::create(); | |
// Ptr<Facemark> facemark = Facemark::create("AAM"); | |
Ptr<Facemark> facemark = FacemarkAAM::create(); | |
std::vector<Rect> faces; | |
std::vector<Point2f> landmarks; | |
std::vector<std::vector<Point2f> > facesLandmarks; | |
/*process using custom face detector*/ | |
// facemark->setFaceDetector(getFaces); | |
// facemark->getFaces(image,faces); | |
// facemark->process(image, faces, facesLandmarks); | |
/*process using default face detector (haar)*/ | |
facemark->process(image, faces, facesLandmarks,"haarcascade_frontalface_alt.xml"); | |
//facemark->getFacesHaar(image, faces, "haarcascade_frontalface_alt.xml"); | |
/*test the detection*/ | |
facemark->detect(image,landmarks); | |
facemark->detect(image(Rect(10,10,50,50)),landmarks); | |
/*test the training*/ | |
facemark->training("hello.text","test.text"); | |
/*print the detected landmarks*/ | |
for(int i=0;i<landmarks.size();i++){ | |
cout<<landmarks[i].x<<" "<<landmarks[i].y<<endl; | |
} | |
cout<<faces.size()<<" "<<landmarks.size()<<endl; | |
/*draw the result*/ | |
for(int i = 0;i <faces.size(); i++){ | |
rectangle(image, faces[i], Scalar(255,0,0)); | |
} | |
// | |
// namedWindow("Display Image", WINDOW_AUTOSIZE ); | |
// imshow("Display Image", image); | |
// waitKey(0); | |
return 0; | |
} | |
bool getFaces( const Mat image, std::vector<Rect> & faces){ | |
Mat gray; | |
printf("inside custom function\n"); | |
String face_cascade_name = "haarcascade_frontalface_alt.xml"; | |
CascadeClassifier face_cascade; | |
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face_cascade\n"); return false; }; | |
cvtColor( image, gray, CV_BGR2GRAY ); | |
equalizeHist( gray, gray ); | |
face_cascade.detectMultiScale( gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) ); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment