How to force tesseract not to use TESSDATA_PREFIX
22,385
This seems helpful: Tesseract - change language file location
From the answer in that thread, it appears to be the case that tesseract looks for the environment variable, but if it is not set, assumes a fixed location.
The easiest way to fix this would be to run "cmd", then do:
c:\Users\alex> set TESSDATA_PREFIX="C:/Projects/project/Release/tessdata"
c:\Users\alex> cd MyOCRProgDir
c:\Users\alex\MyOCRProgDir> MyProg
Hope that helps!
Author by
Alex Hoppus
I'am involved/interested in micro-kernel secure operating system development.
Updated on February 25, 2020Comments
-
Alex Hoppus over 4 years
I had tesseract installed on my pc, and it defined TESSDATA_PREFIX enviroment variable. After complete uninstallation of tesseract, i try to use tesseract API in this way:
if (myOCR->Init("C:/Projects/project/Release/tessdata/", "rus")) { fprintf(stderr, "Could not initialize tesseract.\n"); exit(1); }
and recieve
Error opening data file C:\Program Files (x86)\Tesseract-OCR\tessdata/rus.traine ddata Please make sure the TESSDATA_PREFIX environment variable is set to the parent d irectory of your "tessdata" directory. Failed loading language 'rus' Tesseract couldn't load any languages! Could not initialize tesseract.
typing set TESSDATA_PREFIX in cmd gives me that there is no such variable. But tesseract remembers it (don't know how). So how can i force tesseract to search traindata in concrete folder? Thanks
-
Alex Hoppus over 11 yearsi don't want to use this, because it wouldn't work on another pc
-
Alex Hoppus over 11 years1.) i will have no opportunity to set env variable mannualy on another pc 2.) it is not convinient 3) even after reseting this variable, i dont know why, but it searches in C:\Progamfiles (x86)\tesseract-ocr ...
-
Alex Hoppus over 11 yearsi made full reg scan and deleted all when i met TESSDATA_PREFIX, but it searches in old directory
-
Rahul Banerjee over 11 yearsFirstly, you will put these commands into a "Batch file" (a file with .bat extension) and when you copy your program onto the other computer(s), you'll also copy this .bat file onto their Desktop, making it a "shortcut" that they double-click to launch your OCR program. Secondly, since this did not work, is there any chance you could build Tesseract from source? I know it sounds involved, but if you can do that, you may be able to use the advice on the thread I pointed you to.
-
Alex Hoppus over 11 yearsin this case you can use putenv right from the code rather than bat file. Anyway reboot solves this tricky problem with enviroment variable previously defined by tesseract exe. Thanks
-
Rahul Banerjee over 11 yearsAll it needed was a reboot? Hah! Glad you were able to figure it out.