vb.net 初始化 Emgu.CV 的异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13417449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception initializing Emgu.CV
提问by Richard Twitty
Hey this is my first time using this website, but I a problem. I saw this awesome youtube video about getting ocr to work with vb.net. Here the url:
嘿,这是我第一次使用这个网站,但我有问题。我看到了这个很棒的 YouTube 视频,内容是关于让 ocr 与 vb.net 一起工作。这里的网址:
http://www.youtube.com/watch?v=Kjdu8SjEtG0
http://www.youtube.com/watch?v=Kjdu8SjEtG0
So I decided to download the emgu libraries, here the url:
所以我决定下载 emgu 库,这里是 url:
http://sourceforge.net/projects/emgucv/
http://sourceforge.net/projects/emgucv/
I did everything the video say and I get this error: "An error occurred creating the form. See Exception.InnerException for details. The error is: The type initializer for 'Emgu.CV.OCR.Tesseract' threw an exception."
我做了视频所说的一切,我得到这个错误:“创建表单时出错。有关详细信息,请参阅 Exception.InnerException。错误是:'Emgu.CV.OCR.Tesseract' 的类型初始值设定项引发异常。”
I even copy the exception(if that do any help):
我什至复制了异常(如果有帮助的话):
System.InvalidOperationException was unhandled
Message=An error occurred creating the form. See Exception.InnerException for details. The error is: The type initializer for 'Emgu.CV.OCR.Tesseract' threw an exception.
Source=WindowsApplication1
StackTrace:
at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at WindowsApplication1.My.MyProject.MyForms.get_Form1()
at WindowsApplication1.My.MyApplication.OnCreateMainForm() in C:\Users\UltimateSoul\AppData\Local\Temporary Projects\WindowsApplication1\My Project\Application.Designer.vb:line 35
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.TypeInitializationException
Message=The type initializer for 'Emgu.CV.OCR.Tesseract' threw an exception.
Source=Emgu.CV.OCR
TypeName=Emgu.CV.OCR.Tesseract
StackTrace:
at Emgu.CV.OCR.Tesseract..ctor(String dataPath, String language, OcrEngineMode mode)
at WindowsApplication1.Form1..ctor() in C:\Users\UltimateSoul\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb:line 8
InnerException: System.TypeInitializationException
Message=The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
Source=Emgu.CV
TypeName=Emgu.CV.CvInvoke
StackTrace:
at Emgu.CV.CvInvoke.CV_MAKETYPE(Int32 depth, Int32 cn)
at Emgu.CV.OCR.Tesseract..cctor()
InnerException: System.DllNotFoundException
Message=Unable to load DLL 'opencv_core242': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=Emgu.CV
TypeName=""
StackTrace:
at Emgu.CV.CvInvoke.cvRedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
at Emgu.CV.CvInvoke..cctor()
InnerException:
I been on this for days, and got no where. Please help thanks!
我已经在这几天了,但无处可去。请帮忙谢谢!
I sorry here the code
我很抱歉这里的代码
Imports Emgu.CV
Imports Emgu.Util
Imports Emgu.CV.OCR
Imports Emgu.CV.Structure
Public Class Form1
Dim OCRz As Tesseract = New Tesseract("tessdata", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_ONLY)
Dim pic As Bitmap = New Bitmap(270, 100)
Dim gfx As Graphics = Graphics.FromImage(pic)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
gfx.CopyFromScreen(New Point(Me.Location.X + PictureBox1.Location.X + 4, Me.Location.Y + PictureBox1.Location.Y + 30), New Point(0, 0), pic.Size)
PictureBox1.Image = pic
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OCRz.Recognize(New Image(Of Bgr, Byte)(pic))
RichTextBox1.Text = OCRz.GetText
End Sub
End Class
回答by Eko Junaidi Salam
copy cvextern.dlland file with opencv_**.dllto your output directory: bin/Debug/
复制cvextern.dll并文件opencv_**.dll到您的输出目录:bin/Debug/
Setting your configuration manager to run "AnyCPU", and the configuration must "Debug".
将配置管理器设置为运行“AnyCPU”,并且配置必须“调试”。
回答by Vipul Divyanshu
If you are on a 64bit OS, you must add to reference the following files too (For EMGU CV version >=2.4)
如果您使用的是 64 位操作系统,则还必须添加以引用以下文件(对于 EMGU CV 版本 >=2.4)
cudart64_42_9.dll, cvextern.dll, npp64_42_9.dll
cudart64_42_9.dll, cvextern.dll, npp64_42_9.dll
This will help in using emguCv 2.4.x in 64bit OS without internal exceptions.
这将有助于在 64 位操作系统中使用 emguCv 2.4.x,没有内部异常。
回答by Tvs
In the video it is x64 dir being copied. Instead copy x86 dir in your project dir and in properties select all the dll files enable 'copy if newer'.
在视频中,它是被复制的 x64 目录。而是在您的项目目录中复制 x86 目录,并在属性中选择所有 dll 文件,启用“如果更新则复制”。

