Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Code error, Please help me!!!

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 Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;

         
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        Capture capturecam = null;       //instance for capture using webcam
            bool CapturingProcess = false;   //boolean stating the capturing process status
            Image<Bgr, Byte> imgOrg;   //image type RGB (or Bgr as we say in Open CV)
            Image<Gray, Byte> imgProc; //processed image will be grayscale so a gray image
            
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            
            try
            {
                capturecam = new Capture();
               
            }
            catch (NullReferenceException exception)
            {
                MessageBox.Show(exception.Message);
                return;
            }
            Application.Idle += new EventHandler(ProcessFunction);
            CapturingProcess = true;

        }
        void ProcessFunction (object sender, EventArgs e)
        {
            imgOrg=capturecam.QueryFrame();
            if (imgOrg == null) return;

            imgProc = imgOrg.InRange(new Bgr(50,50,50) , new Bgr (255,255,255));
            imgProc = imgProc.SmoothGaussian(9);
            original.Image=imgOrg;
            processed.Image=imgProc;
        }

        private void playorpause_Click(object sender, EventArgs e)
        {
            if (CapturingProcess == true)
            {
                Application.Idle -= ProcessFunction;
                CapturingProcess = false;
                playorpause.Text= "Play";
            }
            else
            {
                Application.Idle += ProcessFunction;
                CapturingProcess = true;
                playorpause.Text= "Pause";
            }
        }
    }
}


What I have tried:

After Debug, error:
"The type initializer for 'Emgu.CV.CvInvoke' threw an exception."
.
Posted
Updated 4-May-17 1:18am

1 solution

it is a runtime issue, depending when it happens. A possible reason maybe that the "Emgu"-runtime isnt present or working in the app. Like not registered or dlls not in the app-directory or some wrong version like in that question The type initializer for '' threw an exception.

Try to inspect the details of the exception, because often some detail text explains what happened.
 
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