logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Paul Rayman  
#1 Posted : Tuesday, January 5, 2016 6:58:42 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,103

Thanks: 7 times
Was thanked: 128 time(s) in 125 post(s)
Question:
I having issues getting the Tesseract.Net library to locate the tesseract.dll in an MVC web project.
I've followed your installation instructions (marking both x86 and x64 versions as Copy to Output Directory=Copy always) and it works fine in a class library and WinForms application. The web site cannot seem to find it though. I've verified the tesseract.dll is copied to the bin folder along with the Patagames.Ocr.dll and have even tried adding tesseract.dll manually in different spots. Do you have any other suggestions?

Answer:
This is happens because the Web application is running in a IIS's working directory, unlike the classical apps. In consequence of that, the LoadLibrary function can't find the tesseract.dll during initialization process.
You can specify the full path to tesseract.dll through PathToEngine property of OcrApi() class to solve this problem.

Code:

public void InitOcr()
{
    OcrApi.PathToEngine = @"c:\YourApp\tesseract.dll";
    using (var api = OcrApi.Create())
    {
        api.Init();
    }
}
emil10  
#2 Posted : Thursday, June 16, 2016 5:00:05 PM(UTC)
emil10

Rank: Newbie

Groups: Registered
Joined: 6/16/2016(UTC)
Posts: 2

Hello guys,

actually I have the same problem described in the previous post.
I also take care about the given hints above respectively the working instruction.
But however, there is still the Problem "An unhandled exception of type 'System.Exception' occurred in Patagames.Ocr.dll".

2nd question: I have implemented this in an Console Application. Is this possible? Or is this maybe the Problem?

Here is my Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Patagames.Ocr;
using Patagames.Ocr.Enums;
using System.Drawing;


namespace tesTest
{
class Program
{
public static object Bitmap { get; private set; }

static void Main(string[] args)
{
OcrApi.PathToEngine = @"C:........\x64\tesseract.dll";
using (var api = OcrApi.Create())
{
api.Init(Languages.English);

using (var bmp = Image.FromFile(@"C:.....jpg", true) as Bitmap)
{
string plainText = api.GetTextFromImage(bmp);
}
}
}
}

}



Thank for you help.

Greetings
Paul Rayman  
#3 Posted : Friday, June 17, 2016 8:36:52 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,103

Thanks: 7 times
Was thanked: 128 time(s) in 125 post(s)
Please check what you are using a 64-bit application pool / console application.
Also please provide stack trace.
Thanks.
emil10  
#4 Posted : Sunday, June 19, 2016 4:43:18 PM(UTC)
emil10

Rank: Newbie

Groups: Registered
Joined: 6/16/2016(UTC)
Posts: 2

Hello Paul,

actually, I do not know, what you want with the stack trace exactly? Could you explain this?

The error occurred while calling "using (var api = OcrApi.Create())"

The error is: "An unhandled exception of type 'System.Exception' occurred in Patagames.Ocr.dll
Additional information: 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"

The .dll is for sure in the project. Maybe a solution would be do put the complete path inside. How would that work? Can you give an example? I can’t find method descriptions regarding the Patagames.Ocr.dll.


Greetings
Guest  
#5 Posted : Sunday, June 19, 2016 7:13:54 PM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 163

Was thanked: 5 time(s) in 5 post(s)
Are you reading this article?
https://tesseract.pataga...6-b6e9-9df777c4678c.htm#!

Also, you can use the Nuget Package Manager in Visual Studio to install the Tesseract.Net SDK.
In this case, run the following command in the Package Manager Console
Quote:
PM> Install-Package Tesseract.Net.SDK


It will download package and install the SDK into your project in appropriate way.
Guest  
#6 Posted : Friday, April 28, 2017 6:53:19 AM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 163

Was thanked: 5 time(s) in 5 post(s)
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

Guest  
#7 Posted : Thursday, May 4, 2017 6:48:24 AM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 163

Was thanked: 5 time(s) in 5 post(s)
try copy tessdata x64 x86 folders to (your project path)/bin/Debug. Probably you need only to copy x64 but i copied all.
Paul Rayman  
#8 Posted : Wednesday, May 10, 2017 8:43:59 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,103

Thanks: 7 times
Was thanked: 128 time(s) in 125 post(s)
Do you setup library as described here?
https://tesseract.pataga...e6-b6e9-9df777c4678c.htm
somchai.l  
#9 Posted : Monday, August 9, 2021 7:14:58 AM(UTC)
somchai.l

Rank: Newbie

Groups: Registered
Joined: 8/9/2021(UTC)
Posts: 2
Thailand
Location: Songkhla

Hi All,

I got the same problem with the latest version 1.20.342. Cannot run on UnitTest. Is there any resolve?


Originally Posted by: Guest Go to Quoted Post
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 Monday, August 9, 2021 7:21:57 AM(UTC)  | Reason: add version number

somchai.l  
#10 Posted : Monday, August 9, 2021 8:49:02 AM(UTC)
somchai.l

Rank: Newbie

Groups: Registered
Joined: 8/9/2021(UTC)
Posts: 2
Thailand
Location: Songkhla

Hi All,

My previous post problem on Tesseract.Net SDK version 1.20.342.
I test on the Unit Test Project (.NET Framework) base on .NET Framework 4.8 and has error as follow:
Quote:
Error: Unable to find an entry point named 'TessBaseAPICreate' in DLL 'tesseract.dll'.

Setting OcrApi.PathToEngine also does not work, same error.

However, I try to test again with the same code on the MSTest Test Project base on .NET Core 3.1 (Long-Term Support).
It work as run on console application (No need to set OcrApi.PathToEngine).

I don'nt know, why. I need to test OCR with other test on the Unit Test Project. Can anyone guide me, please.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.