/// <summary>
        /// To release the resources.
        /// </summary>
        protected override void ReleaseResources()
        {
            isInitWaiting = false;
            hasInitDone   = false;

            if (natCamDeviceCamera.IsRunning)
            {
                natCamDeviceCamera.StopPreview();
            }

            natCamDeviceCamera = null;
            preview            = null;

            pixelBuffer        = null;
            didUpdateThisFrame = false;

            if (frameMat != null)
            {
                frameMat.Dispose();
                frameMat = null;
            }
            if (rotatedFrameMat != null)
            {
                rotatedFrameMat.Dispose();
                rotatedFrameMat = null;
            }
        }
Пример #2
0
        public void StartPreview(DeviceCamera genericCamera, Action startCallback, Action frameCallback)
        {
            this.startCallback = startCallback;
            this.frameCallback = frameCallback;
            var camera = genericCamera as DeviceCameraLegacy;

            // Create preview
            if (PreviewTexture && this.camera != camera)
            {
                WebCamTexture.Destroy(PreviewTexture);
                PreviewTexture = null;
            }
            if (!PreviewTexture)
            {
                if (camera.PreviewResolution.x == 0)
                {
                    PreviewTexture = new WebCamTexture(camera.Device.name);
                }
                else
                {
                    PreviewTexture = new WebCamTexture(
                        camera.Device.name,
                        camera.PreviewResolution.x,
                        camera.PreviewResolution.y,
                        (int)Mathf.Max(camera.Framerate, 30)
                        );
                }
                this.camera = camera as DeviceCameraLegacy;
            }
            // Start preview
            firstFrame = true;
            PreviewTexture.Play();
            DispatchUtility.onFrame += Update;
        }
Пример #3
0
 public void StartPreview(DeviceCamera camera, Action startCallback, Action frameCallback)
 {
     this.startCallback = startCallback;
     this.frameCallback = frameCallback;
     NatCamBridge.StartPreview((IntPtr)(camera as DeviceCameraiOS));
     OnOrient();
 }
Пример #4
0
 public void Toggle()
 {
     Parameters.FlashMode = On ? FLASH_MODE_OFF : SupportedFlashModeOn;
     DeviceCamera.SetParameters(Parameters);
     IMInventory.IMApplication.camera = DeviceCamera;
     OnToggled();
 }
Пример #5
0
    public static void StartCamera()
    {
        _savedCounter = 0;
        DeviceCamera camera = DeviceCamera.RearCamera;

        if (camera == null)
        {
            camera = DeviceCamera.FrontCamera;
            if (camera == null)
            {
                Debug.LogWarning("No device camera found.");
                return;
            }
        }

        Vector2Int newSize = new Vector2Int(Mathf.FloorToInt(Screen.width / 2f), Mathf.FloorToInt(Screen.height / 2f));

        camera.PhotoResolution = camera.PreviewResolution = newSize;
        camera.Framerate       = 30;
        Debug.Log("New PhotoResolution size: " + newSize);

        NatCam.StartPreview(camera, OnStart);

        Clear();
    }
Пример #6
0
 public void StartPreview(DeviceCamera camera, Action startCallback, Action frameCallback)
 {
     this.startCallback = startCallback;
     this.frameCallback = frameCallback;
     OnOrient();
     natcam.Call("startPreview", (AndroidJavaObject)(camera as DeviceCameraAndroid));
 }
Пример #7
0
    public override void OnInspectorGUI()
    {
        GUI.enabled = false;
        EditorGUILayout.PropertyField(script, true, new GUILayoutOption[0]);
        GUI.enabled = true;

#if UNITY_WEBPLAYER || UNITY_WEBGL
        EditorGUILayout.HelpBox("This component does not work on web player/webGL platform", MessageType.Error);
#else
        this.serializedObject.Update();

        DeviceCamera deviceCamera = (DeviceCamera)target;

        EditorGUILayout.PropertyField(defaultDevice, new GUIContent("default Device"));
        EditorGUILayout.PropertyField(capWidth, new GUIContent("capture Width"));
        EditorGUILayout.PropertyField(capHeight, new GUIContent("capture Height"));
        EditorGUILayout.PropertyField(capFPS, new GUIContent("capture FPS"));
        EditorGUILayout.PropertyField(autoPlay, new GUIContent("auto Play"));
        EditorGUILayout.PropertyField(material, new GUIContent("Render Material"));
        EditorGUILayout.PropertyField(rawImage, new GUIContent("Render RawImage"));

        if (Application.isPlaying == true)
        {
            EditorGUILayout.LabelField(string.Format("Device Name: {0}", deviceCamera.deviceName));
            EditorGUILayout.LabelField(string.Format("Image Width: {0:d}", deviceCamera.Width));
            EditorGUILayout.LabelField(string.Format("Image Height: {0:d}", deviceCamera.Height));
            if (GUILayout.Button("Refresh Settings") == true)
            {
                deviceCamera.RefreshSettings();
            }
            if (GUILayout.Button("Change Device") == true)
            {
                deviceCamera.ChangeDevice();
            }
            if (deviceCamera.isPlaying == false)
            {
                if (GUILayout.Button("Play") == true)
                {
                    deviceCamera.Play();
                }
            }
            else
            {
                if (GUILayout.Button("Pause") == true)
                {
                    deviceCamera.Pause();
                }
            }
            if (GUILayout.Button("Stop") == true)
            {
                deviceCamera.Stop();
            }
        }

        this.serializedObject.ApplyModifiedProperties();
#endif
    }
Пример #8
0
    // Use this for initialization
    IEnumerator Start()
    {
        // When the app start, ask for the authorization to use the webcam
        yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam));

        if (Application.HasUserAuthorization(UserAuthorization.WebCam))
        {
            mCamera = new DeviceCamera();
        }
    }
Пример #9
0
    // Use this for initialization
    IEnumerator Start()
    {
        yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam));

        if (Application.HasUserAuthorization(UserAuthorization.WebCam))
        {
            mCamera = new DeviceCamera();
            StartWork();
        }
    }
Пример #10
0
 // Use this for initialization
 private void Start()
 {
     // Start camera preview
     deviceCamera = useFrontCamera ? DeviceCamera.FrontCamera : DeviceCamera.RearCamera;
     if (!deviceCamera)
     {
         Debug.LogError("Camera is null. Consider using " + (useFrontCamera ? "rear" : "front") + " camera");
         return;
     }
     deviceCamera.StartPreview(OnStart);
 }
Пример #11
0
 void Start()
 {
     deviceCamera = useFrontCamera ? DeviceCamera.FrontCamera : DeviceCamera.RearCamera;
     if (!deviceCamera)
     {
         Debug.LogError("Camera is null. Consider using " + (useFrontCamera ? "rear" : "front") + " camera");
         return;
     }
     deviceCamera.PreviewResolution = new Vector2Int(640, 480);
     deviceCamera.StartPreview(OnStart, OnFrame);
 }
Пример #12
0
        public void SwitchCamera()
        {
            if (camera.IsRunning)
            {
                camera.StopPreview();
            }

            cameraIndex = ++cameraIndex % WebCamTexture.devices.Length;
            camera      = DeviceCamera.Cameras [cameraIndex];
            camera.PreviewResolution = new Vector2Int(requestedWidth, requestedHeight);
            camera.Framerate         = requestedFramerate;
            StartPreview(startCallback, frameCallback);
        }
    public void ResizeByWebCam(DeviceCamera webCam)
    {
#if UNITY_EDITOR
        float tmpW = transform.localScale.x;
        float tmpH = transform.localScale.z;

        if (tmpW > tmpH)
        {
            tmpH = tmpW * webCam.getSize().y / webCam.getSize().x;
        }
        else
        {
            tmpW = tmpH * webCam.getSize().x / webCam.getSize().y;
        }

        transform.localScale = new Vector3(tmpW, transform.localScale.y, tmpH);
#endif
    }
Пример #14
0
        public NatCamSource(int width, int height, int framerate, bool front)
        {
            this.requestedWidth     = width;
            this.requestedHeight    = height;
            this.requestedFramerate = framerate;

            for (; cameraIndex < DeviceCamera.Cameras.Length; cameraIndex++)
            {
                if (DeviceCamera.Cameras [cameraIndex].IsFrontFacing == front)
                {
                    break;
                }
            }

            if (cameraIndex == DeviceCamera.Cameras.Length)
            {
                Debug.LogError("Camera is null. Consider using " + (front ? "rear" : "front") + " camera.");
                return;
            }

            camera = DeviceCamera.Cameras [cameraIndex];
            camera.PreviewResolution = new Vector2Int(width, height);
            camera.Framerate         = framerate;
        }
Пример #15
0
 void Start()
 {
     webcam           = new DeviceCamera(isUseEasyWebCam);
     e_CameraPlaneObj = transform.Find("CameraPlane").gameObject;
     //StartWork ();
 }
Пример #16
0
    public void StartCamera()
    {
        //   if (NatCamCamera == null) {
        //      Debug.Log("entra aqui?");
        // NatCamCamera = DeviceCamera.FrontCamera;
        //NatCamCamera.StartPreview(OnStart, OnFrame);
        //   NatCamCamera.StartPreview(OnStart);
        //  }


        Debug.Log("Kauel: StartCamera()");

        singleton = this;

        Mode = KameraMode.Camera;

        /////////////////////////////////////////////////////   RawImageCamera.texture = previewTexture;
        //RawImageCamera.texture = preview;
        //previewTexture = preview;

#if UNITY_EDITOR
        NatCamCamera = DeviceCamera.Cameras[0];
        ////////////////////////////////////////////////////// CamCreated = true;
#elif UNITY_ANDROID
        Debug.Log("Kauel: Android");

        NatCamCamera = DeviceCamera.RearCamera;


        /*  if (NatCam.HasPermissions) {
         *
         *    Debug.Log("Kauel: NatCam permissions OK :)");
         *
         * } else {
         *
         *    Debug.Log("Kauel: NatCam has NO PERMISSIONS!!!");
         *
         * }
         *
         * NatCamCamera = CameraDevice.GetDevices()[0];
         */

        // NatCamCamera = DeviceCamera.Cameras[0];
        if (!CamCreated)
        {
            //   CamCreated = true;
            //   NatCamCamera = DeviceCamera.Cameras[0];
            //   NatCamCamera = DeviceCamera.RearCamera;
            //   NatCamCamera.PreviewResolution.Set(1920, 1080);
            //   NatCamCamera.PhotoResolution.Set(1920, 1080);
            //   Debug.Log("Kauel: CamCreated");

            // NatCam.Camera = DeviceCamera.RearCamera;
            // var NatCamCamera = CameraDevice.GetDevices()[0];
            //  NatCamCamera = CameraDevice.GetDevices()[0];

            // NatCamCamera = DeviceCamera.RearCamera;

            //  NatCamCamera.SetPreviewResolution(ResolutionPreset.FullHD);
            //  NatCamCamera.SetPhotoResolution(ResolutionPreset.FullHD);
            //  NatCamCamera.SetFramerate(FrameratePreset.Default);

            //  Debug.Log("Kauel: CamCreated");
        }
#elif UNITY_IOS
        Debug.Log("Kauel: iOS");



        if (!CamCreated)
        {
            CamCreated = true;

            //NatCam.Camera = DeviceCamera.RearCamera;
            var NatCam.Camera = CameraDevice.GetDevices()[0];

            NatCam.Camera.SetPreviewResolution(ResolutionPreset.FullHD);

            NatCam.Camera.SetPhotoResolution(ResolutionPreset.FullHD);

            Debug.Log("Kauel: CamCreated");
        }
#endif



        NatCamCamera.StartPreview(OnStart);

        PanelSelector.ShowOnlyThisPanel(0); //Solo el panel de fotos

        Debug.Log("Kauel: StartCamera() ha finalizado");
    }
Пример #17
0
        public CameraSensor()
        {
            recordingClock = new RealtimeClock();

            deviceCamera = DeviceCamera.FrontCamera;
        }
Пример #18
0
 public void SwitchCamera()
 {
     deviceCamera.StopPreview();
     deviceCamera = deviceCamera.IsFrontFacing ? DeviceCamera.RearCamera : DeviceCamera.FrontCamera;
     deviceCamera.StartPreview(OnStart);
 }
        /// <summary>
        /// Initializes this instance by coroutine.
        /// </summary>
        protected override IEnumerator _Initialize()
        {
            if (hasInitDone)
            {
                ReleaseResources();

                if (onDisposed != null)
                {
                    onDisposed.Invoke();
                }
            }

            isInitWaiting = true;

            // Creates the camera
            if (!String.IsNullOrEmpty(requestedDeviceName))
            {
                int requestedDeviceIndex = -1;
                if (Int32.TryParse(requestedDeviceName, out requestedDeviceIndex))
                {
                    if (requestedDeviceIndex >= 0 && requestedDeviceIndex < DeviceCamera.Cameras.Length)
                    {
                        natCamDeviceCamera = DeviceCamera.Cameras [requestedDeviceIndex];
                    }
                }
                else
                {
                    for (int cameraIndex = 0; cameraIndex < DeviceCamera.Cameras.Length; cameraIndex++)
                    {
                        if (DeviceCamera.Cameras [cameraIndex].UniqueID == requestedDeviceName)
                        {
                            natCamDeviceCamera = DeviceCamera.Cameras [cameraIndex];
                            break;
                        }
                    }
                }
                if (natCamDeviceCamera == null)
                {
                    Debug.Log("Cannot find camera device " + requestedDeviceName + ".");
                }
            }

            if (natCamDeviceCamera == null)
            {
                natCamDeviceCamera = requestedIsFrontFacing ? DeviceCamera.FrontCamera : DeviceCamera.RearCamera;
            }

            if (natCamDeviceCamera == null)
            {
                if (DeviceCamera.Cameras.Length > 0)
                {
                    natCamDeviceCamera = DeviceCamera.Cameras [0];
                }
                else
                {
                    isInitWaiting = false;

                    if (onErrorOccurred != null)
                    {
                        onErrorOccurred.Invoke(ErrorCode.CAMERA_DEVICE_NOT_EXIST);
                    }

                    yield break;
                }
            }

            natCamDeviceCamera.Framerate = (int)requestedFPS;

            // Set the camera's preview resolution
            natCamDeviceCamera.PreviewResolution = new Vector2Int(requestedWidth, requestedHeight);

            // Starts the camera
            // Register callback for when the preview starts
            // Register for preview updates
            natCamDeviceCamera.StartPreview(OnStart, OnFrame);

            int  initFrameCount = 0;
            bool isTimeout      = false;

            while (true)
            {
                if (initFrameCount > timeoutFrameCount)
                {
                    isTimeout = true;
                    break;
                }
                else if (didUpdateThisFrame)
                {
                    Debug.Log("NatCamPreviewToMatHelper:: " + "UniqueID:" + natCamDeviceCamera.UniqueID + " width:" + preview.width + " height:" + preview.height + " fps:" + natCamDeviceCamera.Framerate
                              + " isFrongFacing:" + natCamDeviceCamera.IsFrontFacing);

                    frameMat = new Mat(preview.height, preview.width, CvType.CV_8UC4);

                    screenOrientation = Screen.orientation;
                    screenWidth       = Screen.width;
                    screenHeight      = Screen.height;

                    if (rotate90Degree)
                    {
                        rotatedFrameMat = new Mat(preview.width, preview.height, CvType.CV_8UC4);
                    }

                    isInitWaiting = false;
                    hasInitDone   = true;
                    initCoroutine = null;

                    if (onInitialized != null)
                    {
                        onInitialized.Invoke();
                    }

                    break;
                }
                else
                {
                    initFrameCount++;
                    yield return(null);
                }
            }

            if (isTimeout)
            {
                natCamDeviceCamera.StopPreview();

                isInitWaiting = false;
                initCoroutine = null;

                if (onErrorOccurred != null)
                {
                    onErrorOccurred.Invoke(ErrorCode.TIMEOUT);
                }
            }
        }