Exemplo n.º 1
0
        async Task <IEnumerable <RawEmotion> > CaptureEmotionAsync()
        {
            _isProcessing = true;

            RawEmotion[] result;

            try
            {
                var photoFile = await _photoService.CreateAsync();

                var imageProperties = ImageEncodingProperties.CreateBmp();
                await _mediaManager.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                result = await _emotionClient.RecognizeAsync(await photoFile.OpenStreamForReadAsync());
            }
            finally
            {
                await _photoService.CleanupAsync();

                _isProcessing = false;
            }

            return(result.IsNullOrEmpty()
                ? await Task.FromResult(Enumerable.Empty <RawEmotion>())
                : result);
        }
Exemplo n.º 2
0
        private async void btnTake_Click(object sender, RoutedEventArgs e)
        {
            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
            StorageFile             file      = await ApplicationData.Current.LocalFolder.CreateFileAsync("Photo.jpg", CreationCollisionOption.ReplaceExisting);

            await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);
        }
Exemplo n.º 3
0
        private async void capture_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                capture.IsEnabled = false;

                if (displayInformation.NativeOrientation == DisplayOrientations.Portrait)
                {
                    captureTransform.Rotation = 90.0;
                }

                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                capture.IsEnabled = true;
                status.Log(capture, LocalizableStrings.CAMERA_CAPTURE_SUCCESS);

                IRandomAccessStream photoStream = await photoFile.OpenAsync(FileAccessMode.Read);

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;
            }
            catch (Exception ex)
            {
                status.Log(ex.Message);
            }
            finally
            {
                capture.IsEnabled = true;
            }
        }
Exemplo n.º 4
0
        public async Task <WriteableBitmap> CaptureJpegImageAsync()
        {
            var bitmap = new WriteableBitmap(400, 300);

            using (var memoryStream = new InMemoryRandomAccessStream())
            {
                var file = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(IMAGECAPTURE_FILENAME, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                try
                {
                    await _mediaCapture.CapturePhotoToStorageFileAsync(_imageEncodingProperties, file);

                    var photoStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    await bitmap.SetSourceAsync(photoStream);

                    return(bitmap);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                return(null);
            }
        }
Exemplo n.º 5
0
        private async void CreateGroupButtonMethod()
        {
            faceServiceClient = new FaceServiceClient("fbeb228a7f1943b69c3e6e2861f22ff0");

            //var client = new HttpClient();
            //var queryString = WebUtility.UrlEncode(string.Empty);
            string personGroupId = "group1";
            Guid   personId      = new Guid("a3f0bd5c-b917-41f7-b50f-ae6fb2e3c6a2");
            //// Request header
            //client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "fbeb228a7f1943b69c3e6e2861f22ff0");
            //var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/" + personGroupId + "/persons/"+ personId +"/persistedFaces" ;

            //HttpResponseMessage response;

            MediaCapture mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();

            photo = await KnownFolders.PicturesLibrary.CreateFileAsync(
                "capture1.jpg", CreationCollisionOption.ReplaceExisting);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
            await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photo);

            //Request body
            Stream image = await photo.OpenStreamForReadAsync();

            await faceServiceClient.AddPersonFaceAsync(personGroupId, personId, image);

            await faceServiceClient.TrainPersonGroupAsync(personGroupId);


            //var faces = await faceServiceClient.DetectAsync(image);
            //var faceIds = faces.Select(face => face.FaceId).ToArray();

            //var results = await faceServiceClient.IdentifyAsync(personGroupId, faceIds);
            //foreach (var identifyResult in results)
            //{
            //    if (identifyResult.Candidates.Length == 0)
            //    {

            //    }
            //    else
            //    {
            //        var candidateId = identifyResult.Candidates[0].PersonId;
            //        var person = await faceServiceClient.GetPersonAsync(personGroupId, candidateId);

            //    }
            //}
            //string body = JsonConvert.SerializeObject(new
            //{
            //    url =  photo.Path,
            //});
            //byte[] byteData = Encoding.UTF8.GetBytes(body);

            //using (var content = new ByteArrayContent(byteData))
            //{
            //    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            //    response = await client.PostAsync(uri, content);
            //}
        }
Exemplo n.º 6
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            CloudBlockBlob blockBlob = createBlob();

            MediaCapture mediaCaptureManager = new MediaCapture();

            mediaCaptureManager.InitializeAsync().ToObservable()
            .ObserveOnDispatcher()
            .SelectMany(_ =>
            {
                previewElement.Source = mediaCaptureManager;
                return(mediaCaptureManager.StartPreviewAsync().ToObservable());
            })
            .Subscribe(_ =>
            {
                Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync("tmp.jpg", Windows.Storage.CreationCollisionOption.ReplaceExisting).ToObservable()
                .Repeat()
                .Delay(TimeSpan.FromSeconds(5))
                .Subscribe(photoStorageFile =>
                {
                    Task.Run(async() => {
                        await mediaCaptureManager.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);
                        await blockBlob.UploadFromFileAsync(photoStorageFile);
                    }).Wait();
                }, ex => Debug.WriteLine(ex.Message));
            });
        }
Exemplo n.º 7
0
        private async void previewElement_Tapped(object sender, TappedRoutedEventArgs e)
        {
            // Block multiple taps.
            if (!IsCaptureInProgress)
            {
                IsCaptureInProgress = true;

                // Create the temporary storage file.
                media = await ApplicationData.Current.LocalFolder
                        .CreateFileAsync("capture_file.jpg", CreationCollisionOption.ReplaceExisting);

                // Take the picture and store it locally as a JPEG.
                await cameraCapture.CapturePhotoToStorageFileAsync(
                    ImageEncodingProperties.CreateJpeg(), media);

                captureButtons.Visibility = Visibility.Visible;

                // Use the stored image as the preview source.
                BitmapImage tempBitmap = new BitmapImage(new Uri(media.Path));
                imagePreview.Source       = tempBitmap;
                imagePreview.Visibility   = Visibility.Visible;
                previewElement.Visibility = Visibility.Collapsed;
                IsCaptureInProgress       = false;
                ButtonRetake.Visibility   = Visibility.Visible;
            }
        }
        public async void ImageCapture()
        {
            try
            {
                captureImage.Source = null;

                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                status.Text = "Take Photo succeeded: " + photoFile.Path;
                //To preview capture image on UI
                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;

                //To send Image to cloud
                await ImageUpload.UploadToAzure(photoFile, "mypic");
            }
            catch (Exception ex)
            {
                status.Text = ex.Message;
            }
        }
Exemplo n.º 9
0
        //GENERAL PURPOSE FUNCTION
        ///<summary>
        ///     Takes photo, saves photo file on temp folder, sets a place of grid as new photo and then returns user with attribute PhotoFace.
        ///</summary>
        private async Task <User> TakePhoto(String filename)
        {
            var photoFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

            await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateBmp(), photoFile);

            IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

            BitmapImage bitmap = new BitmapImage();

            bitmap.SetSource(photoStream);
            Image img = new Image()
            {
                Width = 100, Source = bitmap
            };

            //Add photo to grid

            photoContainer.Children.Add(img);
            Grid.SetRow(img, photoContainer.RowDefinitions.Count - 1);
            Grid.SetColumn(img, photoContainer.ColumnDefinitions.Count - 1);

            User u = new User();

            u.PhotoFace = img;
            await Print("Picture taken!");

            return(u);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Takes a picture from the webcam
        /// </summary>
        /// <returns>StorageFile of image</returns>
        public async Task <StorageFile> TakePicture()
        {
            try
            {
                //captureImage is our Xaml image control (to preview the picture onscreen)
                CaptureImage.Source = null;

                //gets a reference to the file we're about to write a picture into
                StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    "RaspPiSecurityPic.jpg", CreationCollisionOption.GenerateUniqueName);

                //use the MediaCapture object to stream captured photo to a file
                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await MediaCap.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                //show photo onscreen
                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                CaptureImage.Source = bitmap;

                AppStatus.Text = "Took Photo: " + photoFile.Name;

                return(photoFile);
            }
            catch (Exception ex)
            {
                //write the exception on screen
                AppStatus.Text = "Error taking picture: " + ex.Message;

                return(null);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 画像取得.
        /// </summary>
        private void capture()
        {
            MediaCapture mediaCaptureManager = new MediaCapture();

            mediaCaptureManager.InitializeAsync()
            .ToObservable()
            .ObserveOnDispatcher()
            .SelectMany(_ =>
            {
                previewElement.Source = mediaCaptureManager;
                return(mediaCaptureManager.StartPreviewAsync().ToObservable());
            })
            .Subscribe(_ =>
            {
                Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync("tmp.jpg", Windows.Storage.CreationCollisionOption.ReplaceExisting)
                .ToObservable()
                .Repeat()
                .Delay(TimeSpan.FromSeconds(10))
                .Subscribe(photoStorageFile =>
                {
                    Task.Run(async() => {
                        await mediaCaptureManager.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);

                        await getStorageSasUriAsync();

                        await putStorageFileAsync(photoStorageFile);

                        await notificationFileUploadAsync();
                    }).Wait();
                }, ex => Debug.WriteLine(ex.Message));
            });
        }
Exemplo n.º 12
0
        private async Task UploadPhoto()
        {
            photoUploadTimer.Stop();
            photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(capturedPhotoFile, CreationCollisionOption.ReplaceExisting);

            var imageProperties = ImageEncodingProperties.CreateJpeg();

            try
            {
                using (var fileStream = await photoStorageFile.OpenStreamForReadAsync())
                {
                    await mediaCaptureManager.CapturePhotoToStorageFileAsync(imageProperties, photoStorageFile);

                    var fileName = "img" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
                    await deviceClient.UploadToBlobAsync(fileName, fileStream);

                    Debug.WriteLine(string.Format("Uploaded: {0} at {1}", fileName, DateTime.Now.ToString("yyyy/MM/dd - hh:mm:ss")));
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
            }
            photoUploadTimer.Start();
        }
Exemplo n.º 13
0
        private async Task <StorageFile> TakePicture()
        {
            try
            {
                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.ReplaceExisting);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                          () =>
                {
                    statusLabel.Text = "Photo taken";
                });

                return(photoFile);
                //IRandomAccessStream photoStream = await photoFile.OpenReadAsync();
                //BitmapImage bitmap = new BitmapImage();
                //bitmap.SetSource(photoStream);
            }
            catch (Exception ex)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                          () =>
                {
                    statusLabel.Text = ex.Message;
                });

                return(null);
            }
        }
Exemplo n.º 14
0
        private async Task TakePhotoAsync()
        {
            if (!this.isEnabled)
            {
                return;
            }

            //Use current time in ticks as image name
            string imageName = DateTime.UtcNow.Ticks.ToString() + ".jpg";

            //Get folder to store images
            var cacheFolder = KnownFolders.PicturesLibrary;

            cacheFolder = await cacheFolder.GetFolderAsync("securitysystem-cameradrop");

            //Create blank file to store image
            StorageFile image = await cacheFolder.CreateFileAsync(imageName);

            try
            {
                //Capture an image and store it in the given file
                await mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), image);
            }
            catch (Exception ex)
            {
                //Expected Exception. If image capture was unsuccessful, delete the blank file created
                await image.DeleteAsync();
            }
        }
Exemplo n.º 15
0
        private async Task <string> ScanAndDecodeImage()
        {
            Result result = null;

            while (result == null && IsPreviewing)
            {
                // TODO capture to stream instead
                //using (var stream = new InMemoryRandomAccessStream()) {
                //await MediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
                var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("beam.jpg", CreationCollisionOption.GenerateUniqueName);

                await MediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);

                using (var stream = await photoStorageFile.OpenReadAsync()) {
                    // initialize with 1,1 to get the current size of the image
                    var writeableBmp = new WriteableBitmap(1, 1);
                    writeableBmp.SetSource(stream);
                    // and create it again because otherwise the WB isn't fully initialized and decoding
                    // results in a IndexOutOfRange
                    writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
                    stream.Seek(0);
                    await writeableBmp.SetSourceAsync(stream);

                    result = DecodeBitmap(writeableBmp);
                }
                await photoStorageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);

                //}
            }
            return(result != null ? result.Text : null);
        }
Exemplo n.º 16
0
        private async void TakePhotoButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            try
            {
                Debug.WriteLine("Taking photo");
                TakePhotoButton.IsEnabled = false;

                //store the captured image
                _photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("capturedImage", CreationCollisionOption.ReplaceExisting);

                Debug.WriteLine("Create photo file successful");

                //create the properties to write
                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await _mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, _photoFile);

                TakePhotoButton.IsEnabled = true;
                Debug.WriteLine("Photo taken");

                //map the captured image as Bitmap image to the right column
                ImageElement.Source = await OpenImageAsBitmapAsync(_photoFile);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
                TakePhotoButton.IsEnabled = true;
            }
        }
Exemplo n.º 17
0
        private async void ImageUpload(string deviceId)
        {
            try
            {
                using (Windows.Storage.Streams.InMemoryRandomAccessStream captureStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
                {
                    await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream);

                    await captureStream.FlushAsync();

                    captureStream.Seek(0);

                    // Drops file onto device file system for debugging only
#if DEBUG
                    IStorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("Timelapse.jpg", CreationCollisionOption.ReplaceExisting);

                    ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                    await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);
#endif
                    LoggingService.Log("ImageUploadService Upload starting");
                    ImageUploadService.Upload(deviceId, captureStream);
                    LoggingService.Log("ImageUploadService Upload done");
                }
            }
            catch (Exception ex)
            {
                LoggingService.Error($"Image capture or upload failed ", ex);
            }
        }
Exemplo n.º 18
0
        private async Task takePhoto_Click()
        {
            try
            {
                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                //takePhoto.IsEnabled = true;
                //status.Text = "Take Photo succeeded: " + photoFile.Path;
                path = photoFile.Path;
                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    BitmapImage bitmap = new BitmapImage();
                    bitmap.SetSource(photoStream);
                    captureImage.Source = bitmap;
                });

                TakeAndSendPicture(photoFile);
            }
            catch (Exception ex)
            {
                Cleanup();
            }
            finally
            {
            }
        }
Exemplo n.º 19
0
        private async void UploadImageButtonClick()
        {
            //CameraCaptureUI captureUI = new CameraCaptureUI();
            //captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            //captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
            //photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            MediaCapture mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();

            photo = await KnownFolders.PicturesLibrary.CreateFileAsync(
                "capture_file.jpg", CreationCollisionOption.ReplaceExisting);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
            await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photo);

            if (photo == null)
            {
                // User cancelled photo capture
                return;
            }

            Status += "Image is Uploading...\n";
            SendToBlobAsync();
        }
Exemplo n.º 20
0
        private async void takePhoto_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                btnTakePhoto.IsEnabled = false;
                captureImage.Source    = null;
                //store the captured image
                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                btnTakePhoto.IsEnabled = true;
                txtLocation.Text       = "Take Photo succeeded: " + photoFile.Path;
                //display the image
                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;
                Picker_SelectedFile = photoFile;
                SelectFile();
            }
            catch (Exception ex)
            {
                txtLocation.Text = ex.Message;
                Cleanup();
            }
        }
Exemplo n.º 21
0
        private async Task <bool> TakePhoto_Click(object sender, TextChangedEventArgs e)
        {
            var files = await KnownFolders.PicturesLibrary.GetFilesAsync();

            var one = files.FirstOrDefault(x => x.Name == PHOTO_FILE_NAME);

            if (one != null)
            {
                await one.DeleteAsync();
            }
            StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                PHOTO_FILE_NAME, CreationCollisionOption.ReplaceExisting);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
            await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

            IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

            BitmapImage bitmap = new BitmapImage();

            bitmap.SetSource(photoStream);
            captureImage.Source = bitmap;
            photoStream.Dispose();

            using (Stream photoStream2 = await photoFile.OpenStreamForReadAsync())
            {
                await UploadFileToStorage(photoStream2, PHOTO_FILE_NAME);
            }

            return(true);
        }
Exemplo n.º 22
0
        private async void takePhoto_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                takePhoto.IsEnabled   = false;
                recordVideo.IsEnabled = false;
                captureImage.Source   = null;

                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                takePhoto.IsEnabled = true;
                status.Text         = "Take Photo succeeded: " + photoFile.Path;

                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;
            }
            catch (Exception ex)
            {
                status.Text = ex.Message;
                Cleanup();
            }
            finally
            {
                takePhoto.IsEnabled   = true;
                recordVideo.IsEnabled = true;
            }
        }
Exemplo n.º 23
0
        async public void OnCapturesCommand(object param)
        {
            MediaCapture takePhotoManager = new MediaCapture();
            await takePhotoManager.InitializeAsync();

            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
            IStorageFile            file      = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                "Photo.jpg", CreationCollisionOption.GenerateUniqueName);

            await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);

            //Windows.Storage.StorageFile file = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);

            if (file != null)
            {
                IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(fileStream);

                IGraphInfo graph = this.Info as IGraphInfo;
                NodeVM     node  = new NodeVM();
                node.OffsetX    = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportWidth) / 2;
                node.OffsetY    = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportHeight) / 2;
                node.UnitHeight = 100;
                node.UnitWidth  = 100;
                node.Content    = new Image()
                {
                    Source = bitmap, Stretch = Stretch.Fill
                };
                (Nodes as ObservableCollection <NodeVM>).Add(node);
            }
        }
Exemplo n.º 24
0
        private async void UploadPhoto()
        {
            uploadTimer.Stop();
            photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(capturedPhotoFile, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();

            try
            {
                await mediaCaptureManager.CapturePhotoToStorageFileAsync(imageProperties, photoStorageFile);

                var cloudStorageAccount = CloudStorageAccount.Parse(AzureStorageConnString);
                var blobClient          = cloudStorageAccount.CreateCloudBlobClient();
                var container           = blobClient.GetContainerReference("photos");
                await container.CreateIfNotExistsAsync();

                var fileName  = "photo" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
                var blockBlob = container.GetBlockBlobReference(fileName);
                await blockBlob.UploadFromFileAsync(photoStorageFile);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            uploadTimer.Start();
        }
Exemplo n.º 25
0
        private async void TakePhoto()
        {
            DeviceInformation cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Front);

            if (cameraDevice == null)
            {
                ErrorText.Text = "No camera";
                return;
            }

            MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings {
                VideoDeviceId = cameraDevice.Id
            };

            MediaCapture mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync(settings);

            StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("MyPhoto", CreationCollisionOption.GenerateUniqueName);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();

            await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

            IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

            BitmapImage bitmap = new BitmapImage();

            bitmap.SetSource(photoStream);
            ImageControl.Source = bitmap;
        }
Exemplo n.º 26
0
        async void CapturePhoto()
        {
            var photoFolder = KnownFolders.CameraRoll;
            var photoFile   = await photoFolder.CreateFileAsync("photo.jpg", CreationCollisionOption.GenerateUniqueName);

            var photoEncoding = ImageEncodingProperties.CreateJpeg();
            await mediaCapture.CapturePhotoToStorageFileAsync(photoEncoding, photoFile);
        }
Exemplo n.º 27
0
        public async Task <StorageFile> CapturePhoto(string desiredName = "photo.jpg")
        {
            var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(desiredName, CreationCollisionOption.GenerateUniqueName);

            await mediaCapture.CapturePhotoToStorageFileAsync(imgEncodingProperties, photoStorageFile);

            return(photoStorageFile);
        }
Exemplo n.º 28
0
        // method to take a still image, send to APIs, and display result
        public async void takePhoto_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                takePhoto.IsEnabled = false;

                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                takePhoto.IsEnabled = true;
                statusBox.Text      = "Take Photo succeeded: " + photoFile.Path;

                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                IRandomAccessStream photoStream2 = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                await writeableBitmap.SetSourceAsync(photoStream2);

                // and now for the face API call
                statusBox.Text = "Uploading image for Face API";

                Stream fs1 = await photoFile.OpenStreamForReadAsync();

                Stream fs2 = await photoFile.OpenStreamForReadAsync();

                var faceClient    = new FaceServiceClient("9725d03742394560be3ff295e1e435a2");
                var emotionClient = new EmotionServiceClient("c9306a1f134749759f1f4f9ae8838e1a");
                faceResult = await faceClient.DetectAsync(fs1);

                emotionResult = await emotionClient.RecognizeAsync(fs2);

                numFaces = faceResult.Length;

                statusBox.Text = "Number of faces detected: " + numFaces.ToString();
                currentFace    = 0;

                if (numFaces > 0) // if faces were returned in the result, display the first one
                {
                    displayFaceInfo();
                    displayImage();
                }
            }
            catch (Exception ex)
            {
                statusBox.Text = ex.Message;
                Cleanup();
            }
            finally
            {
                takePhoto.IsEnabled = true;
            }
        }
Exemplo n.º 29
0
        private async void MediaCapture_buttonPhoTo()
        {
            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
            StorageFile             file      = await ApplicationData.Current.LocalFolder.CreateFileAsync("Photo.jpg", CreationCollisionOption.ReplaceExisting);

            await mediaCap.CapturePhotoToStorageFileAsync(imgFormat, file);

            mediaCapture.Status = "Photo";
        }
        public async Task <StorageFile> CapturePhoto(string desiredName = "visit_photo.jpg")
        {
            // Create new unique file in the pictures library and capture photo into it
            var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(desiredName, CreationCollisionOption.ReplaceExisting);

            await mediaCapture.CapturePhotoToStorageFileAsync(imgEncodingProperties, photoStorageFile);

            return(photoStorageFile);
        }