예제 #1
0
    async void Start()
    {
        //initialization
        photoPanel.gameObject.SetActive(false);
        captureButton.gameObject.SetActive(true);
        decisionButton.gameObject.SetActive(false);
        oneMoreButton.gameObject.SetActive(false);

        // Request camera permissions
        // if (!await MediaDeviceQuery.RequestPermissions<CameraDevice>()) {
        //     Debug.LogError("User did not grant camera permissions");
        //     return;
        // }
        // Create a device query for device cameras
        // Use `GenericCameraDevice` so we also capture WebCamTexture cameras
        var criterion = MediaDeviceQuery.Criteria.RearFacing;
        var query     = new MediaDeviceQuery(criterion);

        device = query.currentDevice as CameraDevice;
        var previewTexture = await device.StartRunning();

        Debug.Log($"Started camera preview with resolution {previewTexture.width}x{previewTexture.height}");
        // Display preview texture
        previewPanel.texture            = previewTexture;
        previewAspectFitter.aspectRatio = previewTexture.width / (float)previewTexture.height;
        // Set UI state
    }
예제 #2
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", "");
            }
        }
예제 #3
0
    // Start is called before the first frame update
    async void Start()
    {
        var Fquery = new MediaDeviceQuery(MediaDeviceQuery.Criteria.FrontFacing);

        frontDevice = (CameraDevice)Fquery.currentDevice;
        var Rquery = new MediaDeviceQuery(MediaDeviceQuery.Criteria.RearFacing);

        rearDevice = (CameraDevice)Rquery.currentDevice;

        var previewTexture = await rearDevice.StartRunning();

        BGImage.texture = previewTexture;
    }
예제 #4
0
        async void Start()
        {
            // Request mic permissions
            if (!await MediaDeviceQuery.RequestPermissions <AudioDevice>())
            {
                Debug.LogError("User did not grant microphone permissions");
                return;
            }
            // Create a media device query for audio devices
            var deviceQuery = new MediaDeviceQuery(MediaDeviceQuery.Criteria.AudioDevice);

            // Get the device
            device = deviceQuery.currentDevice as AudioDevice;
            Debug.Log($"{device}");
        }
예제 #5
0
        async void Start()
        {
            // Request camera permissions
            if (!await MediaDeviceQuery.RequestPermissions <CameraDevice>())
            {
                Debug.LogError("User did not grant camera permissions");
                return;
            }
            // Create a device query for device cameras
            // Use `GenericCameraDevice` so we also capture WebCamTexture cameras
            query = new MediaDeviceQuery(Criteria.GenericCameraDevice);
            // Start camera preview
            var device         = query.currentDevice as ICameraDevice;
            var previewTexture = await device.StartRunning();

            Debug.Log($"Started camera preview with resolution {previewTexture.width}x{previewTexture.height}");
            // Display preview texture
            previewPanel.texture            = previewTexture;
            previewAspectFitter.aspectRatio = previewTexture.width / (float)previewTexture.height;
            // Set UI state
            switchIcon.color = query.devices.Length > 1 ? Color.white : Color.gray;
            flashIcon.color  = device is CameraDevice cameraDevice && cameraDevice.flashSupported ? Color.white : Color.gray;
        }
예제 #6
0
        public NatDeviceCamSource(int width, int height, int framerate = 30, bool front = false)
        {
            requestedWidth     = width;
            requestedHeight    = height;
            requestedFramerate = framerate;

            // Create a device query for device cameras
            // Use `GenericCameraDevice` so we also capture WebCamTexture cameras
            deviceQuery = new MediaDeviceQuery(MediaDeviceQuery.Criteria.GenericCameraDevice);

            // Pick camera
            if (deviceQuery.devices.Length == 0)
            {
                Debug.LogError("Camera device does not exist.");
                return;
            }

            for (var i = 0; i < deviceQuery.devices.Length; i++)
            {
                activeCamera = deviceQuery.currentDevice as ICameraDevice;
                if (activeCamera.frontFacing == front)
                {
                    break;
                }
                deviceQuery.Advance();
            }

            if (activeCamera == null || activeCamera.frontFacing != front)
            {
                Debug.LogError("Camera is null. Consider using " + (front ? "rear" : "front") + " camera.");
                activeCamera = null;
                return;
            }

            activeCamera.previewResolution = (width : requestedWidth, height : requestedHeight);
            activeCamera.frameRate         = requestedFramerate;
        }