stasm_opencv_example.cpp
// stasm_opencv_example.cpp: locate facial landmarks using the Stasm DLL
#include "stdio.h"
#include "cv.h"
#include "highgui.h"
#include "../stasm/stasm_dll.hpp" // defines AsmSearchDll
int main (void)
{
const char *image_name = "../data/test-image.jpg";
IplImage *img = cvLoadImage(image_name, CV_LOAD_IMAGE_COLOR);
if (img == NULL) {
printf("Error: Cannot open %s\n", image_name);
return -1;
}
// locate the facial landmarks with stasm
int nlandmarks;
int landmarks[500]; // space for x,y coords of up to 250 landmarks
AsmSearchDll(&nlandmarks, landmarks,
image_name, img->imageData, img->width, img->height,
1 /* is_color */, NULL /* conf_file0 */, NULL /* conf_file1 */);
if (nlandmarks == 0) {
printf("\nError: Cannot locate landmarks in %s\n", image_name);
return -1;
}
#if 0 // print the landmarks if you want
printf("landmarks:\n");
for (int i = 0; i < nlandmarks; i++)
printf("%3d: %4d %4d\n", i, landmarks[2 * i], landmarks[2 * i + 1]);
#endif
// draw the landmarks on the image
int *p = landmarks;
cvPolyLine(img, (CvPoint **)&p, &nlandmarks, 1, 1, CV_RGB(255,0,0));
// show the image with the landmarks
cvShowImage("stasm example", img);
cvWaitKey(0);
cvDestroyWindow("stasm example");
cvReleaseImage(&img);
return 0;
}
Back to Stasm homepage