I am trying to use Tesseract
OCR Software in Linqpad
. I made the following steps:
1) I installed Tesseract 3.02 by using the installer in
https://code.google.com/p/tesseract-ocr/downloads/detail?name=tesseract-ocr-setup-3.02.02.exe&
2) I added in Linqpad a reference to Tesseract through nuget, precisely the following package: a .Net wrapper for tesseract-ocr
3) I added in the PATH variable the path of Tesseract binary that contains also two native dll library
4) I installed Visual Studio x86 & x64 runtime as suggested in
https://github.com/charlesw/tesseract/wiki/Error-2
However, when I try to use tesseract
in Linqpad
I get the following error:
DllNotFoundException: Failed to find library "liblept168.dll" for platform x86
I suppose that the Problem is related to how use native dll
in Linqpad.
How can I fix this Problem?
The incompatibility between LINQpad and the Tesseract nuget package is due to the way the InteropDotNet
library loads native assemblies at run-time.
You can add the following method to your LINQpad query that has the Tesseract nuget package added, and it should allow the InteropDotNet library to find the native assemblies it needs.
static void CopyTessLibraries(string tessVersion, string platform)
{
var destFolder = Path.Combine(Environment.CurrentDirectory,platform);
Directory.CreateDirectory(destFolder);
var tessNugetFolder = new LINQPad.ObjectModel.NuGetReference("Tesseract")
.GetPackageFolders()
.First(folderName => folderName.Contains($@"Tesseract\{tessVersion}"));
var platformFiles = Directory.GetFiles(Path.Combine(tessNugetFolder,platform));
foreach (var file in platformFiles)
{
var fileInfo = new FileInfo(file);
var destFile = Path.Combine(destFolder, fileInfo.Name);
if (!File.Exists(destFile))
{
fileInfo.CopyTo(destFile, true);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With