pitumalkani
pitumalkani

Reputation: 127

The type initializer for 'Emgu.CV.CvInvoke' threw an exception

I have written simple program to open image and show image in VS 2010 in C# using EmguCV but I am getting the following exception:

The type initializer for 'Emgu.CV.CvInvoke' threw an exception.

at line Image<Bgr, Byte> myimg = new Image<Bgr, Byte>(openfile.FileName);

here is 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 Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;

namespace imgdisplay2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void imageBox1_Click(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)  
        {
            OpenFileDialog openfile = new OpenFileDialog();
            if (openfile.ShowDialog() == DialogResult.OK)
            {
                // imageBox1 =new Emgu.CV.UI.ImageBox() ;
                Image<Bgr, Byte> myimg = new Image<Bgr, Byte>(openfile.FileName);
                pictureBox1.Image = myimg.ToBitmap();
                //imageBox1.Image =myimg ;
            }  
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
        }
    }
}

Upvotes: 5

Views: 19004

Answers (2)

Babi
Babi

Reputation: 131

Here's how I could solve the problem: Copy the x86 (or x64 on 64-bit OS) folder address under "bin" folder where your Emgu is installed. Mine is: C:\Emgu\emgucv-windows-universal-gpu 2.4.9.1847\bin\x86

Then paste this address here: Control Panel>System>Advanced System Settings>Environment Variables> in system variables click on "Path" and click edit > add a semicolon to the end of the string there and paste the address you've just copied to clipboard after that semicolon > click on the OKs.

Upvotes: 1

Luca Del Tongo
Luca Del Tongo

Reputation: 2702

You should solve CVInvoke exception by following suggestions outlined in emgu official wiki:

http://www.emgu.com/wiki/index.php/Download_And_Installation#The_type_initializer_for_.27Emgu.CV.CvInvoke.27_threw_an_exception.

Upvotes: 4

Related Questions