protected override void Start() { // Load global camera benchmark settings. int width, height, framerate; NatCamWithOpenCVForUnityExample.CameraConfiguration(out width, out height, out framerate); NatCamWithOpenCVForUnityExample.ExampleSceneConfiguration(out performImageProcessingEachTime); // Create camera source cameraSource = new NatCamSource(width, height, framerate, useFrontCamera); if (!cameraSource.activeCamera) { cameraSource = new NatCamSource(width, height, framerate, !useFrontCamera); } cameraSource.StartPreview(OnStart, OnFrame); // Create comic filter comicFilter = new ComicFilter(); exampleTitle = "[NatCamWithOpenCVForUnity Example] (" + NatCamWithOpenCVForUnityExample.GetNatCamVersion() + ")"; exampleSceneTitle = "- Integration With NatShare Example"; fpsMonitor = GetComponent <FpsMonitor>(); if (fpsMonitor != null) { fpsMonitor.Add("Name", "IntegrationWithNatShareExample"); fpsMonitor.Add("performImageProcessingEveryTime", performImageProcessingEachTime.ToString()); fpsMonitor.Add("onFrameFPS", onFrameFPS.ToString("F1")); fpsMonitor.Add("drawFPS", drawFPS.ToString("F1")); fpsMonitor.Add("width", ""); fpsMonitor.Add("height", ""); fpsMonitor.Add("isFrontFacing", ""); fpsMonitor.Add("orientation", ""); } }
protected override void OnDestroy() { if (cameraSource != null) { cameraSource.Dispose(); cameraSource = null; } if (frameMatrix != null) { frameMatrix.Dispose(); } frameMatrix = null; Texture2D.Destroy(texture); texture = null; comicFilter.Dispose(); comicFilter = null; }
public virtual void Start() { // Load global camera benchmark settings. int width, height, fps; NatCamWithOpenCVForUnityExample.GetCameraResolution(out width, out height); NatCamWithOpenCVForUnityExample.GetCameraFps(out fps); previewResolution = new NatCamU.Core.CameraResolution(width, height); requestedFPS = fps; // Set the active camera NatCam.Camera = useFrontCamera ? DeviceCamera.FrontCamera : DeviceCamera.RearCamera; // Null checking if (!NatCam.Camera) { Debug.LogError("Camera is null. Consider using " + (useFrontCamera ? "rear" : "front") + " camera"); return; } if (!preview) { Debug.LogError("Preview RawImage has not been set"); return; } // Set the camera's preview resolution NatCam.Camera.PreviewResolution = previewResolution; // Set the camera framerate NatCam.Camera.Framerate = requestedFPS; NatCam.Play(); NatCam.OnStart += OnStart; NatCam.OnFrame += OnFrame; fpsMonitor = GetComponent <FpsMonitor> (); if (fpsMonitor != null) { fpsMonitor.Add("Name", "NatCamPreviewToMatExample"); fpsMonitor.Add("onFrameFPS", onFrameFPS.ToString("F1")); fpsMonitor.Add("drawFPS", drawFPS.ToString("F1")); fpsMonitor.Add("width", ""); fpsMonitor.Add("height", ""); fpsMonitor.Add("orientation", ""); } comicFilter = new ComicFilter(); }