- Home /
Question by
EinfachFinn · Mar 06 at 02:13 AM ·
scripting problemopencv
NullReference OpenCv
Hey, im working with this script but getting hundreds of errors. May someone please help me?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OpenCvSharp;
public class FaceDetector : MonoBehaviour
{
public int Camera;
WebCamTexture _webCamTexture;
CascadeClassifier cascade;
// Start is called before the first frame update
void Start()
{
WebCamDevice[] devices = WebCamTexture.devices;
_webCamTexture = new WebCamTexture(devices[1].name);
_webCamTexture.Play();
cascade = new CascadeClassifier(Application.dataPath + @"haarcascade_frontalface_default.xml");
}
// Update is called once per frame
void Update()
{
GetComponent<Renderer>().material.mainTexture = _webCamTexture;
Mat frame = OpenCvSharp.Unity.TextureToMat(_webCamTexture);
findNewFace(frame);
}
void findNewFace(Mat frame)
{
var faces = cascade.DetectMultiScale(frame, 1.1, 2, HaarDetectionType.ScaleImage);
if (faces.Length >= 1)
{
Debug.Log(faces[1].Location);
}
}
}
FileNotFoundException: "C:/Users/finn0/Doodle Dude/Assetshaarcascade_frontalface_default.xml"not found OpenCvSharp.CascadeClassifier..ctor (System.String fileName) (at Assets/Asset/OpenCV/OpenCV+Unity/Assets/Scripts/OpenCvSharp/modules/objdetect/CascadeClassifier.cs:40) FaceDetector.Start () (at Assets/Scripts/FaceDetector.cs:18)
NullReferenceException: Object reference not set to an instance of an object FaceDetector.findNewFace (OpenCvSharp.Mat frame) (at Assets/Scripts/FaceDetector.cs:33) FaceDetector.Update () (at Assets/Scripts/FaceDetector.cs:28)
Comment
Your answer
