如何修复TypeLoadException(EmguCV + Unity3d)

时间:2018-07-06 13:46:47

标签: c# unity3d monodevelop emgucv

我正在尝试将EmguCV(OpenCV包装器)与Unity3d集成。为此,我遵循了this教程并完成了所有必需的步骤。

我现在拥有的是:

  • EmguCV:emgucv-windesktop_x64-cuda 3.1.0.2504
  • Unity 2017.4.0f1(在其Build> Player设置中设置了实验性.NET 4.6)
  • Monodevelop 5.9.6
  • OS:Window 7(x64位)

我做了什么

  • 我在目录C:\ Emgu \ emgucv-windesktop_x64-cuda 3.1.0.2504中安装了EmguCV
  • 将EmguCV目录的环境变量设置为

    enter image description here

    enter image description here

  • 统一创建场景并在其中添加面部检测脚本

enter image description here

以下是用于面部检测的脚本:

using UnityEngine;
using System.IO;
using Emgu.CV;
using Emgu.CV.Structure;

public class faceDetect : MonoBehaviour {

    private int frameWidth;
    private int frameHeight;
    private VideoCapture cvCapture;
    private CascadeClassifier _cascadeClassifier;
    private Image<Bgr, byte> currentFrameBgr;

    public Material mt;

    void Start () {

        cvCapture = new VideoCapture(0);

        _cascadeClassifier = new CascadeClassifier(Application.dataPath + "/haarcascade_frontalface_alt.xml");

        frameWidth = (int)cvCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth);
        frameHeight = (int)cvCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight);

        cvCapture.Start();

    }

    void Update () {

        faceDetector();
    }


    private void faceDetector()
    {
        currentFrameBgr = cvCapture.QueryFrame().ToImage<Bgr, byte>();

        Texture2D tex = new Texture2D(640, 480);

        if (currentFrameBgr != null)
        {
            Image<Gray, byte> grayFrame = currentFrameBgr.Convert<Gray, byte>();

            var faces = _cascadeClassifier.DetectMultiScale(grayFrame, 1.1, 4, new System.Drawing.Size(frameWidth/8, frameHeight/8));

            foreach (var face in faces)
            {
                currentFrameBgr.Draw(face, new Bgr(0, 255, 0), 3);
            }

            //Convert this image into Bitmap, the pixel values are copied over to the Bitmap
            currentFrameBgr.ToBitmap();

            MemoryStream memstream = new MemoryStream();
            currentFrameBgr.Bitmap.Save(memstream, currentFrameBgr.Bitmap.RawFormat);

            tex.LoadImage(memstream.ToArray());
            mt.mainTexture = tex;
        }
    }

    private void OnDestroy()
    {
        //release from memory
        cvCapture.Dispose();
        cvCapture.Stop();
    }
}
  • 从EmguCV bin目录中复制以下必需的DLL文件,并将其粘贴到统一项目资产文件夹中。 (我在this教程中提到了为面部检测脚本添加的必需DLL文件)

enter image description here

问题所在:

当我在Unity中运行程序时,它给出了TypeLoadException的错误

TypeLoadException: Could not set up parent class, due to: Could not load file or assembly 'Microsoft.VisualStudio.DebuggerVisualizers, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. assembly:Microsoft.VisualStudio.DebuggerVisualizers, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:<unknown type> member:<none> assembly:C:\Users\Public\Documents\Unity Projects\EmguCvExample\Assets\Emgu.CV.DebuggerVisualizers.VS2010.dll type:BaseImageVisualizer member:<none>
System.RuntimeType.GetMethodsByName (System.String name, System.Reflection.BindingFlags bindingAttr, System.Boolean ignoreCase, System.RuntimeType reflectedType) (at <c95265f74fdf4905bfb0d5a4b652216c>:0)
System.RuntimeType.GetMethodCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConv, System.Type[] types, System.Boolean allowPrefixLookup) (at <c95265f74fdf4905bfb0d5a4b652216c>:0)
System.RuntimeType.GetMethods (System.Reflection.BindingFlags bindingAttr) (at <c95265f74fdf4905bfb0d5a4b652216c>:0)
UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (UnityEditor.Build.BuildPipelineInterfaces+BuildCallbacks findFlags) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:189)

这是控制台窗口

enter image description here

所以问题是如何修复TypeLoadException错误,以成功将EmguCV集成为一个整体。

0 个答案:

没有答案