ROC SDK  2.4.0
Scalable Face Recognition Software
roc_example_object_detection.c

Source code for examples/roc_example_object_detection.c.

/*
* This example application takes a command line input of an image path
* and an object to detect and outputs the detected object bounding boxes
* with the confidence that the bounding box is a correct prediction.
*
* To compile this example on OS X / Linux (bash):
*
* $ gcc -o roc-example-object-detection roc_example_object_detection.c -I ../include/ -L ../lib/ -Wl,-rpath,'$ORIGIN/../lib:../lib' -lroc
*
* To compile this example on Windows (Visual Studio Command Prompt):
*
* $ cl roc-example-object-detection.c /TP /I ../include/ ../lib/roc.lib /Feroc-example-object-detection.exe
*
* To run this application using an example image:
*
* Linux
* $ ./roc-example-object-detection ../lib ../data/plane.jpg airplane,bicycle,boat,bus,car,gun,license_plate,military_vehicle,motorcycle,person,truck
*
* Windows
* $ .\roc-example-object-detection.exe . ..\data\plane.jpg airplane,bicycle,boat,bus,car,gun,license_plate,military_vehicle,motorcycle,person,truck
*/
#include <stdio.h>
#include <stdlib.h>
#include "roc.h"
int main(int argc, char *argv[])
{
roc_image image;
roc_template templates[10];
size_t adaptive_minimum_size;
int i;
if (argc != 4)
roc_ensure("Expected three arguments:\n"
#ifdef _WIN32
" > roc-example-object-detection.exe path\\to\\rocsdk\\bin path/to/image.jpg airplane,bicycle,boat,bus,car,gun,license_plate,military_vehicle,motorcycle,person,truck"
#else // !_WIN32
" $ roc-example-object-detection path/to/rocsdk/lib path/to/image.jpg airplane,bicycle,boat,bus,car,gun,license_plate,military_vehicle,motorcycle,person,truck"
#endif // _WIN32
);
// Initialize SDK
roc_ensure(roc_initialize(NULL, NULL));
// Set the objects of focus
const char *objects = argv[3];
if (strstr(objects, "airplane")) algorithm_id |= ROC_AIRPLANE_DETECTION;
if (strstr(objects, "bicycle")) algorithm_id |= ROC_BICYCLE_DETECTION;
if (strstr(objects, "boat")) algorithm_id |= ROC_BOAT_DETECTION;
if (strstr(objects, "bus")) algorithm_id |= ROC_BUS_DETECTION;
if (strstr(objects, "car")) algorithm_id |= ROC_CAR_DETECTION;
if (strstr(objects, "gun")) algorithm_id |= ROC_GUN_DETECTION;
if (strstr(objects, "license_plate")) algorithm_id |= ROC_LICENSE_PLATE_DETECTION;
if (strstr(objects, "military_vehicle")) algorithm_id |= ROC_MILITARY_VEHICLE_DETECTION;
if (strstr(objects, "motorcycle")) algorithm_id |= ROC_MOTORCYCLE_DETECTION;
if (strstr(objects, "person")) algorithm_id |= ROC_PERSON_DETECTION;
if (strstr(objects, "truck")) algorithm_id |= ROC_TRUCK_DETECTION;
if (strstr(objects, "all") || strstr(objects, "ALL")) algorithm_id |= ROC_ALL_OBJECT_DETECTION;
if (!algorithm_id)
roc_ensure("Unrecognized object type!");
// Detect up to ten objects in the image
roc_ensure(roc_read_image(argv[2], ROC_BGR24, &image));
roc_ensure(roc_represent(image, algorithm_id, adaptive_minimum_size, 10, ROC_OBJECT_SUGGESTED_FALSE_DETECTION_RATE, ROC_NO_MIN_QUALITY, &templates[0]));
for (i=0; i<10; i++) {
if (!templates[i].algorithm_id) {
if (i == 0)
puts("Failed to detect objects in image!");
break;
}
roc_string label;
roc_ensure(roc_get_metadata(templates[i], "Label", &label));
printf("%s Confidence = %f Center = (%d, %d) Size = (%d, %d)\n", label, (double)templates[i].detection.confidence, (int)templates[i].detection.x, (int)templates[i].detection.y, (int)templates[i].detection.width, (int)templates[i].detection.height);
roc_ensure(roc_free_template(&templates[i]));
}
// Cleanup
return EXIT_SUCCESS;
}