Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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)
{

}

}
}
Posted
Updated 11-Jun-16 9:41am
v3
Comments
Leo Chapiro 10-Sep-15 5:57am    
This is a bit difficult to help you without to see the source code ... Let me mark your question as "Unclear AND Incomplete" ...
Member 11952997 14-Sep-15 1:10am    
sorry for late reply bro,
i send code below in visual studio 2010 with c#, i use metro framework.

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<emgu.cv.structure.bgr, byte=""> frame = this._capture.QueryFrame();
Emgu.CV.Image<emgu.cv.structure.bgr, byte=""> frame1 = frame.Resize(150, 150, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
pbphoto.Image = frame1.Bitmap;
}

private void btnSaveVisitorMaster_Click(object sender, EventArgs e)
{

}

}
}
Member 11730805 14-Sep-15 5:07am    
Actually which project you are working on..bec these code paths seems familiar to me...

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900