Exemplo n.º 1
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);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 public void StartPreview(Action startCallback, Action frameCallback)
 {
     this.startCallback = startCallback;
     this.frameCallback = frameCallback;
     camera.StartPreview(
         (Texture preview) => {
         width        = preview.width;
         height       = preview.height;
         this.preview = preview;
         sourceBuffer = new byte[width * height * 4];
         startCallback();
     },
         frameCallback
         );
 }
Exemplo n.º 4
0
    public void PlayCamera()
    {
        Debug.Log("Kauel: PlayCamera()");

        if (Mode == KameraMode.Camera)
        {
            Debug.Log("KAmera Mode");

            // Free the photo texture
            Texture2D.Destroy(photo); photo = null;
            NatCamCamera.StopPreview();
            NatCamCamera.StartPreview(OnStart);

            RawImageCamera.texture = previewTexture;
        }
    }
Exemplo n.º 5
0
        public void Start()
        {
            m_IsReady = false;

            // Start recording
            recordingClock = new RealtimeClock();
            videoRecorder  = new MP4Recorder(
                videoWidth,
                videoHeight,
                15,
                0,
                0,
                FileLocationCB,
                "facecam.mp4",
                (int)(480 * 540 * 11.4f)
                );

            deviceCamera.Framerate = 15;
            deviceCamera.StartPreview(OnStart, OnFrame);
        }
Exemplo n.º 6
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");
    }
        // Update is called once per frame
        protected override void Update()
        {
            if (hasInitDone)
            {
                // Catch the orientation change of the screen and correct the mat image to the correct direction.
                if (screenOrientation != Screen.orientation && (screenWidth != Screen.width || screenHeight != Screen.height))
                {
                    if (!natCamDeviceCamera.IsRunning)
                    {
                        bool isRotatedFrame = false;
                        DeviceOrientation oldOrientation = (DeviceOrientation)(int)screenOrientation;
                        DeviceOrientation newOrientation = (DeviceOrientation)(int)Screen.orientation;
                        if (oldOrientation == DeviceOrientation.Portrait ||
                            oldOrientation == DeviceOrientation.PortraitUpsideDown)
                        {
                            if (newOrientation == DeviceOrientation.LandscapeLeft ||
                                newOrientation == DeviceOrientation.LandscapeRight)
                            {
                                isRotatedFrame = true;
                            }
                        }
                        else if (oldOrientation == DeviceOrientation.LandscapeLeft ||
                                 oldOrientation == DeviceOrientation.LandscapeRight)
                        {
                            if (newOrientation == DeviceOrientation.Portrait ||
                                newOrientation == DeviceOrientation.PortraitUpsideDown)
                            {
                                isRotatedFrame = true;
                            }
                        }

                        if (isRotatedFrame)
                        {
                            int width  = frameMat.width();
                            int height = frameMat.height();

                            if (frameMat != null)
                            {
                                frameMat.Dispose();
                                frameMat = null;
                            }
                            if (rotatedFrameMat != null)
                            {
                                rotatedFrameMat.Dispose();
                                rotatedFrameMat = null;
                            }

                            frameMat = new Mat(width, height, CvType.CV_8UC4, new Scalar(0, 0, 0, 255));

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

                    #if UNITY_IOS && !UNITY_EDITOR
                    if (onDisposed != null)
                    {
                        onDisposed.Invoke();
                    }
                    if (onInitialized != null)
                    {
                        onInitialized.Invoke();
                    }
                    #elif UNITY_ANDROID && !UNITY_EDITOR
                    if (natCamDeviceCamera.IsRunning)
                    {
                        natCamDeviceCamera.StopPreview();
                        natCamDeviceCamera.StartPreview(OnStart, OnFrame);
                    }
                    else
                    {
                        if (onDisposed != null)
                        {
                            onDisposed.Invoke();
                        }
                        if (onInitialized != null)
                        {
                            onInitialized.Invoke();
                        }
                    }
                    #endif

                    screenOrientation = Screen.orientation;
                    screenWidth       = Screen.width;
                    screenHeight      = Screen.height;
                }
                else
                {
                    screenWidth  = Screen.width;
                    screenHeight = Screen.height;
                }
            }
        }
Exemplo n.º 8
0
 public void SwitchCamera()
 {
     deviceCamera.StopPreview();
     deviceCamera = deviceCamera.IsFrontFacing ? DeviceCamera.RearCamera : DeviceCamera.FrontCamera;
     deviceCamera.StartPreview(OnStart);
 }