ROC SDK  2.4.0
Scalable Face Recognition Software
roc_example_verify_embedded.c

Source code for examples/roc_example_verify_embedded.c.

/*
* This example application takes as input two PGM image paths (presumed to have
* one face in each image) and outputs the similarity between the face in each
* image using the Embedded API. Similarity values toward one indicate the two
* faces appear to be the same person. Similarity values toward zero indicate
* the two faces appear to be different people. See the API documentation for
* details regarding how similarity scores are normalized.
*
* To compile this example on OS X / Linux (bash):
*
* $ gcc -o roc-example-verify-embedded roc_example_verify_embedded.c -I ../include/ -L ../lib/ -Wl,-rpath,'$ORIGIN/../lib:../lib' -lroc_embedded
*
* To compile this example on Windows (Visual Studio Command Prompt):
*
* $ cl roc_example_verify_embedded.c /I ../include/ ../lib/roc.lib /Feroc-example-verify-embedded.exe
*
* To run this application using two of the example images:
*
* $ ./roc-example-verify-embedded ../data/josh_1.ppm ../data/josh_2.ppm
*/
#include <stdio.h>
#include <stdlib.h>
#include "roc-embedded.h"
int main(int argc, char *argv[])
{
roc_image color[2];
roc_image gray[2];
uint8_t templates[2 * ROC_FAST_FV_SIZE];
roc_similarity similarity;
size_t adaptive_minimum_size, n;
roc_detection detection;
roc_landmark *landmarks;
roc_landmark right_eye, left_eye, chin;
float quality;
int i;
if (argc != 3)
roc_ensure("Expected two image path arguments:\n"
" $ roc-example-verify-embedded path/to/image_a.ppm path/to/image_b.ppm");
// Initialize SDK
// Open both images
for (i=0; i<2; i++) {
roc_ensure(roc_read_ppm(argv[i+1], &color[i]));
roc_ensure(roc_bgr2gray(color[i], &gray[i]));
}
// Find and represent one face in each image
for (i=0; i<2; i++) {
roc_ensure(roc_adaptive_minimum_size(color[i].width, color[i].height, ROC_SUGGESTED_RELATIVE_MIN_SIZE, ROC_SUGGESTED_ABSOLUTE_MIN_SIZE, &adaptive_minimum_size));
if (n != 1)
roc_ensure("Failed to detect a face!");
landmarks = (roc_landmark*) malloc(roc_num_landmarks_for_pose(detection.pose) * sizeof(roc_landmark));
roc_ensure(roc_embedded_error_to_string(roc_embedded_landmark_face(gray[i], &detection, &landmarks[0], &right_eye, &left_eye, &chin, NULL, NULL)));
free(landmarks);
float age;
float analytics_spoof;
roc_ensure(roc_embedded_error_to_string(roc_embedded_represent_face(color[i], detection, right_eye, left_eye, chin, &templates[i*ROC_FAST_FV_SIZE], &quality, &age, NULL, &gender, NULL, NULL, NULL, NULL, NULL, &analytics_spoof, NULL)));
float spoof;
roc_ensure(roc_embedded_error_to_string(roc_embedded_liveness(gray[i], right_eye, left_eye, chin, &spoof)));
spoof = (spoof + analytics_spoof) / 2.f; // We recommend averaging these two responses for the highest accuracy
printf("Face X: %d Y: %d Width: %d Height: %d Quality: %.3f Age: %d Gender: %c Spoof: %c\n", (int) detection.x, (int) detection.y, (int) detection.width, (int) detection.height, quality, (int) age, (gender.female > gender.male ? 'F' : 'M'), (spoof > ROC_CONVENIENT_SPOOF_THRESHOLD ? 'Y' : 'N'));
}
// Compare faces
printf("Similarity: %.3f\n", similarity);
// Cleanup
for (i=0; i<2; i++) {
}
return EXIT_SUCCESS;
}