Ejemplo n.º 1
0
        /// <summary>
        /// Captures a still image from the webcam as a stream, handing the result over to the supplied action delegate.
        /// </summary>
        /// <param name="capturedImageAction">A CapturedImageAction delegate to handle the captured image data.</param>
        public async Task CapturePhoto(CapturedImageAction capturedImageAction)
        {
            if (isCapturing)
            {
                return;
            }

            isCapturing = true;

            var properties    = ImageEncodingProperties.CreateJpeg();
            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(properties);

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var stream = capturedPhoto.Frame.AsStreamForRead();
            var reader = new BinaryReader(stream);

            var byteCount    = Convert.ToInt32(capturedPhoto.Frame.Size);
            var bytes        = reader.ReadBytes(byteCount);
            var memoryStream = new MemoryStream(bytes);

            await capturedImageAction(memoryStream);

            await lowLagCapture.FinishAsync();

            isCapturing = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle a face detected event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void FaceDetectionEffect_FaceDetected(FaceDetectionEffect sender, FaceDetectedEventArgs args)
        {
            // Only run one face detection call to Cognitive Services at a time
            if (!_isRecognizing)
            {
                //If we need the box for the detected face we can get them here
                //foreach (Windows.Media.FaceAnalysis.DetectedFace face in args.ResultFrame.DetectedFaces)
                //{
                //    BitmapBounds faceRect = face.FaceBox;
                //}

                _isRecognizing = true;

                var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                var capturedPhoto = await lowLagCapture.CaptureAsync();

                var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

                await lowLagCapture.FinishAsync();

                using (IRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream())
                {
                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, randomAccessStream);

                    encoder.SetSoftwareBitmap(softwareBitmap);

                    await encoder.FlushAsync();

                    var stream = randomAccessStream.AsStreamForRead();

                    try
                    {
                        //This call the Cognitive Services face API to detect the faces
                        var faces = await FaceService.DetectAsync(stream, true, false);

                        List <Guid> faceList = new List <Guid>();

                        foreach (var face in faces)
                        {
                            faceList.Add(face.FaceId);
                        }

                        LastFaces = faceList.ToArray();
                    }
                    catch
                    {
                        //We could not detect faces using Cognitive Services
                    }
                }

                _isRecognizing = false;
            }
        }
Ejemplo n.º 3
0
        private async void Timer_Tick(object sender, object e)
        {
            timer.Stop();
            await mediaCapture.InitializeAsync();

            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateJpeg());

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            EmotionServiceClient emotionServiceClient = new EmotionServiceClient("638268f88e154b588fabdf134ee3e63e");

            //SoftwareBitmap softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;
            //SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap,
            //    BitmapPixelFormat.Bgra8,
            //    BitmapAlphaMode.Premultiplied);

            //SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
            //await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);

            //imgCaptured.Source = bitmapSource;

            Emotion[] emotionResult = await emotionServiceClient.RecognizeAsync(capturedPhoto.Frame.AsStreamForRead());

            processEmotion(emotionResult);

            await lowLagCapture.FinishAsync();
        }
Ejemplo n.º 4
0
        public async Task InitializeAsync(DeviceInformation camera)
        {
            if (camera != null)
            {
                try
                {
                    _mediaCapture = new MediaCapture();
                    await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = camera.Id, PhotoCaptureSource = PhotoCaptureSource.VideoPreview });

                    try
                    {
                        var res = new VideoEncodingProperties {
                            Height = 360, Width = 640, Bitrate = 121651200, ProfileId = 0, Subtype = "YUY2"
                        };
                        await _mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, res);
                    }
                    catch
                    {
                    }

                    _lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                    _mediaCapture = null;
                }
            }
            else
            {
                _mediaCapture = null;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Start video recording
        /// </summary>
        /// <returns></returns>
        private async Task StartVideoRecordingAsync()
        {
            try
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => PhotoButton.IsEnabled = false);

                if (_mediaCapture.MediaCaptureSettings.ConcurrentRecordAndPhotoSupported)
                {
                    ImageEncodingProperties imageEncodingProperties = ImageEncodingProperties.CreateJpeg();
                    _lowLagPhotoCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(imageEncodingProperties);

                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => PhotoButton.IsEnabled = true);
                }

                var mediaEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
                var folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("Cam360", CreationCollisionOption.OpenIfExists);

                var file = await folder.CreateFileAsync("test.mp4", CreationCollisionOption.GenerateUniqueName);

                await _mediaCapture.StartRecordToStorageFileAsync(mediaEncodingProfile, file);
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format("StartVideoRecording did not complete: {0}", ex.Message);
                Debug.Write(errorMessage);
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    await new MessageDialog(errorMessage).ShowAsync();
                });
            }
        }
        private async Task startPreviewAsync()
        {
            try
            {
                mediaCapture = new MediaCapture();
                await mediaCapture.InitializeAsync(settings);


                displayRequest = new DisplayRequest();
                displayRequest.RequestActive();
                DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
                lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));
            }
            catch (UnauthorizedAccessException)
            {
                MainPage.ShowMessage("Unable to start");
                return;
            }

            try
            {
                previewControl.Source = mediaCapture;
                await mediaCapture.StartPreviewAsync();

                isPreviewing = true;
            }
            catch (System.IO.FileLoadException)
            {
                mediaCapture.CaptureDeviceExclusiveControlStatusChanged += MediaCapture_CaptureDeviceExclusiveControlStatusChanged;
            }
        }
Ejemplo n.º 7
0
        private async void TakePhotoAsync()
        {
            mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();

            //mediaCapture.Failed += MediaCapture_Failed;

            // Prepare and capture photo
            // 캡쳐한 사진을 바로 XAML에서 보여줌
            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

            await lowLagCapture.FinishAsync();

            //임시로 저장된 거를 XAML에서 표시
            if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
            {
                softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
            }

            var source = new SoftwareBitmapSource();
            await source.SetBitmapAsync(softwareBitmap);

            // Set the source of the Image control
            imageControl.Source = source;
        }
        //Takes iamge and creates a writableBitmap from result
        //NEW TO ME
        private async Task <WriteableBitmap> takeImage()
        {
            try
            {
                var capture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                var photo = await capture.CaptureAsync();

                var             softwareBitmap = photo.Frame.SoftwareBitmap;
                WriteableBitmap bitmap         = new WriteableBitmap(softwareBitmap.PixelWidth, softwareBitmap.PixelHeight);
                softwareBitmap.CopyToBuffer(bitmap.PixelBuffer);
                await capture.FinishAsync();

                return(bitmap);
            }
            catch (Exception e)
            {
                if (!cancelled)
                {
                    await errorDialog();
                }
                manager.navigateMain(typeof(FrameViewerPage));
            }
            return(new WriteableBitmap(0, 0));
        }
Ejemplo n.º 9
0
        public async Task InitializeAsync()
        {
            _mediaCapture = new MediaCapture();
            await _mediaCapture.InitializeAsync();

            _mediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Photo;
            _capture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(GetImageEncodingProperties());
        }
Ejemplo n.º 10
0
 public async Task Init()
 {
     var initTask = Task.Run(async() =>
     {
         await mMediaCapture.InitializeAsync();
         mLowLagCapture = await mMediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateJpeg());
     });
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Capture a Picture Method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CaptureToFile()
        {
            try
            {
                // Prepare and capture photo
                var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                var capturedPhoto = await lowLagCapture.CaptureAsync();

                var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

                await lowLagCapture.FinishAsync();

                if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                    softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
                {
                    softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                }

                var bitmapSource = new SoftwareBitmapSource();
                await bitmapSource.SetBitmapAsync(softwareBitmap);

                captureImage.Source = bitmapSource;


                //to file
                saveFileCount++;
                fileNameWithType = saveFileCount.ToString() + " " + fileNameBox.Text + ".jpg";

                var myPictures = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures);

                file = await myPictures.SaveFolder.CreateFileAsync(fileNameWithType, CreationCollisionOption.GenerateUniqueName);

                using (var captureStream = new InMemoryRandomAccessStream())
                {
                    await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream);

                    using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        var decoder = await BitmapDecoder.CreateAsync(captureStream);

                        var encoder = await BitmapEncoder.CreateForTranscodingAsync(fileStream, decoder);

                        var properties = new BitmapPropertySet {
                            { "System.Photo.Orientation", new BitmapTypedValue(PhotoOrientation.Normal, PropertyType.UInt16) }
                        };
                        await encoder.BitmapProperties.SetPropertiesAsync(properties);

                        await encoder.FlushAsync();
                    }
                }
            }
            catch
            {
            }
        }//end CaptureToFile
Ejemplo n.º 12
0
        private async System.Threading.Tasks.Task <CapturedPhoto> CapturePreviewFrame()
        {
            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

            var frame = await lowLagCapture.CaptureAsync();

            await lowLagCapture.FinishAsync();

            return(frame);
        }
Ejemplo n.º 13
0
        private async void ScreenShot_Click(object sender, RoutedEventArgs e)
        {
            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

            await lowLagCapture.FinishAsync();
        }
Ejemplo n.º 14
0
        public async Task <SoftwareBitmap> GetImageAsync()
        {
            if (_photoCapture == null)
            {
                _photoCapture = await MediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));
            }

            var cc = await _photoCapture.CaptureAsync();

            return(cc.Frame.SoftwareBitmap);
        }
        /// <summary>
        /// Takes the camera output and displays the Clarifai predictions on the pane.
        /// </summary>
        /// <returns>a task</returns>
        private async Task RunPredictionsAndDisplayResponse()
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    if (_predictionApi == null)
                    {
                        return;
                    }

                    LowLagPhotoCapture lowLagCapture =
                        await _mediaCapture.PrepareLowLagPhotoCaptureAsync(
                            ImageEncodingProperties.CreateUncompressed(MediaPixelFormat
                                                                       .Bgra8));
                    CapturedPhoto capturedPhoto   = await lowLagCapture.CaptureAsync();
                    SoftwareBitmap softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;
                    byte[] data = await EncodedBytes(softwareBitmap,
                                                     BitmapEncoder.JpegEncoderId);

                    try
                    {
                        ConceptsTextBlock.Text = await _predictionApi
                                                 .PredictConcepts(data, _selectedModel);
                    }
                    catch (Exception ex)
                    {
                        ShowMessageToUser("Error: " + ex.Message);
                    }

                    try
                    {
                        (double camWidth, double camHeight) = CameraOutputDimensions();

                        List <Rect> rects = await _predictionApi.PredictFaces(data,
                                                                              camWidth, camHeight);
                        CameraGrid.Children.Clear();
                        foreach (Rect r in rects)
                        {
                            CameraGrid.Children.Add(CreateGuiRectangle(r, camWidth, camHeight));
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowMessageToUser("Error: " + ex.Message);
                    }

                    await lowLagCapture.FinishAsync();
                }
                catch (COMException) // This is thrown when application exits.
                {
                    // No need to handle this since the application is exiting.
                }
            });
Ejemplo n.º 16
0
        private async Task CapturePhoto()
        {
            var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateJpeg());

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var softwareBitmap = capturedPhoto.Frame.AsStream();

            CapturePhotoService.ImageCaptureHandler(Xamarin.Forms.ImageSource.FromStream(() => softwareBitmap));

            await lowLagCapture.FinishAsync();
        }
Ejemplo n.º 17
0
        public async Task <object> CapturePictureAsync()
        {
            var encodingProperties = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8);
            var lowLagCapture      = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(encodingProperties);

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

            await lowLagCapture.FinishAsync();

            return(softwareBitmap);
        }
Ejemplo n.º 18
0
        public async Task <Stream> TakeSnapshotAsync()
        {
            var encoding = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8);
            var capture  = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(encoding);

            var photo = await capture.CaptureAsync();

            var frame = photo.Frame;

            await capture.FinishAsync();

            return(await this.WriteToStreamAsync(frame));
        }
Ejemplo n.º 19
0
        async private void InitLowLagPhotoCapture_Click(object sender, RoutedEventArgs e)
        {
            // Enable thumbnail images
            mediaCaptureManager.VideoDeviceController.LowLagPhoto.ThumbnailEnabled     = true;
            mediaCaptureManager.VideoDeviceController.LowLagPhoto.ThumbnailFormat      = MediaThumbnailFormat.Bmp;
            mediaCaptureManager.VideoDeviceController.LowLagPhoto.DesiredThumbnailSize = 25;

            // Image properties
            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();

            // Create LowLagPhotoCapture object
            lowLagCaptureMgr = await mediaCaptureManager.PrepareLowLagPhotoCaptureAsync(imgFormat);
        }
Ejemplo n.º 20
0
        public async Task InitializeCameraAsync()
        {
            // Asynchronously initialize this instance.
            var mediaInitSettings = new MediaCaptureInitializationSettings {
                VideoDeviceId = this.DeviceId
            };

            mediaInitSettings.StreamingCaptureMode = StreamingCaptureMode.Video;
            await _mediaCapture.InitializeAsync(mediaInitSettings);

            await this.SetCameraResolutionAsync(1280, 720);

            _lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));
        }
Ejemplo n.º 21
0
        public async Task CaptureToSoftwareBitmap()
        {
            //<SnippetCaptureToSoftwareBitmap>
            // Prepare and capture photo
            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

            await lowLagCapture.FinishAsync();

            //</SnippetCaptureToSoftwareBitmap>
        }
Ejemplo n.º 22
0
        private async Task <SoftwareBitmap> CaptureImage()
        {
            await this.InitializeMediaCaptureIfNeeded();

            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(
                ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

            await lowLagCapture.FinishAsync();

            return(softwareBitmap);
        }
        private async Task Init()
        {
            try
            {
                mMediaCapture = new MediaCapture();
                await mMediaCapture.InitializeAsync();

                mLowLagCapture = await mMediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateJpeg());

                mStreamWebSocket         = new StreamWebSocket();
                mStreamWebSocket.Closed += MStreamWebSocket_Closed;
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 24
0
        public async Task <SoftwareBitmap> CapturePhoto(MediaCapture mediaCapture)
        {
            using (var captureStream = new InMemoryRandomAccessStream())
            {
                await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateBmp(), captureStream);

                var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                var capturedPhoto = await lowLagCapture.CaptureAsync();

                var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;
                await lowLagCapture.FinishAsync();

                return(softwareBitmap);
            }
        }
Ejemplo n.º 25
0
        private async void _timer_Tick(object sender, object e)
        {
            try
            {
                if (!IsBusy)
                {
                    //IsBusy = true;
                    //var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;

                    //var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height);
                    //var previewFrame = await _mediaCapture.GetPreviewFrameAsync(videoFrame);

                    //var bitmap = new WriteableBitmap(previewFrame.SoftwareBitmap.PixelWidth, previewFrame.SoftwareBitmap.PixelHeight);

                    //previewFrame.SoftwareBitmap.CopyToBuffer(bitmap.PixelBuffer);
                    //await Task.Factory.StartNew(async () =>
                    //{
                    //    Log.Info(1);
                    //    await ScanBitmap(bitmap);
                    //});
                    IsBusy = true;
                    var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;

                    var bitmap    = new WriteableBitmap((int)previewProperties.Width, (int)previewProperties.Height);
                    var imgFormat = ImageEncodingProperties.CreateJpeg();

                    // Create LowLagPhotoCapture object
                    var lowLagCaptureMgr = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(imgFormat);

                    var photo = await lowLagCaptureMgr.CaptureAsync();

                    await bitmap.SetSourceAsync(photo.Frame);

                    //previewFrame.SoftwareBitmap.CopyToBuffer(bitmap.PixelBuffer);
                    await Task.Factory.StartNew(async() =>
                    {
                        await ScanBitmap(bitmap);
                    });
                }
                IsBusy = false;
                await Task.Delay(50);
            }
            catch (Exception ex)
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 26
0
        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            AddLog("開始");
            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

            await lowLagCapture.FinishAsync();


            using (IRandomAccessStream stream = new InMemoryRandomAccessStream())
            {
                // Create the decoder from the stream
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                // Get the SoftwareBitmap representation of the file
                softwareBitmap = await decoder.GetSoftwareBitmapAsync();


                // Create an encoder with the desired format
                BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);

                // Set the software bitmap
                encoder.SetSoftwareBitmap(softwareBitmap);

                await encoder.FlushAsync();



                //ビットマップにして表示
                System.IO.Stream stream2 = System.IO.WindowsRuntimeStreamExtensions.AsStream(stream);
                var img = System.Drawing.Bitmap.FromStream(stream2);
                //this.pictureBox1.Image = img;
                //img.Save(Environment.SpecialFolder.Desktop + @"\aaa.bmp");

                AddLog("表示");
                // 画面に表示
                var a = System.Windows.Media.Imaging.BitmapFrame.Create(stream2, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad);
                PreviewFrameImage.Source = a;
            }

            AddLog("修了");
        }
Ejemplo n.º 27
0
        //Should return a base64 encoded string
        private async Task <string> _Capture()
        {
            // Prepare and capture photo
            var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateJpeg());

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            byte[] bytes = new byte[capturedPhoto.Frame.Size];
            await capturedPhoto.Frame.AsStream().ReadAsync(bytes, 0, bytes.Length);

            //var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

            await lowLagCapture.FinishAsync();

            var response = Convert.ToBase64String(bytes);

            return(response);
        }
Ejemplo n.º 28
0
        public async Task <SoftwareBitmap> CaptureAsync()
        {
            try
            {
                var lowLagCapture = await defaultManager.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                var capturedPhoto = await lowLagCapture.CaptureAsync();

                var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;
                await lowLagCapture.FinishAsync();

                return(softwareBitmap);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 29
0
        private async void captureQr(object sender, object e)
        {
            try{
                mediaCapture = new MediaCapture();
                await mediaCapture.InitializeAsync();

                // Prepare and capture photo
                var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                var capturedPhoto = await lowLagCapture.CaptureAsync();

                var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

                BarcodeReader r   = new BarcodeReader();
                Result        res = r.Decode(softwareBitmap);
                if (res != null)
                {
                    Passagier passagier = ((App)Application.Current).Zetel.Passagier;
                    if (res.Text == "admin")
                    {
                        Frame.Navigate(typeof(LoginPersoneel), null, new DrillInNavigationTransitionInfo());
                    }
                    if (passagier.getCode() == res.Text)
                    {
                        Frame.Navigate(typeof(MainPage), null, new DrillInNavigationTransitionInfo());
                    }
                    else
                    {
                        myStoryboard.Begin();
                        Melding.Text = "Verkeerde boarding pass";
                    }
                }
                await lowLagCapture.FinishAsync();
            }catch (UnauthorizedAccessException ex)
            {
                Melding.Opacity = 1;
                Melding.Text    = "Geen toegang tot webcam of microfoon kijk naar de readme";
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Trigger take photo and recognize the emotion present in the image
        /// </summary>
        private async void ButtonRun_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Prepare and capture photo
                var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                var capturedPhoto = await lowLagCapture.CaptureAsync();

                var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

                await lowLagCapture.FinishAsync();

                // Display the captured image
                var imageSource      = new SoftwareBitmapSource();
                var displayableImage = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                await imageSource.SetBitmapAsync(displayableImage);

                PreviewImage.Source = imageSource;

                // Crop, Resize and Convert to gray scale the image (FERPlus model expects a grayscale image of 64x64 pixels)
                var rgbaImage     = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied);
                var mindim        = Math.Min(rgbaImage.PixelWidth, rgbaImage.PixelHeight);
                var croppedBitmap = CropSoftwareBitmap(rgbaImage,
                                                       rgbaImage.PixelWidth / 2 - mindim / 2,
                                                       rgbaImage.PixelHeight / 2 - mindim / 2,
                                                       mindim, mindim);
                var scaledBitmap    = ResizeSoftwareBitmap(croppedBitmap, 64, 64);
                var grayscaleBitmap = SoftwareBitmap.Convert(scaledBitmap, BitmapPixelFormat.Gray8, BitmapAlphaMode.Ignore);

                // Finally, Predict the dominat emotion present in the image (assuming that the image predominatly shows a face)
                VideoFrame inputImage = VideoFrame.CreateWithSoftwareBitmap(grayscaleBitmap);
                await Task.Run(async() =>
                {
                    // Evaluate the image
                    await EvaluateVideoFrameAsync(inputImage);
                });
            }
            catch (Exception ex)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => StatusBlock.Text = $"error: {ex.Message}");
            }
        }