Open Hakxsorus opened 8 months ago
I will not close this issue since the error persists. However, for anyone experiencing similar problems, I have found a workaround.
This is simply done by programmatically creating the tessdata
directory and downloading eng.traineddata
to a known location in the user's file system on app initialisation.
Note that this is for a production environment and only needs to be done once. Consider disabling this check for local debugging.
Create the tessdata
directory there.
private const string AppDataFolderName = "YourAppName";
private const string TessdataFolderName = "tessdata";
/// <summary>
/// Gets the path to Blitz's directory in the AppData folder.
/// </summary>
/// <returns>The application directory path.</returns>
public string GetAppDataFolderPath()
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
return Path.Combine(appDataPath, AppDataFolderName);
}
/// <summary>
/// Gets the path to Blitz's tessdata directory.
/// </summary>
/// <returns>The tessdata path.</returns>
public string GetTessdataFolderPath()
{
return Path.Combine(GetAppDataFolderPath(), TessdataFolderName);
}
Make sure to check the directory exists there before downloading.
/// <summary>
/// Downloads the Tesseract English language model to the tessdata folder.
/// </summary>
/// <param name="tessdataFolderPath">The path to the tessdata folder.</param>
private static async Task DownloadTrainedData(string tessdataFolderPath)
{
const string tessdataEngFileName = "eng.traineddata";
const string tessdataEngUrl = "https://github.com/tesseract-ocr/tessdata_fast/raw/main/eng.traineddata";
using var client = new HttpClient();
await using var stream = await client.GetStreamAsync(tessdataEngUrl);
await using var fs = new FileStream(Path.Combine(tessdataFolderPath, tessdataEngFileName),
FileMode.OpenOrCreate);
await stream.CopyToAsync(fs);
}
using var engine = new TesseractEngine(tessdataFolderPath, "eng", EngineMode.Default);
Error
But I do have the environment variable set to the
tessdata
folder witheng.traineddaata
.It only works if I call it from my project root directory where
tessdata
folder is published into.Works
Does Not Work