本文介绍了C#:'Emgu.CV.CvInvoke'的类型初始值设定项引发了异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中出现以下错误:'Emgu.CV.CvInvoke'的类型初始化程序引发异常。我的代码:



使用System; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
使用MetroFramework.Forms;使用System.Data.Odbc
;
使用System.Data.SqlClient;
使用System.Configuration;
使用System.Media;
使用System.Drawing.Imaging;
使用Emgu.CV;
使用Emgu.CV.UI;
使用Emgu.CV.Structure;
使用Emgu.Util;
使用System.Runtime.InteropServices;

名称空间Visitor_GatePass_Management_System
{
//公共部分类VisitorMasterPage:表格

公共部分类VisitorMasterPage:MetroForm
{

public VisitorMasterPage()
{
InitializeComponent();
}

私人Emgu.CV.Capture _capture;
//私有静态Emgu.CV.Capture _capture;
private bool _captureInProgress;
//Emgu.CV.Capture _capture;
// bool _captureInProgress;

private void VisitorMasterPage_Load(object sender,EventArgs e)
{
lblpath.Text =D:\\\\ image.jpg;
}

private void btncapphonto_Click(object sender,EventArgs e)
{
if((this.lblpath.Text.Trim()。Length> 0) )
{
if((_capture == null))
{
try
{
// _ capture = new Emgu.CV.Capture() ;

_capture = new Capture();
}
catch(NullReferenceException excpt)
{
MetroFramework.MetroMessageBox.Show(this,excpt.Message);
}
}
if(((_capture!= null)))
{
if(_captureInProgress)
{
this.btncapphonto .Text =开始捕获;
// this.Load + = new EventHandler(this.ProcessFrame);
// EventHandlerList list =(EventHandlerList)
Application.Idle - = new EventHandler(this.ProcessFrame);

this.pbphoto.Image.Save(this.lblpath.Text,ImageFormat.Jpeg);
this.pbphoto.ImageLocation = this.lblpath.Text;
}
else
{
// captureButton.Text =Capture
this.btncapphonto.Text =Capture;
Application.Idle + = new EventHandler(this.ProcessFrame);
}
_captureInProgress =!_captureInProgress;
}
}
其他
{
MetroFramework.MetroMessageBox.Show(这个,请设置用于保存图像的目录路径。);
}
}

private void ProcessFrame(对象发送者,EventArgs arg)
{
//Emgu.CV.Image [] frame(Emgu。 CV.Structure.Bgr,Byte)= this._capture.QueryFrame;
Emgu.CV.Image frame = this._capture.QueryFrame();
Emgu.CV.Image frame1 = frame.Resize(150,150,Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
pbphoto.Image = frame1.Bitmap;
}

private void btnSaveVisitorMaster_Click(object sender,EventArgs e)
{

}

}
}
解决方案

I have a following error in my project: "The type initializer for 'Emgu.CV.CvInvoke' threw an exception". My code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Configuration;
using System.Media;
using System.Drawing.Imaging;
using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using Emgu.Util;
using System.Runtime.InteropServices;

namespace Visitor_GatePass_Management_System
{
// public partial class VisitorMasterPage : Form

public partial class VisitorMasterPage : MetroForm
{

public VisitorMasterPage()
{
  InitializeComponent();
}

private Emgu.CV.Capture _capture;
//private static Emgu.CV.Capture _capture;
private bool _captureInProgress;
//Emgu.CV.Capture _capture;
//bool _captureInProgress;

private void VisitorMasterPage_Load(object sender, EventArgs e)
{
 lblpath.Text = "D:\\image.jpg";
}

private void btncapphonto_Click(object sender, EventArgs e)
{
  if ((this.lblpath.Text.Trim().Length > 0))
  {
    if ((_capture==null))
    {
      try
    {
     //_capture = new Emgu.CV.Capture();

     _capture = new Capture();
    }
    catch (NullReferenceException excpt)
    {
      MetroFramework.MetroMessageBox.Show(this, excpt.Message);
    }
  }
  if (((_capture != null)))
  {
    if (_captureInProgress)
    {
      this.btncapphonto.Text = "Start Capture";
      // this.Load +=new EventHandler(this.ProcessFrame);
      //EventHandlerList list=(EventHandlerList)
      Application.Idle -= new EventHandler(this.ProcessFrame);

      this.pbphoto.Image.Save(this.lblpath.Text, ImageFormat.Jpeg);
      this.pbphoto.ImageLocation = this.lblpath.Text;
    }
    else
    {
      // captureButton.Text = "Capture"
      this.btncapphonto.Text = "Capture";
      Application.Idle += new EventHandler(this.ProcessFrame);
    }
    _captureInProgress = !_captureInProgress;
  }
 }
 else
 {
    MetroFramework.MetroMessageBox.Show(this, "Please set directory path for saving the image.");
 }
}

private void ProcessFrame(object sender, EventArgs arg)
{
  //Emgu.CV.Image[] frame(Emgu.CV.Structure.Bgr,Byte)= this._capture.QueryFrame;
  Emgu.CV.Image frame = this._capture.QueryFrame();
  Emgu.CV.Image frame1 = frame.Resize(150, 150,Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
  pbphoto.Image = frame1.Bitmap;
}

private void btnSaveVisitorMaster_Click(object sender, EventArgs e)
{

}

}
}
解决方案


这篇关于C#:'Emgu.CV.CvInvoke'的类型初始值设定项引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 09:45