public async Task StartRunning(Action startCallback, Action frameCallback) { if (activeCamera == null || isRunning) { return; } this.startCallback = startCallback; this.frameCallback = frameCallback; preview = await activeCamera.StartRunning(); width = preview.width; height = preview.height; isRunning = true; firstFrame = true; attachment = new GameObject("NatDeviceWithOpenCVForUnityExample NatDeviceCamSource Helper").AddComponent <NatDeviceCamSourceAttachment>(); attachment.@delegate = () => { if (firstFrame) { startCallback(); firstFrame = false; } else { frameCallback(); } }; }
public void StopRunning() { if (activeCamera == null || !isRunning) { return; } if (attachment != null) { attachment.@delegate = default; NatDeviceCamSourceAttachment.Destroy(attachment.gameObject); attachment = default; } activeCamera.StopRunning(); isRunning = false; }