ROC SDK  2.4.0
Scalable Face Recognition Software
roc_example_ocr.c

Source code for examples/roc_example_ocr.c.

/*
* This example application takes a command line input of an image path
* and outputs the optical character recognition (OCR) results.
*
* To compile this example on OS X / Linux (bash):
*
* $ gcc -o roc-example-ocr roc_example_ocr.c -I ../include/ -L ../lib/ -Wl,-rpath,'$ORIGIN/../lib:../lib' -lroc
*
* To compile this example on Windows (Visual Studio Command Prompt):
*
* $ cl roc-example-ocr.c /TP /I ../include/ ../lib/roc.lib /Feroc-example-ocr.exe
*
* To run this application using an example image:
*
* Linux
* $ ./roc-example-ocr ../lib ../data/right_lane_ends.png
*
* Windows
* $ .\roc-example-ocr.exe . ..\data\right_lane_ends.png
*/
#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 != 3)
roc_ensure("Expected two arguments:\n"
#ifdef _WIN32
" > roc-example-ocr.exe path\\to\\rocsdk\\bin path/to/image.jpg"
#else // !_WIN32
" $ roc-example-ocr path/to/rocsdk/lib path/to/image.jpg"
#endif // _WIN32
);
// Initialize SDK
roc_ensure(roc_initialize(NULL, NULL));
// Detect up to ten words in the image
roc_ensure(roc_read_image(argv[2], ROC_BGR24, &image));
for (i=0; i<10; i++) {
if (!templates[i].algorithm_id) {
if (i == 0)
puts("Failed to detect text in image!");
break;
}
roc_string text;
roc_ensure(roc_get_metadata(templates[i], "Text", &text));
printf("%s Confidence = %f Center = (%d, %d) Size = (%d, %d)\n", text, 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;
}