我已经在这个项目上工作了几个月,我正在尝试使用OpenCVSharp将眼睛跟踪整合到Unity中.我已经设法让一切工作,包括实际跟踪瞳孔等,但我有内存泄漏.基本上在程序运行20-30秒后冻结并且控制台错误说"无法分配(这里插入数字)位".在查看程序运行期间的内存使用情况后,您可以看到它的使用情况稳步攀升,直至最大化然后崩溃.
现在我花了很长时间试图解决这个问题,并阅读了很多关于正确发布图像/存储等的帮助帖子.尽管事实上我正在这样做,但它似乎并未正确释放它们.我尝试使用垃圾收集器强制它回收内存,但这似乎也没有用.我只是对图像做了一些根本性的错误以及我如何回收它们?或者每帧都创建新图像(即使我正在释放它们)导致问题.
任何帮助将不胜感激.这是下面的代码,您可以忽略更新功能中的许多内容,因为它与实际跟踪部分和校准有关.我意识到代码非常混乱,抱歉!需要担心的主要部分是EyeDetection().
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using OpenCvSharp;
using OpenCvSharp.Blob;
//using System.Xml;
//using System.Threading;
//using AForge;
//using OpenCvSharp.Extensions;
//using System.Windows.Media;
//using System.Windows.Media.Imaging;
public class CaptureScript2 : MonoBehaviour
{
//public GameObject planeObj;
public WebCamTexture webcamTexture; //Texture retrieved from the webcam
//public Texture2D texImage; //Texture to apply to plane
public string deviceName;
private int devId = 1;
private int imWidth = 800; //camera width
private int imHeight = 600; //camera height
private string errorMsg = "No errors …Run Code Online (Sandbox Code Playgroud)