protected override void OnStart()
        {
            settingInfo1 = "- resolution: " + cameraSource.width + "x" + cameraSource.height;

            // Create matrix
            if (frameMatrix != null)
            {
                frameMatrix.Dispose();
            }
            frameMatrix = new Mat(cameraSource.height, cameraSource.width, CvType.CV_8UC4);
            // Create texture
            if (texture != null)
            {
                Texture2D.Destroy(texture);
            }
            texture = new Texture2D(
                cameraSource.width,
                cameraSource.height,
                TextureFormat.RGBA32,
                false,
                false
                );
            // Display preview
            rawImage.texture         = texture;
            aspectFitter.aspectRatio = cameraSource.width / (float)cameraSource.height;
            Debug.Log("NatDevice camera source started with resolution: " + cameraSource.width + "x" + cameraSource.height + " isFrontFacing: " + cameraSource.isFrontFacing);

            if (fpsMonitor != null)
            {
                fpsMonitor.Add("width", cameraSource.width.ToString());
                fpsMonitor.Add("height", cameraSource.height.ToString());
                fpsMonitor.Add("isFrontFacing", cameraSource.isFrontFacing.ToString());
                fpsMonitor.Add("orientation", Screen.orientation.ToString());
            }
        }
Esempio n. 2
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", "");
            }
        }
Esempio n. 4
0
        protected override void OnStart()
        {
            base.OnStart();

            // Create pixel buffer
            pixelBuffer = new byte[cameraSource.width * cameraSource.height * 4];
            // Create texture
            if (texture != null)
            {
                Texture2D.Destroy(texture);
            }
            texture = new Texture2D(
                cameraSource.width,
                cameraSource.height,
                TextureFormat.RGBA32,
                false,
                false
                );
            // Display texture
            rawImage.texture         = texture;
            aspectFitter.aspectRatio = cameraSource.width / (float)cameraSource.height;
            Debug.Log("WebCam camera source started with resolution: " + cameraSource.width + "x" + cameraSource.height + " isFrontFacing: " + cameraSource.isFrontFacing);

            if (fpsMonitor != null)
            {
                fpsMonitor.Add("width", cameraSource.width.ToString());
                fpsMonitor.Add("height", cameraSource.height.ToString());
                fpsMonitor.Add("isFrontFacing", cameraSource.isFrontFacing.ToString());
                fpsMonitor.Add("orientation", Screen.orientation.ToString());
            }
        }
Esempio n. 5
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", "");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Raises the webcam texture to mat helper initialized event.
        /// </summary>
        public void OnWebCamTextureToMatHelperInitialized()
        {
            Debug.Log("OnWebCamTextureToMatHelperInitialized");

            Mat webCamTextureMat = webCamTextureToMatHelper.GetMat();

            texture = new Texture2D(webCamTextureMat.cols(), webCamTextureMat.rows(), TextureFormat.RGBA32, false);
            Utils.fastMatToTexture2D(webCamTextureMat, texture);

            gameObject.GetComponent <Renderer>().material.mainTexture = texture;

            gameObject.transform.localScale = new Vector3(webCamTextureMat.cols(), webCamTextureMat.rows(), 1);
            Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);

            if (fpsMonitor != null)
            {
                fpsMonitor.Add("width", webCamTextureToMatHelper.GetWidth().ToString());
                fpsMonitor.Add("height", webCamTextureToMatHelper.GetHeight().ToString());
                fpsMonitor.Add("isFrontFacing", webCamTextureToMatHelper.IsFrontFacing().ToString());
                fpsMonitor.Add("rotate90Degree", webCamTextureToMatHelper.rotate90Degree.ToString());
                fpsMonitor.Add("flipVertical", webCamTextureToMatHelper.flipVertical.ToString());
                fpsMonitor.Add("flipHorizontal", webCamTextureToMatHelper.flipHorizontal.ToString());
                fpsMonitor.Add("orientation", Screen.orientation.ToString());
            }


            float width  = webCamTextureMat.width();
            float height = webCamTextureMat.height();

            float widthScale  = (float)Screen.width / width;
            float heightScale = (float)Screen.height / height;

            if (widthScale < heightScale)
            {
                Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
            }
            else
            {
                Camera.main.orthographicSize = height / 2;
            }

            UpdateNatDeviceCameraProps(webCamTextureToMatHelper);
        }
Esempio n. 7
0
        protected override void OnStart()
        {
            base.OnStart();

            // Create pixel buffer
            pixelBuffer = new byte[cameraSource.width * cameraSource.height * 4];
            // Create texture
            if (texture != null)
            {
                Texture2D.Destroy(texture);
            }
            texture = new Texture2D(
                cameraSource.width,
                cameraSource.height,
                TextureFormat.RGBA32,
                false,
                false
                );
            // Display preview
            rawImage.texture         = texture;
            aspectFitter.aspectRatio = cameraSource.width / (float)cameraSource.height;
            Debug.Log("NatDevice camera source started with resolution: " + cameraSource.width + "x" + cameraSource.height + " isFrontFacing: " + cameraSource.isFrontFacing);
            // Log camera properties
            var cameraProps = new Dictionary <string, string>();
            var camera      = cameraSource.activeCamera as CameraDevice;

            if (camera != null)
            {
                cameraProps.Add("exposureBias", camera.exposureBias.ToString());
                cameraProps.Add("exposureLock", camera.exposureLock.ToString());
                cameraProps.Add("exposureLockSupported", camera.exposureLockSupported.ToString());
                cameraProps.Add("exposureRange", camera.exposureRange.max + "x" + camera.exposureRange.min);
                cameraProps.Add("fieldOfView", camera.fieldOfView.width + "x" + camera.fieldOfView.height);
                cameraProps.Add("flashMode", camera.flashMode.ToString());
                cameraProps.Add("flashSupported", camera.flashSupported.ToString());
                cameraProps.Add("focusLock", camera.focusLock.ToString());
                cameraProps.Add("focusLockSupported", camera.focusLockSupported.ToString());
                cameraProps.Add("frameRate", camera.frameRate.ToString());
                cameraProps.Add("frontFacing", camera.frontFacing.ToString());
                cameraProps.Add("photoResolution", camera.photoResolution.width + "x" + camera.photoResolution.height);
                cameraProps.Add("previewResolution", camera.previewResolution.width + "x" + camera.previewResolution.height);
                cameraProps.Add("running", camera.running.ToString());
                cameraProps.Add("torchEnabled", camera.torchEnabled.ToString());
                cameraProps.Add("torchSupported", camera.torchSupported.ToString());
                cameraProps.Add("uniqueID", camera.uniqueID.ToString());
                cameraProps.Add("whiteBalanceLock", camera.whiteBalanceLock.ToString());
                cameraProps.Add("whiteBalanceLockSupported", camera.whiteBalanceLockSupported.ToString());
                cameraProps.Add("zoomRange", camera.zoomRange.max + "x" + camera.zoomRange.min);
                cameraProps.Add("zoomRatio", camera.zoomRatio.ToString());
            }

            Debug.Log("# Active Camera Properties #####################");
            foreach (string key in cameraProps.Keys)
            {
                Debug.Log(key + ": " + cameraProps[key]);
            }
            Debug.Log("#######################################");

            if (fpsMonitor != null)
            {
                fpsMonitor.Add("width", cameraSource.width.ToString());
                fpsMonitor.Add("height", cameraSource.height.ToString());
                fpsMonitor.Add("orientation", Screen.orientation.ToString());

                fpsMonitor.boxWidth  = 240;
                fpsMonitor.boxHeight = 800;
                fpsMonitor.LocateGUI();

                foreach (string key in cameraProps.Keys)
                {
                    fpsMonitor.Add(key, cameraProps[key]);
                }
            }
        }