我在2008下用c#写的一个控制台程序如下
String win = "Test Window";
CvInvoke.cvNamedWindow(win);
Intptr ptr = CvInvoke.cvLoadImage("图像文件名", Emgu.CV.CvEnum.LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_ANYCOLOR);
CvInvoke.cvShowImage(win, ptr);
CvInvoke.cvWaitKey(0);
CvInvoke.cvDestroyWindow();编译没有错误,但是进入调试时会出现
Emgu.CV.CvInvoke的类型初始值设定项引发异常
但是我在2005下却没有一点问题,请达人指点,不甚感激
如果没有相关的dll,可以在这里下载到http://www.emgu.com/wiki/index.php/Download_And_Installation 

解决方案 »

  1.   

    Copy the OpenCV dll files: cv100.dll, cvaux100.dll, cvcam100.dll, cxcore100.dll, cxts001.dll, highgui100.dll, libguide40.dll and ml100.dll to the execution directory.试试吧!
      

  2.   


    那要怎么设置呢?麻烦说一下吧,我也是这个问题,我把Emgu.CV.Windows.Binary-1.4.0.0.zip里解压出来的文件里的DLL加到了项目引用里,把Emgu.CV.SourceAndExamples-1.4.0.0.zip里解压出来的文件夹src设置了系统路径,但是还是有这个问题.详细的Exception说明我看了一下,是说"无法加载cxcore110.dll",可是这个DLL已经在系统路径下面了,而且在CMD下面任意目录下我都可以直接输入cxcore110.dll,VS直接就打开了.但是项目里还是有问题.我试过把几个相关的DLL放在System32下面\把其所在的目录设置到Path里面\把相关的DLL放在项目目录下面,都不行.求高手解惑.附1:我的测试代码:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Emgu.CV;
    using Emgu.CV.UI;namespace OpenCV_Cell {
        class Program {
            static void Main (string[] args) {
                Image<Bgr,Byte> image;
                image = new Image<Bgr, Byte> (640, 480);  //在这一行引发了异常
            }
        }
    }附2:"Emgu.CV.CvInvoke的类型初始值设定项引发异常"的详细信息:
    未处理 System.TypeInitializationException
      Message="“Emgu.CV.CvInvoke”的类型初始值设定项引发异常。"
      Source="Emgu.CV"
      TypeName="Emgu.CV.CvInvoke"
      StackTrace:
           在 Emgu.CV.CvInvoke.cvCreateImageHeader(MCvSize size, IPL_DEPTH depth, Int32 channels)
           在 Emgu.CV.Image`2.AllocateData(Int32 rows, Int32 cols)
           在 Emgu.CV.Image`2..ctor(Int32 width, Int32 height)
           在 OpenCV_Cell.Program.Main(String[] args) 位置 E:\My Documents\Visual Studio 2008\Projects\OpenCV_Cell\OpenCV_Cell\Program.cs:行号 12
           在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.DllNotFoundException
           Message="无法加载 DLL“cxcore110.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。"
           Source="Emgu.CV"
           TypeName=""
           StackTrace:
                在 Emgu.CV.CvInvoke.cvRedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
                在 Emgu.CV.CvInvoke..cctor()
           InnerException: 
      

  3.   

    总算知道为什么了。他用了opencv1.0的类库。而且,我也终于明白他们说的“Copy the OpenCV dll files: cv100.dll, cvaux100.dll, cvcam100.dll, cxcore100.dll, cxts001.dll, highgui100.dll, libguide40.dll and ml100.dll to the execution directory. ”是什么意思。
      

  4.   

    是这个意思:opencv1.0按照好以后,有个bin文件夹。比如opencv安装在
    “C:\Program Files\OpenCV”,那么就有个 “C:\Program Files\OpenCV\bin”文件夹,这个文件夹里有cv100.dll, cvaux100.dll, cvcam100.dll, cxcore100.dll, cxts001.dll, highgui100.dll, libguide40.dll and ml100.dll ,这几个动态链接库。把它们拷贝到你的VS项目中的bin文件夹中,就不会发生错误了。我刚试过,用的就是本站下载的“C#写的基于opencv的程序”。
      

  5.   

    再说明一下,我用的是Emgu cv1.3,如果用Emgu cv1.3还是会出错。
      

  6.   

    你应该用的是emgucv2.0 吧,需要装 vc++ 2008 sp1 
    http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&displaylang=zh-cn
    我也类似的问题,解决了
      

  7.   

    如果你用的是2005 装vc++ 2005 sp1
    http://code.msdn.microsoft.com/KB961894/Release/ProjectReleases.aspx?ReleaseId=2067
      

  8.   

    为什么emgu自带的例子可以运行而自己写的却出现该错误呢,即便是完全拷贝的例子