示例#1
0
        //Get the list of files previously uploaded to the server.
        private async void GetListOfFilesOnServer()
        {
            //Defines web address to upload photos to
            var AWSServer = "http://seefood-dev2.us-east-2.elasticbeanstalk.com/";

            try
            {
                HttpClient serverClient = new HttpClient();
                var        response     = await serverClient.GetAsync(AWSServer);

                string        responseString = response.Content.ReadAsStringAsync().Result;
                ImagesFromAWS imagesFromAWS  = JsonConvert.DeserializeObject <ImagesFromAWS>(responseString);
                Debug.WriteLine(imagesFromAWS);
                foreach (Item pathItem in imagesFromAWS.photos)
                {
                    string imageFilePath = pathItem.File;
                    //Parse filename to get classification and confidence
                    string[] splitFilePath = imageFilePath.Split('/');
                    string   fileName      = splitFilePath[splitFilePath.Length - 1];
                    Console.WriteLine(fileName);
                    string[] splitFileName = fileName.Split('-');


                    AWSClassification newClassification = new AWSClassification();
                    newClassification.Classification = Convert.ToInt32(splitFileName[0]);
                    newClassification.Confidence     = Convert.ToDouble(splitFileName[1]);
                    newClassification.Filename       = imageFilePath;

                    Console.WriteLine("FoodOrNot: {0}", newClassification.Classification);
                    Console.WriteLine("Confidence: {0}", newClassification.Confidence);
                    Console.WriteLine("Filepath: {0}", newClassification.Filename);

                    previousClassifications.Add(newClassification);
                }
                GetImages();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred: " + ex.ToString());
                return;
            }
        }
示例#2
0
        //Send Images To AWS
        public static async void ClassifyImage(Dictionary <Image, byte[]> imagesToUpload)
        {
            //Defines web address to upload photos to
            var AWSServer = "http://seefood-dev2.us-east-2.elasticbeanstalk.com/upload";

            try
            {
                //Iterate through all images passed in (should only be one at a time)
                foreach (KeyValuePair <Image, byte[]> uploadData in imagesToUpload)
                {
                    //Get byte array of image
                    var byteArrayToUpload = uploadData.Value;

                    //Set up HTTP client and data to upload (byte array) THIS MAY NOT WORK
                    HttpClient serverClient = new HttpClient();
                    MultipartFormDataContent uploadDataContent = new MultipartFormDataContent();
                    ByteArrayContent         byteArrayContent  = new ByteArrayContent(byteArrayToUpload);
                    string fileName = "SeeFoodUpload" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".png";
                    uploadDataContent.Add(byteArrayContent, "file", fileName);

                    //Get server response
                    var response = await serverClient.PostAsync(AWSServer, uploadDataContent);

                    string responseString = response.Content.ReadAsStringAsync().Result;

                    AWSClassification responseClassification = JsonConvert.DeserializeObject <AWSClassification>(responseString);

                    Console.WriteLine(responseClassification.Filename);

                    //Put string of server response into dictionary associated with image.
                    serverResponses.Add(uploadData.Key, responseClassification);

                    Debug.WriteLine(responseString);
                }
                imagesToUpload.Clear();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred: " + ex.ToString());
                return;
            }
        }
示例#3
0
        //get images from aws server to display on page, also setups up any other necessary buttons or graphics
        private async Task GetImage()
        {
            if (serverResponses.Count > 0)
            {
                currentResponse = serverResponses.ElementAt(counter).Value;

                if (counter == 0)
                {
                    prevImage.Opacity = 0;
                }
                else
                {
                    prevImage.Opacity = 100;
                }
                if ((serverResponses.Count - 1) == counter)
                {
                    nextImage.Opacity = 0;
                }
                else
                {
                    nextImage.Opacity = 100;
                }
            }
            var filename = currentResponse.Filename;

            fp.Text = filename;
            if (currentResponse.Classification == 0)
            {
                confy.Text = "Food :)";
            }
            else
            {
                confy.Text = "Not food :(";
            }
            confidenceBar.Progress = currentResponse.Confidence / 100.0;
            confyPercent.Text      = Math.Round(currentResponse.Confidence, 2).ToString() + "%";
            options.Children.Add(confy, 0, 0);
            options.Children.Add(confidenceBar, 1, 0);
            SetColumnSpan(confidenceBar, 2);
            options.Children.Add(confyPercent, 1, 0);
            SetColumnSpan(confyPercent, 2);
            var AWSServer = "http://seefood-dev2.us-east-2.elasticbeanstalk.com/get-image?file=";

            try
            {
                HttpClient serverClient     = new HttpClient();
                var        imageFileRequest = AWSServer + currentResponse.Filename;
                var        response         = await serverClient.GetAsync(imageFileRequest);

                byte[] responseByteArray = response.Content.ReadAsByteArrayAsync().Result;
                Stream imageStream       = new MemoryStream(responseByteArray);
                Image  imageFromServer   = new Image
                {
                    Source = ImageSource.FromStream(() => imageStream),
                };
                testing.Children.Add(imageFromServer, 0, 0);
                SetColumnSpan(imageFromServer, 2);
                testing.Children.Add(nextImage, 1, 1);
                testing.Children.Add(prevImage, 0, 1);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred: " + ex.ToString());
            }
        }