Ejemplo n.º 1
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 = UnityEngine.Windows.WebCam.PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

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

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

            // Capture the image from the camera and save it in the App internal folder
            captureObject.StartPhotoModeAsync(camParameters, delegate(UnityEngine.Windows.WebCam.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, UnityEngine.Windows.WebCam.PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);

                currentlyCapturing = false;
            });
        });
    }
Ejemplo n.º 2
0
 void OnStoppedPhotoMode(UnityEngine.Windows.WebCam.PhotoCapture.PhotoCaptureResult result)
 {
     // Dispose from the object in memory and request the image analysis
     // to the VisionManager class
     photoCaptureObject.Dispose();
     photoCaptureObject = null;
     StartCoroutine(VisionManager.instance.AnalyseLastImageCaptured());
 }
Ejemplo n.º 3
0
    void OnPhotoCaptureCreated(UnityEngine.Windows.WebCam.PhotoCapture captureObject)
    {
        photoCapture = captureObject;

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

        UnityEngine.Windows.WebCam.CameraParameters c = new UnityEngine.Windows.WebCam.CameraParameters();
        c.hologramOpacity        = 0.0f;
        c.cameraResolutionWidth  = cameraResolution.width;
        c.cameraResolutionHeight = cameraResolution.height;
        c.pixelFormat            = UnityEngine.Windows.WebCam.CapturePixelFormat.JPEG;

        captureObject.StartPhotoModeAsync(c, OnPhotoModeStarted);
    }
Ejemplo n.º 4
0
 private void OnStoppedPhotoMode(UnityEngine.Windows.WebCam.PhotoCapture.PhotoCaptureResult result)
 {
     photoCapture.Dispose();
     photoCapture = null;
 }
Ejemplo n.º 5
0
 private static void InvokeOnCapturedPhotoToDiskDelegate(PhotoCapture.OnCapturedToDiskCallback callback, long hResult)
 {
     callback(PhotoCapture.MakeCaptureResult(hResult));
 }
Ejemplo n.º 6
0
 private static void InvokeOnPhotoModeStoppedDelegate(PhotoCapture.OnPhotoModeStoppedCallback callback, long hResult)
 {
     callback(PhotoCapture.MakeCaptureResult(hResult));
 }