20 Simple python demo script of tesseract-ocr 3.02 c-api
29 filename =
"../phototest.tif"
30 libpath =
"/usr/local/lib64/"
31 libpath_w =
"../vs2008/DLL_Release/"
32 TESSDATA_PREFIX = os.environ.get(
'TESSDATA_PREFIX')
33 if not TESSDATA_PREFIX:
34 TESSDATA_PREFIX =
"../"
36 if sys.platform ==
"win32":
37 libname = libpath_w +
"libtesseract302.dll"
38 libname_alt =
"libtesseract302.dll"
39 os.environ[
"PATH"] += os.pathsep + libpath_w
41 libname = libpath +
"libtesseract.so.3.0.2"
42 libname_alt =
"libtesseract.so.3"
45 tesseract = ctypes.cdll.LoadLibrary(libname)
48 tesseract = ctypes.cdll.LoadLibrary(libname_alt)
49 except WindowsError, err:
50 print(
"Trying to load '%s'..." % libname)
51 print(
"Trying to load '%s'..." % libname_alt)
55 tesseract.TessVersion.restype = ctypes.c_char_p
56 tesseract_version = tesseract.TessVersion()[:4]
60 if float(tesseract_version) < 3.02:
61 print(
"Found tesseract-ocr library version %s." % tesseract_version)
62 print(
"C-API is present only in version 3.02!")
65 api = tesseract.TessBaseAPICreate()
66 rc = tesseract.TessBaseAPIInit3(api, TESSDATA_PREFIX, lang);
68 tesseract.TessBaseAPIDelete(api)
69 print(
"Could not initialize tesseract.\n")
72 text_out = tesseract.TessBaseAPIProcessPages(api, filename,
None , 0);
73 result_text = ctypes.string_at(text_out)