EmguCv.CV.CvInvoke引发的EmguCvTypeInitializationException现在,仔细听,因为非常奇怪的部分来了。我首先要说我的问题有三个“级别”,但是,所有“级别”中的代码完全相同,即使没有任何变化。这自然会指向引用或链接问题,但我再次尝试使用不同的教程无济于事。级别1(此级别产生TypeInitializationException)我创建一个新项目,正确引用所有内容等,然后在这个新项目中编写我的代码。调试时,我抛出异常并且我的程序退出。这是问题图片的链接:http://prntscr.com/uychc第2级(这个级别工作得很好,不会抛出任何异常)在这个级别,我几乎找到了EmguCv的示例项目(在这种情况下在VideoSurveilance中),然后删除默认代码并将我的所有代码复制并粘贴到那里。添加我需要的更多参考后,程序运行良好。我不能发布超过3个链接,但你必须相信我,视频图像显示正确。第3级(这个级别不会抛出异常,但会警告我“第一次机会”)在这个级别,我将整个第2级项目复制并粘贴到另一个目录中。找到并重新链接丢失的文件/引用后,我能够运行该程序,但图片没有显示,我收到“Emgu.CV.dll警告中出现类型为“System.TypeInitializationException”的第一次机会异常”.http://prntscr.com/uycmn我目前正在运行Windows7x64(是的,我将构建选项更改为x64和x64.dll)并运行EmguCv2.4.9和2.4.2(在两者上测试)和VisualStudios2010和2012(两者都经过测试)。这是可能值得的代码:usingSystem;使用System.Collections.Generic;使用System.ComponentModel;使用系统数据;使用系统绘图;使用System.Linq;使用系统文本;//使用System.Threading.Tasks;使用System.Windows.Forms;使用System.Windows;使用System.Windows.Controls;使用System.Windows.Data;使用System.Windows.Documents;使用System.Windows.Input;使用System.Windows.Media;使用System.Windows.Media.Imaging;使用System.Windows.Navigation;使用System.Windows.Shapes;使用Microsoft.Kinect;使用Emgu.CV;使用Emgu.CV.CvEnum;使用Emgu.CV.Structure;使用Emgu.CV.UI;使用System.IO;namespaceVideoSurveilance{publicpartialclassVideoSurveilance:Form{KinectSensor传感器;可写位图深度位图;可写位图颜色位图;DepthImagePixel[]depthPixels;byte[]颜色像素;intblobCount=0;publicVideoSurveilance(){InitializeComponent();}privatevoidVideoSurveilance_Load(objectsender,System.EventArgse){foreach(varpotentialSensorinKinectSensor.KinectSensors){if(potentialSensor.Status==KinectStatus.Connected){this.sensor=potentialSensor;休息;}}if(null!=this.sensor){this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);this.colorPixels=newbyte[this.sensor.ColorStream.FramePixelDataLength];this.depthPixels=newDepthImagePixel[this.sensor.DepthStream.FramePixelDataLength];this.colorBitmap=newWriteableBitmap(this.sensor.ColorStream.FrameWidth,this.sensor.ColorStream.FrameHeight,96.0,96.0,PixelFormats.Bgr32,null);this.depthBitmap=newWriteableBitmap(this.sensor.DepthStream.FrameWidth,this.sensor.DepthStream.FrameHeight,96.0,96.0,PixelFormats.Bgr32,null);WriteableBitmap位图;bitmap=newWriteableBitmap(this.sensor.DepthStream.FrameWidth,this.sensor.DepthStream.FrameHeight,96.0,96.0,PixelFormats.Bgr32,无效);byte[]retVal=newbyte[bitmap.PixelWidth*bitmap.PixelHeight*4];bitmap.CopyPixels(newInt32Rect(0,0,bitmap.PixelWidth,bitmap.PixelHeight),retVal,bitmap.PixelWidth*4,0);位图b=newBitmap(bitmap.PixelWidth,bitmap.PixelHeight);诠释k=0;字节红色、绿色、蓝色、alpha;for(inti=0;i
