14

i really a newbie with EgmuCV

i try to capture images from webcam with the following code:

//Program.cs (Winform)
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.UI;
using Emgu.Util;
using Emgu.CV.Structure;

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

        private void button1_Click(object sender, EventArgs e)
        {
            Capture cp = new Capture();
            ImageViewer imv = new ImageViewer();

            Application.Idle += new EventHandler(delegate(object s, EventArgs ea)
            {
                imv.Image = cp.QueryFrame();
            });

            imv.ShowDialog();

        }
    }
}

i get the follow error:

enter image description here

i check and have all necesary dll in the .exe folder

rkmax
  • 17,633
  • 23
  • 91
  • 176

6 Answers6

23

After experiencing this same problem for a while, I found the instructions for solving this (TypeInitializer Exception) are incomplete.

  1. For a basic app, you need cvextern.dll, Emgu.CV.dll, Emgu.CV.UI.dll, Emgu.Util.dll in the .EXE's directory.

  2. You need a x86(x64) dir in the .exe directory and inside "x86" dir you need opencv_calib3dXXX.dll, opencv_contribXXX.dll, opencv_coreXXX.dll, opencv_features2dXXX.dll, opencv_highguiXXX.dll, opencv_imgprocXXX.dll, opencv_legacyXXX.dll, opencv_mlXXX.dll, opencv_objectdetectXXX.dll, opencv_videoXXX.dll and cudart32_42_9.dll, npp32_42_9.dll, opencv_flann240.dll

The app will work as soon as you include all of the required DLLs.

gonzobrains
  • 7,856
  • 14
  • 81
  • 132
rkmax
  • 17,633
  • 23
  • 91
  • 176
  • 3
    For me just copying the **cvextern.dll** from `C:\Emgu\emgucv-windows-universal 3.0.0.2157\bin\x86` to `...\Visual Studio 2013\Projects\ScreenAnalyzer\TestProject\bin\Debug` worked to get rid if the exception. – Alexander Taubenkorb Nov 27 '15 at 10:08
  • For me, having Emgu included via package-manager in a multi-project solution, it was solved by adjusting the build output path of the subproject referencing Emgu to the output path (and so the execute path) of the StartUp project (in VS 2017). – lars k. Mar 19 '19 at 14:20
5

I'm using Emgu 3.0 64 bit and the only thing i need to do to fix this problem is change the build type in my project into x64.

Right click on your project's name -> Properties -> Build -> Platform Target -> x64

refer to http://www.codeproject.com/Articles/257502/Creating-Your-First-EMGU-Image-Processing-Project

hope it helps someone.

fian
  • 61
  • 1
  • 2
  • 3 days of beating my head against a wall solved. In VS 2013 Express, I just clicked off the "prefer 32 bit" in the Platform Target and it suddenly started working. Pretty annoying that a "prefer" option can cause such a problem. Thankyou very much indeed. – Peter Webb Aug 31 '17 at 16:56
1

Another case that happened to me was that I had a NuGet package that was installed but not loaded for my project so the references looked good but at run-time, I got the TypeInitializationException.

-manage NuGet packages

-clock manage on the package

-check the box with the current project.

Denis
  • 664
  • 9
  • 24
1

This problem also occurs if you are using OpenCV DLL compiled with GPU support but your PC doesn't have a GPU, e.g. if you are using a portable computer with Intel graphics chipset.

In this case you can use the older version 2.4.0 which still offers DLL without GPU support:

https://sourceforge.net/projects/emgucv/files/emgucv/2.4.0/libemgucv-windows-x64-2.4.0.1717.zip

Jack Miller
  • 6,843
  • 3
  • 48
  • 66
  • Hi, can you please describe how to use the emgucv 2.4.. I can't find the dll's in your recommended package? Thanks! – titech May 31 '17 at 12:37
  • The DLLs are within the linked ZIP file in the folders ``bin/`` and ``bin/x64/`` for 32bit and 64bit, respectively. Easiest, link all of them to your project and you'll be able to access objects `Capture` and `ImageViewer` mentioned in the initial question. – Jack Miller Aug 17 '17 at 05:34
0

Just copy the cvextern.dll file from x64 folder if you are using 64bit OS and then copy it to the debug folder of your project.

Note: Do it manually because "add existing item" doesn't copy it.

Minion
  • 964
  • 14
  • 16
0

I am using Emgu.CV 4.4.0.4099 and got the same exception. Here is the steps I followed to fix it.

  1. Copy cvextern.dll to output directory.
  2. Installing Emgu.CV.runtime.windows nuget package.