コード例 #1
0
        protected override async void Start()
        {
            base.Start();

            // Load global camera benchmark settings.
            int width, height, framerate;

            NatDeviceWithOpenCVForUnityExample.CameraConfiguration(out width, out height, out framerate);
            // Create camera source
            cameraSource = new WebCamMatSource(width, height, framerate, useFrontCamera);
            if (!cameraSource.activeCamera)
            {
                cameraSource = new WebCamMatSource(width, height, framerate, !useFrontCamera);
            }
            await cameraSource.StartRunning(OnStart, OnFrame);

            fpsMonitor = GetComponent <FpsMonitor>();
            if (fpsMonitor != null)
            {
                fpsMonitor.Add("Name", "WebCamTextureToMatExample");
                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 async void Start()
        {
            base.Start();

            // Load global camera benchmark settings.
            int width, height, framerate;

            NatDeviceWithOpenCVForUnityExample.CameraConfiguration(out width, out height, out framerate);
            // Create camera source
            cameraSource = new NatDeviceCamSource(width, height, framerate, useFrontCamera);
            if (cameraSource.activeCamera == null)
            {
                cameraSource = new NatDeviceCamSource(width, height, framerate, !useFrontCamera);
            }
            await cameraSource.StartRunning(OnStart, OnFrame);

            // Create comic filter
            comicFilter = new ComicFilter();

            exampleTitle      = "[NatDeviceWithOpenCVForUnity Example] (" + NatDeviceWithOpenCVForUnityExample.GetNatDeviceVersion() + ")";
            exampleSceneTitle = "- Integration With NatShare Example";

            fpsMonitor = GetComponent <FpsMonitor>();
            if (fpsMonitor != null)
            {
                fpsMonitor.Add("Name", "IntegrationWithNatShareExample");
                fpsMonitor.Add("onFrameFPS", onFrameFPS.ToString("F1"));
                fpsMonitor.Add("drawFPS", drawFPS.ToString("F1"));
                fpsMonitor.Add("width", "");
                fpsMonitor.Add("height", "");
                fpsMonitor.Add("isFrontFacing", "");
                fpsMonitor.Add("orientation", "");
            }
        }
コード例 #3
0
        protected override async void Start()
        {
            base.Start();

#if !UNITY_STANDALONE_WIN && !UNITY_EDITOR
            // Request camera permissions
            if (!await MediaDeviceQuery.RequestPermissions <CameraDevice>())
            {
                Debug.LogError("User did not grant camera permissions");
                return;
            }
#endif

            // Load global camera benchmark settings.
            int width, height, framerate;
            NatDeviceWithOpenCVForUnityExample.CameraConfiguration(out width, out height, out framerate);
            // Create camera source
            cameraSource = new NatDeviceCamSource(width, height, framerate, useFrontCamera);
            if (cameraSource.activeCamera == null)
            {
                cameraSource = new NatDeviceCamSource(width, height, framerate, !useFrontCamera);
            }
            await cameraSource.StartRunning(OnStart, OnFrame);

            fpsMonitor = GetComponent <FpsMonitor>();
            if (fpsMonitor != null)
            {
                fpsMonitor.Add("Name", "NatDeviceCamPreviewOnlyExample");
                fpsMonitor.Add("onFrameFPS", onFrameFPS.ToString("F1"));
                fpsMonitor.Add("drawFPS", drawFPS.ToString("F1"));
                fpsMonitor.Add("width", "");
                fpsMonitor.Add("height", "");
                fpsMonitor.Add("orientation", "");
            }
        }
コード例 #4
0
        // Use this for initialization
        void Start()
        {
            fpsMonitor = GetComponent <FpsMonitor>();

            webCamTextureToMatHelper = gameObject.GetComponent <NatDeviceCamPreviewToMatHelper>();
            int width, height;

            Dimensions(requestedResolution, out width, out height);
            webCamTextureToMatHelper.requestedWidth  = width;
            webCamTextureToMatHelper.requestedHeight = height;
            webCamTextureToMatHelper.requestedFPS    = (int)requestedFPS;
            webCamTextureToMatHelper.Initialize();

            // Update GUI state
            requestedResolutionDropdown.value = (int)requestedResolution;
            string[] enumNames = System.Enum.GetNames(typeof(FPSPreset));
            int      index     = Array.IndexOf(enumNames, requestedFPS.ToString());

            requestedFPSDropdown.value = index;
            rotate90DegreeToggle.isOn  = webCamTextureToMatHelper.rotate90Degree;
            flipVerticalToggle.isOn    = webCamTextureToMatHelper.flipVertical;
            flipHorizontalToggle.isOn  = webCamTextureToMatHelper.flipHorizontal;
        }