Example #1
0
        private Task QueueFrameCapture(MediaCapture capture)
        {
            if (capture != this.mediaCapture)
            {
                return(Task.FromCanceled(new System.Threading.CancellationToken(true)));
            }

            var previewProperties = mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
            var videoFrame        = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height);

            return(mediaCapture.GetPreviewFrameAsync(videoFrame).AsTask().ContinueWith(preview => {
                var currentFrame = preview.Result;
                SoftwareBitmap previewFrame = currentFrame.SoftwareBitmap;
                return this.Counter.CountItems(previewFrame).ContinueWith(count => {
                    return Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                        if (count.IsFaulted)
                        {
                            Debug.WriteLine("Unable to count items in frame.");
                            return;
                        }
                        LabelCount record = new LabelCount();
                        record.TimeStamp = DateTime.UtcNow;
                        record.Label = "Car";
                        record.Count = count.Result;
                        this.LabelCountDAO.Save(record).ContinueWith(t => { Debug.WriteLine($"Complete: Image count of {count.Result} sent to DB."); });

                        this.lblName.Text = count.Result.ToString();
                    }).AsTask().ContinueWith(display => {
                        return QueueFrameCapture(capture);
                    });
                });
            }));
        }
        public async Task Save(LabelCount labelCount)
        {
            Uri baseUri = new Uri(@"http://localhost:5000/leapvision/api/v1.0/labeled_objects");
            var content = new StringContent(JsonConvert.SerializeObject(labelCount), Encoding.UTF8, "application/json");

            try
            {
                var client = httpHandler.Value;
                using (var message = await client.PostAsync(baseUri, content))
                {
                    if (message != null)
                    {
                        message.EnsureSuccessStatusCode();
                        Debug.Write(message.StatusCode);
                        var response = await message.Content.ReadAsStringAsync();
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Write(e.InnerException.InnerException);
            }

        }