I have 2 solutions using tesseract OCR, one is a console app and it works, code below ...
using Patagames.Ocr;
static void Main(string[] args)
{
OcrApi.LicenseKey = "<my key>";
using (var api = OcrApi.Create())
{
api.Init(Patagames.Ocr.Enums.Languages.English);
using (var bmp = Bitmap.FromFile(@"C:\CodedUITest\Screenshots\Capture.bmp") as Bitmap)
{
string plainText = api.GetTextFromImage(bmp);
}
}
}
After having success with my console app, I have done the same thing in a CodedUI test project (basically like unit testing but where tests can be recorded).
[TestMethod()]
public void CodedUI_Assert_StateString_Active()
{
String filename = "my_screen_dump";
OcrApi.LicenseKey = "<my key here>";
OcrApi.PathToEngine = @"C:\Users\<user>\Documents\CodedUITest_System\CodedUITesting\tesseract.dll";
using (var api = OcrApi.Create())
{
api.Init(Patagames.Ocr.Enums.Languages.English);
using (var bmp = Bitmap.FromFile(@"C:\CodedUITest\Screenshots\" + filename + ".bmp") as Bitmap)
{
string plainText = api.GetTextFromImage(bmp);
}
}
}
I get the error ...
Result Message:
Test method CodedUITesting.Common_Tests_Suite.CodedUI_Assert_StateString_Active threw exception:
System.Exception: Unable to load DLL 'tesseract.dll': The specified module could not be found. Please make sure that you copy it to the application folder. Alternatively, you can specify the full path to the tesseract.dll file using specificPath parameter in the TessBaseAPICreate method
As you can see, I have specified the OcrApi.PathToEngine and I have checked it by copying the folder to explorer and pasting the folder name in and it does find the folder and tesseract.dll is there.
Any ideas why this won't work in my testing solution? I think I know what I'm doing because I got it to work before or is the problem that I have 2 solutions and tesseract is somehow using something from my first solution in my second solution that doesn't work?
Any help appreciated.
Edited by user Friday, April 28, 2017 8:27:20 AM(UTC)
| Reason: Not specified