Пример #1
0
    /**
     *
     * Take photo function
     *
     */
    public void TakePhoto()
    {
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) {
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                if (result.success)
                {
                    // Take a picture
                    photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
                    string filename = string.Format(@"CapturedImage{0}_n.jpg", Time.time);
                    string filePath = System.IO.Path.Combine(Application.dataPath + "/LocalData/Image/", filename);
                    Debug.Log(filePath);

                    photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
                }
                else
                {
                    Debug.LogError("Unable to start photo mode!");
                }
            });
        });
    }
Пример #2
0
    private void Update()
    {
        /*
         * if (++cycleCount >= 2 && sendFinished == true)
         * {
         *  if (photoCaptureObject != null)
         *  {
         *      //photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
         *      photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
         *  }
         *
         *  cycleCount = 0;
         * }*/

        targetTime -= Time.deltaTime;

        if (targetTime <= 0.0f)
        {
            if (state == 0)
            {
                if (CONTINUAL)
                {
                    photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
                    targetTime = 5f; //timeout time
                    state      = -1;
                }
                else
                {
                    if (!picture_taken)
                    {
                        photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
                        picture_taken = true;
                    }
                    stimulusManager.GazeShift();
                    targetTime = 0.5f;
                    state      = 1;
                }
            }

            else if (state == -1)
            {
                state = 0;
            }

            else if (state == 1)
            {
                stimulusManager.StartStimulating();
                targetTime = STIMULATION_DURATION;
                state      = 2;
            }
            else if (state == 2)
            {
                stimulusManager.StopStimulating();
                state = 0;
            }
        }
    }
Пример #3
0
 void TakePicture()
 {
     capturedImageCount++;
     Debug.Log(string.Format("Taking Picture ({0}/{1})...", capturedImageCount, maxphoto));
     string filename = string.Format(@"QRImage{0}.jpg", capturedImageCount);
     string fPath = System.IO.Path.Combine(Application.persistentDataPath, filename);
     Debug.Log(fPath);
     photoCaptureObject.TakePhotoAsync(fPath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
 }
Пример #4
0
 /// <summary>
 /// Called when the photo mode starts, if it's successfull then it'll start taking photos
 /// </summary>
 /// <param name="result">Result of the intent of starting the camera</param>
 private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
 {
     if (result.success)
     {
         photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
     }
     else
     {
         Debug.LogError("Unable to start photo mode!");
     }
 }
Пример #5
0
 public bool TakePhoto(Action <Matrix4x4, Matrix4x4, Texture2D> photoAction)
 {
     if (CanTakePhoto)
     {
         return(false);
     }
     CanTakePhoto = true;
     _takePhotoActionCopyToTexture2D = photoAction;
     _photoCaptureObj.TakePhotoAsync(OnPhotoCapturedCopyToTexture);
     return(true);
 }
Пример #6
0
 void onPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
 {
     if (result.success)
     {
         //saveToFile();
         photoCapture.TakePhotoAsync(onCapturedPhotoToMemory);
     }
     else
     {
         Debug.LogError("Unable to start photo mode");
     }
 }
Пример #7
0
 /// <summary>
 /// 开始照相模式后调用
 /// </summary>
 void OnPhotoModeStarted_HOLO(PhotoCapture.PhotoCaptureResult result)
 {
     if (result.success)
     {
         Debug.Log("照相模式开始");
         photo_capture.TakePhotoAsync(OnProcessFrame);
     }
     else
     {
         Debug.Log("开启照相模式失败");
     }
 }
Пример #8
0
 void UpdateCameraMatrices()
 {
     if (photoCaptureObject != null)
     {
         photoCaptureObject.TakePhotoAsync(UpdateCameraMatricesWithCapturedPhoto);
     }
     else
     {
         Matrix4x4 V = camera.worldToCameraMatrix;
         Matrix4x4 P = camera.projectionMatrix;
         currentInverseVP = (P * V).inverse;
     }
 }
Пример #9
0
    /// <summary>
    /// Take a photo and save it to a temporary application folder.
    /// </summary>
    public void TakePhoto()
    {
        if (isReady)
        {
            string file = string.Format(@"Image_{0:yyyy-MM-dd_hh-mm-ss-tt}.jpg", DateTime.Now);
            currentImagePath = System.IO.Path.Combine(Application.persistentDataPath, file);

            capture.TakePhotoAsync(currentImagePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
            capture.TakePhotoAsync(OnCapturedPhotoToTexture);
        }
        else
        {
            Debug.LogWarning("The camera is not yet ready.");
        }
    }
Пример #10
0
    // Update is called once per frame
    private void ExecuteImageCaptureAndAnalysis()
    {
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
        Texture2D  targetTexture    = new Texture2D(cameraResolution.width, cameraResolution.height);

        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject)
        {
            photoCaptureObject = captureObject;

            CameraParameters c       = new CameraParameters();
            c.hologramOpacity        = 0.0f;
            c.cameraResolutionWidth  = targetTexture.width;
            c.cameraResolutionHeight = targetTexture.height;
            c.pixelFormat            = CapturePixelFormat.BGRA32;

            captureObject.StartPhotoModeAsync(c, delegate(PhotoCapture.PhotoCaptureResult result)
            {
                string filename = string.Format(@"CapturedImage{0}.jpg", tapsCount);
                string filepath = Path.Combine(Application.persistentDataPath, filename);
                VisionManager.instance.imagePath = filepath;
                Debug.Log("Saving Photo into file:" + filepath);
                photoCaptureObject.TakePhotoAsync(filepath, PhotoCaptureFileOutputFormat.JPG, OnCapturePhotoToDisk);
                currentlyCapturing = false;
            }
                                              );
        }
                                 );
    }
Пример #11
0
    public void change()
    {
        Log.Info("change");

        //        Renderer r = gameObject.GetComponent<Renderer>();
        //        r.material.SetColor(1, Color.yellow);

        TrackerManager.Instance.GetTracker <ObjectTracker>().Stop();
        CameraDevice.Instance.Stop();

        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) {
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                // Take a picture
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });
    }
Пример #12
0
    public void OnInputClicked(InputClickedEventData eventData)
    {
        //在整个场景中点击均有效
        //InputManager.Instance.AddGlobalListener(gameObject);

        PhotoCapture.CreateAsync(true, delegate(PhotoCapture captureObject)
        {
            photoCaptureObj = captureObject;

            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 1.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            photoCaptureObj.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result)
            {
                photoCaptureObj.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });

        capturingPhoto = true;

        Debug.Log("Photo Capture CreateAsync Succeed!");
    }
Пример #13
0
    /// <summary>
    /// Begin process of Image Capturing and send To Azure
    /// Computer Vision service.
    /// </summary>
    private void ExecuteImageCaptureAndAnalysis()
    {
        // Set the camera resolution to be the highest possible
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

        Texture2D targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Begin capture process, set the image format
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject)
        {
            photoCaptureObject                   = captureObject;
            CameraParameters camParameters       = new CameraParameters();
            camParameters.hologramOpacity        = 0.0f;
            camParameters.cameraResolutionWidth  = targetTexture.width;
            camParameters.cameraResolutionHeight = targetTexture.height;
            camParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            // Capture the image from the camera and save it in the App internal folder
            captureObject.StartPhotoModeAsync(camParameters, delegate(PhotoCapture.PhotoCaptureResult result)
            {
                string filename = string.Format(@"CapturedImage{0}.jpg", tapsCount);

                string filePath = Path.Combine(Application.persistentDataPath, filename);

                VisionManager.instance.imagePath = filePath;

                photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);

                currentlyCapturing = false;
            });
        });
    }
Пример #14
0
    private void ExecuteImageCaptureAndAnalysis() /// Begin process of Image Capturing and send To Azure Computer Vision service.
    {
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
        Texture2D  targetTexture    = new Texture2D(cameraResolution.width, cameraResolution.height);

        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject)
        {
            photoCaptureObject = captureObject;

            CameraParameters c       = new CameraParameters();
            c.hologramOpacity        = 0.0f;
            c.cameraResolutionWidth  = targetTexture.width;
            c.cameraResolutionHeight = targetTexture.height;
            c.pixelFormat            = CapturePixelFormat.BGRA32;

            captureObject.StartPhotoModeAsync(c, delegate(PhotoCapture.PhotoCaptureResult result)
            {
                string filename = string.Format(@"CapturedImage{0}.jpg", tapsCount);
                string filePath = Path.Combine(Application.persistentDataPath, filename);

                // Set the image path on the FaceAnalysis class
                FaceAnalysis.Instance.imagePath = filePath;

                photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
            });
        });
    }
Пример #15
0
    /// <summary>
    /// Begin process of image capturing and send to Azure Custom Vision Service.
    /// </summary>
    private void ExecuteImageCaptureAndAnalysis()
    {
        cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending
                               ((res) => res.width * res.height).First();

        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        PhotoCapture.CreateAsync(true, delegate(PhotoCapture captureObject)
        {
            photoCaptureObject = captureObject;

            CameraParameters camParameters = new CameraParameters
            {
                hologramOpacity        = 0f,
                cameraResolutionWidth  = targetTexture.width,
                cameraResolutionHeight = targetTexture.height,
                pixelFormat            = CapturePixelFormat.BGRA32
            };

            captureObject.StartPhotoModeAsync(camParameters, delegate(PhotoCapture.PhotoCaptureResult result)
            {
                captureCount++;
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemoryCallback);
            });
        });
    }
    public void StartTakePhoto(MainController mci)
    {
        if (taking)
        {
            return;
        }
        taking = true;
        FindObjectOfType <Flasher>().Flash();

        //Debug.Log("starting to take photo");
        mc = mci;
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) {
            Debug.Log("createasync");
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                // Take a picture
                //Debug.Log("create, photo is null: " + (photoCaptureObject == null).ToString());
                //Debug.Log("here");
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });
    }
Пример #17
0
 public static void Capture()
 {
     if (photoCaptureObject != null)
     {
         photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
     }
 }
Пример #18
0
    private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
    {
        /* Saving to file */
        //if (result.success)
        //{
        //    string filename = string.Format(@"CapturedImage{0}_n.jpg", Time.time);
        //    string filePath = System.IO.Path.Combine(Application.persistentDataPath, filename);

        //    photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
        //}
        //else
        //{
        //    Debug.LogError("Unable to start photo mode!");
        //}


        /* Saving to Texture2D */
        if (result.success)
        {
            photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
        }
        else
        {
            Debug.LogError("Unable to start photo mode!");
        }
    }
Пример #19
0
    public void OnInputClicked(InputClickedEventData eventData)
    {
        if (!capturingPhoto)
        {
            PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject)
            {
                photoCaptureObj = captureObject;

                CameraParameters cameraParameters       = new CameraParameters();
                cameraParameters.hologramOpacity        = 0.0f;
                cameraParameters.cameraResolutionWidth  = cameraResolution.width;
                cameraParameters.cameraResolutionHeight = cameraResolution.height;
                cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;


                //开始拍照时,capturingPhoto为真,capturingSucceed为假
                photoCaptureObj.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result)
                {
                    photoCaptureObj.TakePhotoAsync(OnCapturedPhotoToMemoryAsync);
                    capturingPhoto = true;
                    evaluating     = false;
                });
            });

            UnityEngine.Debug.Log("Photo Capture CreateAsync Succeed!");
        }
    }
Пример #20
0
    // Use this for initialization
    void Start()
    {
        //First: Last: worst resolution?
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).Last();

        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Create a PhotoCapture object
        //Params: Show Holograms=false, onCreatedCallback, wenn PhotoCapture Instance created and ready to be used
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) {
            photoCaptureObject = captureObject;

            //needed for Calling PhotoCapture.StartPhotoModeAsync
            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            // Activate the web camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                // Take a screenshot
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });
    }
Пример #21
0
    public void TakePictureToDisk()
    {
        _imageName = string.Format("SampleImage{0}.jpg", _currentPhotoNumber);
        _filePath  = System.IO.Path.Combine(Application.persistentDataPath, _imageName);

        _photoCaptureObject.TakePhotoAsync(_filePath, PhotoCaptureFileOutputFormat.JPG, OnPhotoCapturedToDisk);
    }
Пример #22
0
        public Task <bool> StartCapture()
        {
            if (FrameHeight == 0 && FrameWidth == 0)
            {
                Debug.LogError("StartCapture() invoked before camera initialized.");
                return(Task.FromResult(false));
            }
            PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject)
            {
                _photoCaptureObject = captureObject;
                UnityEngine.Windows.WebCam.CameraParameters cameraParameters = new UnityEngine.Windows.WebCam.CameraParameters
                {
                    hologramOpacity        = 0.0f,
                    cameraResolutionWidth  = FrameWidth,
                    cameraResolutionHeight = FrameHeight,
                    pixelFormat            = CapturePixelFormat.NV12
                };

                _photoCaptureObject?.StartPhotoModeAsync(cameraParameters, delegate
                {
                    _photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
                });
            });
            return(Task.FromResult(true));
        }
Пример #23
0
    /// <summary>
    /// Begin process of image capturing and send to Azure Custom Vision Service.
    /// </summary>
    private void ExecuteImageCaptureAndAnalysis()
    {
        // Create a label in world space using the ResultsLabel class
        // Invisible at this point but correctly positioned where the image was taken
        SceneOrganiser.Instance.StartAnalysisLabel();
        Debug.Log("Execute Image Capture and Analysis");
        // Set the camera resolution to be the highest possible
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending
                                          ((res) => res.width * res.height).First();
        Texture2D targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Begin capture process, set the image format
        PhotoCapture.CreateAsync(true, delegate(PhotoCapture captureObject)
        {
            photoCaptureObject = captureObject;

            CameraParameters camParameters = new CameraParameters
            {
                hologramOpacity        = 1.0f,
                cameraResolutionWidth  = targetTexture.width,
                cameraResolutionHeight = targetTexture.height,
                pixelFormat            = CapturePixelFormat.BGRA32
            };

            // Capture the image from the camera and save it in the App internal folder
            captureObject.StartPhotoModeAsync(camParameters, delegate(PhotoCapture.PhotoCaptureResult result)
            {
                string filename = string.Format(@"CapturedImage{0}.jpg", captureCount);
                filePath        = Path.Combine(Application.persistentDataPath, filename);
                captureCount++;
                photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
            });
        });
    }
    // Use this for initialization
    public void Start()
    {
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) {
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            width  = cameraResolution.width;
            height = cameraResolution.height;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                // Take a picture
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });
    }
Пример #25
0
    public void TakePhoto()
    {
        taking = true;
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).ToArray()[1];

        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) {
            Debug.Log("createasync");
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                // Take a picture
                Debug.Log("create, photo is null: " + (photoCaptureObject == null).ToString());
                Debug.Log("here");
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });
    }
Пример #26
0
    private void StartCapture()
    {
        //there can only be one active PhotoCapture
        if (captureStarted)
        {
            return;
        }
        captureStarted = true;

        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject)
        {
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result)
            {
                // Take a picture
                if (result.success)
                {
                    photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
                }
            });
        });
    }
Пример #27
0
    public Texture2D TakePhoto()
    {
        // Check if there are any supported resolutions. Exit if none is found
        if (!PhotoCapture.SupportedResolutions.Any())
        {
            Debug.Log("No supported resolutions where found. Photo mode exited.");
            OnPhotoModeEnded?.Invoke();
            return(null);
        }

        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) {
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.BGRA32;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                // Take a picture
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
                Debug.Log("Photo taken.");
            });
        });
        return(targetTexture);
    }
Пример #28
0
    void TakePhoto()
    {
        Vector3 position = new Vector3(newHeadPosition.x, newHeadPosition.y, newHeadPosition.z);

        // Debug.Log("New head position: " + newHeadPosition.ToString());
        Debug.Log("Taking picture");
        // Debug.Log("Rotation:" + Camera.main.transform.rotation.ToString());
        audioData.Play(0);
        photoCount++;

        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(holograms, delegate(PhotoCapture captureObject) {
            photoCaptureObject = captureObject;


            m_cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).Last();

            CameraParameters cameraParameters       = new CameraParameters();
            cameraParameters.hologramOpacity        = 0.0f;
            cameraParameters.cameraResolutionWidth  = m_cameraResolution.width;
            cameraParameters.cameraResolutionHeight = m_cameraResolution.height;
            cameraParameters.pixelFormat            = CapturePixelFormat.JPEG;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) {
                // Take a picture
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });
    }
Пример #29
0
 private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
 {
     if (result.success)
     {
         photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
     }
 }
Пример #30
0
    void Capture()
    {
        //TODO: Theoretically we can start another capture while the network is still busy from a previous capture
        if (photoCaptureObjectCreated && cameraSetupCompleted && photoCaptureModeOn && !cameraBusy)
        {
            photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);

#if IMAGECAPTURE_DEBUG
            Debug.Log("ImageCapture.Capture: Ready to capture; async capture job started");
#endif

            cameraBusy = true;
        }
#if IMAGECAPTURE_DEBUG
        else
        {
            if (!photoCaptureObjectCreated)
            {
                Debug.Log("ImageCapture.Capture: Could not start capture because photoCaptureObject is not ready");
            }
            if (!cameraSetupCompleted)
            {
                Debug.Log("ImageCapture.Capture: Could not start capture because CameraSetup is not complete");
            }
            if (!photoCaptureModeOn)
            {
                Debug.Log("ImageCapture.Capture: Could not start capture because photo capture mode is not on");
            }
            if (cameraBusy)
            {
                Debug.Log("ImageCapture.Capture: Could not start capture because the camera is still capturing from a previous call (cameraBusy)");
            }
        }
#endif
    }