next up previous contents index
Next: Serious tweaking Up: Frontend API Previous: Closing modules   Contents   Index

A simple example

Ok, time to do something concrete.

Usually examples are neat little programs, heavily commented, that do something completely useless. Since this is a tradition, I was unable to refrain using it. Unfortunadly GOCR can't do ``Hello World'', and so I had to imagine something equally uninteresting, and I used the filter example I just told you.

/* filter.c

 * A simple program, that applies a filter to a

 * image, and outputs the image.

 */

 

#include <gocr.h>

int main(int argc, char **argv) { 

/* Initialize the library */

if ( gocr_init(argc, argv) == -1 )

exit(1);

/* Set output to zero */

if ( gocr_setAttribute(VERBOSE, 0) == -1 )

exit(1); 

/* Load a shared object file */

if ( gocr_moduleLoad(''modulename.so'') == -1 )

exit(1);

/* Load a module function that cleans dust */

if ( gocr_functionAppend(imageFilter, ''cleanDust'', NULL) != -1 ) 

exit(1);

/* Load a module function that outputs an image */

if ( gocr_functionAppend(outputFormatter, ''imageOutput'',  
                   ''output.jpg'') != -1 ) 

exit(1);

/* Load the image */

if ( gocr_imageLoad(''image.jpg'', (void *)GOCR_NONE) )

exit(1);

/* Run all modules. */

gocr_runAllModules();

/* Ok, say good bye */

gocr_finalize();

}

The usual comments, now. Notice that two module functions were loaded. The first cleans `dust' of the image, i.e., those nasty pixels that are black in what should be a perfectly white background. The second module outputs the image after the cleaning. Notice how this hypothetical module function takes as argument the name of the output file.

When you call gocr_finalize(), it takes care of unloading shared objects, deleting module functions, closing the image, etc. Don't worry with hundreds or close()s, free()s, etc.


next up previous contents index
Next: Serious tweaking Up: Frontend API Previous: Closing modules   Contents   Index
root 2002-02-17