我正在尝试将EmguCV(OpenCV包装器)与Unity3d集成。为此,我遵循了this教程并完成了所有必需的步骤。
我现在拥有的是:
我做了什么
以下是用于面部检测的脚本:
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();
}
}
问题所在:
当我在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)
这是控制台窗口
所以问题是如何修复TypeLoadException错误,以成功将EmguCV集成为一个整体。