Tesseract OCR getting an exception












0















I'm trying to use this NuGet Package for OCR:



https://github.com/charlesw/tesseract. After execution, I am getting this error:



System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
Source=Tesseract
StackTrace:
at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()
at Tesseract.Interop.LeptonicaApi.Initialize()
at Tesseract.Interop.TessApi.Initialize()
at Tesseract.Interop.TessApi.get_Native()
at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable`1 configFiles, IDictionary`2 initialOptions, Boolean setOnlyNonDebugVariables)
at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode)
at WebDriverSelenium.Program.Main(String args) in C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumProgram.cs:line 26


I've already added my assembly references for System.Reflection.Emit. tessdata is in the same directory with the Program.cs file. Also installed, Microsoft Visual C++ Redistributable for Visual Studio 2017 (x86 and x64). Still I can't make it work. I'm new to C#. And here is what my code looks like:



using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Reflection.Emit;
using Tesseract;

namespace WebDriverSelenium
{
class Program
{
static void Main(string args)
{
IWebDriver webDriver = new ChromeDriver(@"C:UsersKingtotskysourcereposChromeDriver");
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

webDriver.Url = "https://www.google.com";
Screenshot screenshot = ((ITakesScreenshot)webDriver).GetScreenshot();

screenshot.SaveAsFile("test.png", ScreenshotImageFormat.Png);

TesseractEngine engine = new TesseractEngine("./tessdata", "eng", EngineMode.Default);
var ss = Pix.LoadFromFile($@"C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumbinDebugnetcoreapp2.1test.png");
var page = engine.Process(ss);

Console.WriteLine(page.GetText());

//var ocr = new AutoOcr();
//var result = ocr.Read(@"C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumbinDebugnetcoreapp2.1test.png");
//Console.WriteLine(result.Text);
Console.ReadLine();


webDriver.Close();
webDriver.Quit();
}
}
}


What I'm trying to do is get a screenshot of the webpage and read the text found there. I am stuck on what to do next. Your help is really appreciated. Thank you!










share|improve this question























  • I've created a project using your example. Full project (links) can be found here. As you can see I don't use System.Reflection.Emit namespace at all. Also check all properties for files inside tessdata directory, they must have Copy to Output Directory=Copy always or at least Copy to Output Directory=Copy if newer. Please compare my project with yours and let me know what was wrong so I could post an answer here.

    – Andrew Kotov
    Nov 15 '18 at 15:02
















0















I'm trying to use this NuGet Package for OCR:



https://github.com/charlesw/tesseract. After execution, I am getting this error:



System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
Source=Tesseract
StackTrace:
at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()
at Tesseract.Interop.LeptonicaApi.Initialize()
at Tesseract.Interop.TessApi.Initialize()
at Tesseract.Interop.TessApi.get_Native()
at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable`1 configFiles, IDictionary`2 initialOptions, Boolean setOnlyNonDebugVariables)
at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode)
at WebDriverSelenium.Program.Main(String args) in C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumProgram.cs:line 26


I've already added my assembly references for System.Reflection.Emit. tessdata is in the same directory with the Program.cs file. Also installed, Microsoft Visual C++ Redistributable for Visual Studio 2017 (x86 and x64). Still I can't make it work. I'm new to C#. And here is what my code looks like:



using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Reflection.Emit;
using Tesseract;

namespace WebDriverSelenium
{
class Program
{
static void Main(string args)
{
IWebDriver webDriver = new ChromeDriver(@"C:UsersKingtotskysourcereposChromeDriver");
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

webDriver.Url = "https://www.google.com";
Screenshot screenshot = ((ITakesScreenshot)webDriver).GetScreenshot();

screenshot.SaveAsFile("test.png", ScreenshotImageFormat.Png);

TesseractEngine engine = new TesseractEngine("./tessdata", "eng", EngineMode.Default);
var ss = Pix.LoadFromFile($@"C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumbinDebugnetcoreapp2.1test.png");
var page = engine.Process(ss);

Console.WriteLine(page.GetText());

//var ocr = new AutoOcr();
//var result = ocr.Read(@"C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumbinDebugnetcoreapp2.1test.png");
//Console.WriteLine(result.Text);
Console.ReadLine();


webDriver.Close();
webDriver.Quit();
}
}
}


What I'm trying to do is get a screenshot of the webpage and read the text found there. I am stuck on what to do next. Your help is really appreciated. Thank you!










share|improve this question























  • I've created a project using your example. Full project (links) can be found here. As you can see I don't use System.Reflection.Emit namespace at all. Also check all properties for files inside tessdata directory, they must have Copy to Output Directory=Copy always or at least Copy to Output Directory=Copy if newer. Please compare my project with yours and let me know what was wrong so I could post an answer here.

    – Andrew Kotov
    Nov 15 '18 at 15:02














0












0








0








I'm trying to use this NuGet Package for OCR:



https://github.com/charlesw/tesseract. After execution, I am getting this error:



System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
Source=Tesseract
StackTrace:
at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()
at Tesseract.Interop.LeptonicaApi.Initialize()
at Tesseract.Interop.TessApi.Initialize()
at Tesseract.Interop.TessApi.get_Native()
at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable`1 configFiles, IDictionary`2 initialOptions, Boolean setOnlyNonDebugVariables)
at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode)
at WebDriverSelenium.Program.Main(String args) in C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumProgram.cs:line 26


I've already added my assembly references for System.Reflection.Emit. tessdata is in the same directory with the Program.cs file. Also installed, Microsoft Visual C++ Redistributable for Visual Studio 2017 (x86 and x64). Still I can't make it work. I'm new to C#. And here is what my code looks like:



using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Reflection.Emit;
using Tesseract;

namespace WebDriverSelenium
{
class Program
{
static void Main(string args)
{
IWebDriver webDriver = new ChromeDriver(@"C:UsersKingtotskysourcereposChromeDriver");
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

webDriver.Url = "https://www.google.com";
Screenshot screenshot = ((ITakesScreenshot)webDriver).GetScreenshot();

screenshot.SaveAsFile("test.png", ScreenshotImageFormat.Png);

TesseractEngine engine = new TesseractEngine("./tessdata", "eng", EngineMode.Default);
var ss = Pix.LoadFromFile($@"C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumbinDebugnetcoreapp2.1test.png");
var page = engine.Process(ss);

Console.WriteLine(page.GetText());

//var ocr = new AutoOcr();
//var result = ocr.Read(@"C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumbinDebugnetcoreapp2.1test.png");
//Console.WriteLine(result.Text);
Console.ReadLine();


webDriver.Close();
webDriver.Quit();
}
}
}


What I'm trying to do is get a screenshot of the webpage and read the text found there. I am stuck on what to do next. Your help is really appreciated. Thank you!










share|improve this question














I'm trying to use this NuGet Package for OCR:



https://github.com/charlesw/tesseract. After execution, I am getting this error:



System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
Source=Tesseract
StackTrace:
at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()
at Tesseract.Interop.LeptonicaApi.Initialize()
at Tesseract.Interop.TessApi.Initialize()
at Tesseract.Interop.TessApi.get_Native()
at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable`1 configFiles, IDictionary`2 initialOptions, Boolean setOnlyNonDebugVariables)
at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode)
at WebDriverSelenium.Program.Main(String args) in C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumProgram.cs:line 26


I've already added my assembly references for System.Reflection.Emit. tessdata is in the same directory with the Program.cs file. Also installed, Microsoft Visual C++ Redistributable for Visual Studio 2017 (x86 and x64). Still I can't make it work. I'm new to C#. And here is what my code looks like:



using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Reflection.Emit;
using Tesseract;

namespace WebDriverSelenium
{
class Program
{
static void Main(string args)
{
IWebDriver webDriver = new ChromeDriver(@"C:UsersKingtotskysourcereposChromeDriver");
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

webDriver.Url = "https://www.google.com";
Screenshot screenshot = ((ITakesScreenshot)webDriver).GetScreenshot();

screenshot.SaveAsFile("test.png", ScreenshotImageFormat.Png);

TesseractEngine engine = new TesseractEngine("./tessdata", "eng", EngineMode.Default);
var ss = Pix.LoadFromFile($@"C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumbinDebugnetcoreapp2.1test.png");
var page = engine.Process(ss);

Console.WriteLine(page.GetText());

//var ocr = new AutoOcr();
//var result = ocr.Read(@"C:UsersKingtotskysourcereposAutomationPracticeWebDriverSeleniumbinDebugnetcoreapp2.1test.png");
//Console.WriteLine(result.Text);
Console.ReadLine();


webDriver.Close();
webDriver.Quit();
}
}
}


What I'm trying to do is get a screenshot of the webpage and read the text found there. I am stuck on what to do next. Your help is really appreciated. Thank you!







c# tesseract






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 5:32









K. SupertrampK. Supertramp

612




612













  • I've created a project using your example. Full project (links) can be found here. As you can see I don't use System.Reflection.Emit namespace at all. Also check all properties for files inside tessdata directory, they must have Copy to Output Directory=Copy always or at least Copy to Output Directory=Copy if newer. Please compare my project with yours and let me know what was wrong so I could post an answer here.

    – Andrew Kotov
    Nov 15 '18 at 15:02



















  • I've created a project using your example. Full project (links) can be found here. As you can see I don't use System.Reflection.Emit namespace at all. Also check all properties for files inside tessdata directory, they must have Copy to Output Directory=Copy always or at least Copy to Output Directory=Copy if newer. Please compare my project with yours and let me know what was wrong so I could post an answer here.

    – Andrew Kotov
    Nov 15 '18 at 15:02

















I've created a project using your example. Full project (links) can be found here. As you can see I don't use System.Reflection.Emit namespace at all. Also check all properties for files inside tessdata directory, they must have Copy to Output Directory=Copy always or at least Copy to Output Directory=Copy if newer. Please compare my project with yours and let me know what was wrong so I could post an answer here.

– Andrew Kotov
Nov 15 '18 at 15:02





I've created a project using your example. Full project (links) can be found here. As you can see I don't use System.Reflection.Emit namespace at all. Also check all properties for files inside tessdata directory, they must have Copy to Output Directory=Copy always or at least Copy to Output Directory=Copy if newer. Please compare my project with yours and let me know what was wrong so I could post an answer here.

– Andrew Kotov
Nov 15 '18 at 15:02












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313019%2ftesseract-ocr-getting-an-exception%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313019%2ftesseract-ocr-getting-an-exception%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues