async Task MakePredictionRequest(MediaFile file)
        {
            Contract.Ensures(Contract.Result <Task>() != null);
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", "a51ac8a57d4e4345ab0a48947a4a90ac");

            string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/4da1555c-14ca-4aaf-af01-d6e1e97e5fa6/image?iterationId=7bc76035-3825-4643-917e-98f9d9f79b71";

            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(file);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);


                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString);

                    double max = responseModel.Predictions.Max(m => m.Probability);

                    TagLabel.Text = (max >= 0.5) ? "Hotdog" : "Not hotdog";
                }

                //Get rid of file once we have finished using it
                file.Dispose();
            }
        }
Example #2
0
        async Task MakePredictionRequest(MediaFile file)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", "fccf9a9570824165a73e1ae985ea3a3f");

            string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/9fd6cd33-960c-4582-b989-4f0afb9a8c52/image?iterationId=3ade55a7-99cd-43da-8a8b-d16839b3899e";

            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(file);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);


                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString);

                    double max = responseModel.Predictions.Max(m => m.Probability);

                    TagLabel.Text        = (max >= 0.5) ? "Hotdog:" : "Not hotdog:";
                    PredictionLabel.Text = max.ToString() + "%";
                }
                //Get rid of file once we have finished using it
                file.Dispose();
            }
        }
        async Task MakePredictionRequest(MediaFile file)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", "0045ceeffcb84ab996d74b02f31e1b9d");

            string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/84b2f69a-de27-4f32-b610-a12ff5f6c27a/image?iterationId=28883c94-614f-4e19-a328-f0a08d562197";

            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(file);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);


                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString);

                    double max = responseModel.Predictions.Max(m => m.Probability);

                    TagLabel.Text = (max >= 0.5) ? "Mobile" : "Not Mobile";
                }

                //Get rid of file once we have finished using it
                file.Dispose();
            }
        }
Example #4
0
        async Task MakePredictionRequest(MediaFile file)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", "212601d8ea68473e95e11d756d23a745");

            string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/2ff50d41-5b0a-419c-b01c-74978fb61f1e/image?iterationId=ce1d2973-8243-4360-9fa6-56d4b7979a11";

            HttpResponseMessage response;


            byte[] byteData = GetImageAsByteArray(file);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                response = await client.PostAsync(url, content);


                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString);

                    double max = responseModel.Predictions.Max(m => m.Probability);

                    List <Prediction> predictions = responseModel.Predictions;
                    string            tag         = "";

                    foreach (Prediction p in predictions)
                    {
                        if (p.Probability == max)
                        {
                            tag = p.Tag;
                        }
                    }



                    if (max >= 0.5)
                    {
                        TagLabel.Text = tag;
                        AzureManager.AzureManagerInstance.setTag(tag);
                    }
                    else
                    {
                        tag = "Car not found";
                        AzureManager.AzureManagerInstance.setTag(tag);
                        TagLabel.Text = tag;
                    }
                }


                file.Dispose();
            }
        }
Example #5
0
        async Task MakePredictionRequest(MediaFile file)
        {
            MyActivityIndicator.IsRunning = true;
            Contract.Ensures(Contract.Result <Task>() != null);
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", "4acc8969a66e4e6a8566c55658bbe9d2");

            string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/d1a68296-d332-4042-95e6-b7e27d9108ec/image?iterationId=6a37a80b-d46b-4cb9-ba20-ff9d2d586972";

            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(file);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);


                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString);

                    double max = responseModel.Predictions.Max(m => m.Probability);


                    if (max >= 0.5)
                    {
                        TagLabel.Text = "There is a heavy traffic in TinFactory";
                        await CrossTextToSpeech.Current.Speak(TagLabel.Text);

                        await Navigation.PushAsync(new redtrafficlightpage());

                        CrossLocalNotifications.Current.Show("Alert", "We have send the informaton to local concen autheroties");
                    }

                    else
                    {
                        TagLabel.Text = " There is no heavy Traffic in Tin Factory";
                        await CrossTextToSpeech.Current.Speak(TagLabel.Text);

                        await Navigation.PushAsync(new normaltrafficlightpage());
                    }

                    MyActivityIndicator.IsRunning = false;
                }

                //Get rid of file once we have finished using it
                file.Dispose();
            }
        }
Example #6
0
        async Task MakePredictionRequest(MediaFile file)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", "2b785ad623f047a0a511d9e14d9e7f2c");

            string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/226891aa-f1db-4015-a7a4-c9c383f3e158/image?iterationId=91ae0a9d-0b1d-447a-883a-76f8baf6de2e";

            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(file);


            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);


                if (response.IsSuccessStatusCode)
                {
                    TagLabel.Text        = "";
                    PredictionLabel.Text = "";

                    var responseString = await response.Content.ReadAsStringAsync();

                    EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString);
                    double          max           = responseModel.Predictions.Max(m => m.Probability);
                    JObject         rss           = JObject.Parse(responseString);

                    //Querying with LINQ
                    //Get all Prediction Values
                    var Probability = from p in rss["Predictions"] select(string) p["Probability"];
                    var Tag         = from p in rss["Predictions"] select(string) p["Tag"];

                    //Truncate values to labels in XAML
                    foreach (var item in Tag)
                    {
                        TagLabel.Text += item + ": \n";
                    }

                    foreach (var item in Probability)
                    {
                        PredictionLabel.Text += item + "\n";
                    }
                }

                //Get rid of file once we have finished using it
                file.Dispose();
            }
        }
Example #7
0
        async Task MakePredictionRequest(MediaFile file)
        {
            Contract.Ensures(Contract.Result <Task>() != null);
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", "4acc8969a66e4e6a8566c55658bbe9d2");

            string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.1/Prediction/ce6463c9-a4b5-4af6-aed2-18babd9f8483/image?iterationId=1ddec163-8098-4387-b095-fa55183c512e";

            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(file);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);


                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString);

                    double max = responseModel.Predictions.Max(m => m.Probability);


                    if (max >= 0.5)
                    {
                        TagLabel.Text = "There is a heavy traffic in TinFactory";
                        await CrossTextToSpeech.Current.Speak(TagLabel.Text);

                        await Navigation.PushAsync(new redtrafficlightpage());

                        CrossLocalNotifications.Current.Show("Alert", "We have send the informaton to local concen autheroties");
                    }

                    else
                    {
                        TagLabel.Text = " There is no heavy Traffic in Tin Factory";
                        await CrossTextToSpeech.Current.Speak(TagLabel.Text);

                        await Navigation.PushAsync(new normaltrafficlightpage());
                    }
                }

                //Get rid of file once we have finished using it
                file.Dispose();
            }
        }
Example #8
0
        async Task MakePredictionRequest(MediaFile file)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Prediction-Key", "c03a2b1920814aa6b76f909335d6caac");

            string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/6f01caf1-69d3-47f6-bebf-7fc26900a96e/image?iterationId=464a5036-2f1e-4d20-b92e-0631e294656f";

            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(file);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);

                string tag = "";

                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString);

                    double max = responseModel.Predictions.Max(m => m.Probability);

                    List <Prediction> predictions = responseModel.Predictions;

                    foreach (Prediction p in predictions)
                    {
                        if (p.Probability == max)
                        {
                            tag = p.Tag;
                        }
                    }
                }
                await getDetails(tag);

                file.Dispose();
            }
        }