unsafe Task <ITranslator> IDetectService.Detect(ref ImageData image) { Profiler.BeginSample("FaceService.DetectAsync"); // too small image if (image.WebcamWidth < 40) { Debug.LogWarning("FaceService.DetectAsync: image is too small"); goto DetectDone; } if (promise != null) { promise.TrySetCanceled(); // the number of detected faces fixed(FaceData *facePtr = translator.storage) { translator.count = (UInt16)FaceLib.Detect(ref translator.context, ref image, facePtr); } DetectDone: // return result in translator form promise = new TaskCompletionSource <ITranslator>(); promise.SetResult(translator); Profiler.EndSample(); return(promise.Task); } void IDisposable.Dispose() { Debug.LogWarning("FaceService.Dispose"); FaceLib.Release(ref translator.context); if (need3D) { Face3DLib.Release(ref translator.context3D); } if (promise == null) return; } promise.TrySetCanceled(); promise = null; }
internal unsafe void Init(int _maxCount, bool _need3D, LevelOf3DProcess _levelOf3DProcess) { context = default(FaceLib.Context); context.detectableSize = 128f; context.logStateMode = 0; context.maxCount = (UInt16)_maxCount; context.InitPath = Application.persistentDataPath; storage = new FaceData[context.maxCount]; need3D = _need3D; quad = FindObjectOfType <AutoBackgroundQuad>(); FaceLib.Init(ref context); if (need3D) { context3D.levelOf3DProcess = _levelOf3DProcess; Face3DLib.Init(ref context3D); } }