Tesseract TESSDATA_PREFIX Environment Variable

Per the Tesseract.Init() function with the following parameters;

public void Init(
string dataPath = null,
string language = null,
OcrEngineMode oem = OcrEngineMode.OEM_DEFAULT,
string[] configs = null,
string[] varsVec = null,
string[] varsValues = null,
bool setOnlyNonDebugParams = false,
bool checkLanguage = true

I was trying to change the dataPath but despite trying multiple variations, I was unable to change it and it kept defaulting to the Tesseract installation directory “C:Program FilesTesseract-OCR”.

The value is actually set as an environment variable TESSDATA_PREFIX. So what I did was set it within my program;

string ev = Environment.GetEnvironmentVariable("TESSDATA_PREFIX");
string dir = Directory.GetCurrentDirectory() + @"tessdata";
Environment.SetEnvironmentVariable("TESSDATA_PREFIX", dir, EnvironmentVariableTarget.Process);

EnvironmentVariableTarget.Process seem to work fine for me but you can try switching to Machine or User if it doesn’t work.