ROC SDK  2.4.0
Scalable Face Recognition Software
roc_example_flatten.c

Source code for examples/roc_example_flatten.c.

/*
* This example application takes as input an image path (presumed to have at
* least one face in it), constructs a template, and then illustrates how to
* flatten/unflatten the template to/from a buffer.
*
* To compile this example on OS X / Linux (bash):
*
* $ gcc -o roc-example-flatten roc_example_flatten.c -I ../include/ -L ../lib/ -Wl,-rpath,'$ORIGIN/../lib:../lib' -lroc
*
* To compile this example on Windows (Visual Studio Command Prompt):
*
* $ cl roc_example_flatten.c /I ../include/ ../lib/roc.lib /Feroc-example-flatten.exe
*
* To run this application using an example image:
*
* $ ./roc-example-flatten ../data/josh_1.jpg
*/
#include <stdio.h>
#include <stdlib.h>
#include "roc.h"
int main(int argc, char *argv[])
{
roc_image image, face_thumbnail;
roc_template template_src, template_dst;
size_t buffer_size;
uint8_t *buffer;
if (argc != 2)
roc_ensure("Expected one image path argument:\n"
" $ roc-example-flatten path/to/image_a.jpg");
// Initialize SDK
roc_ensure(roc_initialize(NULL, NULL));
// Open the image
roc_ensure(roc_read_image(argv[1], ROC_BGR24, &image));
// Find and represent one face in the image
if (!template_src.algorithm_id) {
printf("Failed to detect face in image: %s\n", argv[1]);
return EXIT_FAILURE;
}
// Flatten the template to a buffer
roc_ensure(roc_flattened_bytes(template_src, &buffer_size));
buffer = (uint8_t*) malloc(buffer_size);
roc_ensure(roc_flatten(template_src, buffer));
printf("Flattened size: %zu bytes\n", buffer_size);
// Unflatten the template from a buffer
roc_ensure(roc_unflatten(buffer, &template_dst));
// Decode the thumbnail (if needed)
roc_ensure(roc_decode_image(template_dst.tn, template_dst.tn_size, ROC_BGR24, &face_thumbnail));
// Cleanup
roc_ensure(roc_free_template(&template_src));
roc_ensure(roc_free_template(&template_dst));
roc_ensure(roc_free_image(face_thumbnail));
free(buffer);
return EXIT_SUCCESS;
}