Как исправить исключение TypeLoadException (EmguCV + Unity3d) - PullRequest
0 голосов
/ 06 июля 2018

Я пытаюсь интегрировать EmguCV (OpenCV Wrapper) с Unity3d. Для этого я следовал этому учебнику и выполнил все необходимые шаги.

Теперь, что у меня есть:

  • EmguCV: emgucv-windesktop_x64-cuda 3.1.0.2504
  • Unity 2017.4.0f1 (с установленным на нем экспериментальным .NET 4.6 в разделе «Сборка»> «Настройки проигрывателя»)
  • Monodevelop 5.9.6
  • ОС: окно 7 (x64 бит)

И что я сделал:

  • Я установил EmguCV в каталог C: \ Emgu \ emgucv-windesktop_x64-cuda 3.1.0.2504
  • Установить переменные среды для каталога 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();
    }
}
  • Скопировал следующие требуемые файлы DLL из каталога bin EmguCV и вставил их в папку ресурсов проекта Unity. (Необходимые 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 в единство.

...