Esempio n. 1
0
        public async Task<ActionResult> AnalyzeInDomain()
        {
            var result = await visionClient.AnalyzeImageInDomainAsync(
                "https://i.ndtvimg.com/i/2017-10/taj-mahal-unsplash-650_650x400_51508150014.jpg",
                "landmarks"
                );

            var result1 = await visionClient.AnalyzeImageInDomainAsync(
                "https://i.ndtvimg.com/i/2016-10/amitabh-bachchan_650x400_61476137341.jpg",
                "celebrities"
                );

            return View();
        }
Esempio n. 2
0
        private async Task <AnalysisInDomainResult> UploadAndAnalyzeImage(MediaFile file, Model domainModel)
        {
            AnalysisInDomainResult analysisResult =
                await visionServiceClient.AnalyzeImageInDomainAsync(file.GetStream(), domainModel);

            return(analysisResult);
        }
Esempio n. 3
0
        /// <summary>
        /// Uploads the image to Project Oxford and performs analysis against a given domain
        /// </summary>
        /// <param name="imageFilePath">The image file path.</param>
        /// <param name="domainModel">The domain model to analyze against</param>
        /// <returns></returns>
        private async Task <AnalysisInDomainResult> UploadAndAnalyzeInDomainImage(string imageFilePath, Model domainModel)
        {
            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE STARTS HERE
            // -----------------------------------------------------------------------

            //
            // Create Project Oxford Vision API Service client
            //
            VisionServiceClient VisionServiceClient = new VisionServiceClient(SubscriptionKey, SubscriptionEndpoint);

            Log("VisionServiceClient is created");

            using (Stream imageFileStream = File.OpenRead(imageFilePath))
            {
                //
                // Analyze the image for the given domain
                //
                Log("Calling VisionServiceClient.AnalyzeImageInDomainAsync()...");
                AnalysisInDomainResult analysisResult = await VisionServiceClient.AnalyzeImageInDomainAsync(imageFileStream, domainModel);

                return(analysisResult);
            }

            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE ENDS HERE
            // -----------------------------------------------------------------------
        }
Esempio n. 4
0
        /// <summary>
        /// Sends a url to Project Oxford and performs analysis against a given domain
        /// </summary>
        /// <param name="imageUrl">The url of the image to analyze</param>
        /// <param name="domainModel">The domain model to analyze against</param>
        /// <returns></returns>
        private async Task <AnalysisInDomainResult> AnalyzeInDomainUrl(string imageUrl, Model domainModel)
        {
            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE STARTS HERE
            // -----------------------------------------------------------------------

            //
            // Create Project Oxford Vision API Service client
            //
            VisionServiceClient VisionServiceClient = new VisionServiceClient(SubscriptionKey, SubscriptionEndpoint);

            Log("VisionServiceClient is created");

            //
            // Analyze the url against the given domain
            //
            Log("Calling VisionServiceClient.AnalyzeImageInDomainAsync()...");
            AnalysisInDomainResult analysisResult = await VisionServiceClient.AnalyzeImageInDomainAsync(imageUrl, domainModel);

            return(analysisResult);

            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE ENDS HERE
            // -----------------------------------------------------------------------
        }
        /// <summary> Function which submits a frame to the Computer Vision API for celebrity
        ///     detection. </summary>
        /// <param name="frame"> The video frame to submit. </param>
        /// <returns> A <see cref="Task{LiveCameraResult}"/> representing the asynchronous API call,
        ///     and containing the celebrities returned by the API. </returns>
        private async Task <LiveCameraResult> CelebrityAnalysisFunction(VideoFrame frame)
        {
            // Encode image.
            var jpg = frame.Image.ToMemoryStream(".jpg", s_jpegParams);
            // Submit image to API.
            var result = await _visionClient.AnalyzeImageInDomainAsync(jpg, "celebrities");

            // Count the API call.
            Properties.Settings.Default.VisionAPICallCount++;
            // Output.
            var celebs = JsonConvert.DeserializeObject <CelebritiesResult>(result.Result.ToString()).Celebrities;
            LiveCameraResult _result = new LiveCameraResult
            {
                TimeStamp = DateTime.Now,
                // Extract face rectangles from results.
                Faces = celebs.Select(c => CreateFace(c.FaceRectangle)).ToArray(),
                // Extract celebrity names from results.
                CelebrityNames = celebs.Select(c => c.Name).ToArray()
            };

            TotalAPIResults.Add(_result);
            ApiResult = _result;
            analysisLog.SaveData(_result);
            return(_result);
        }
        public async Task <AnalysisInDomainResult> MakeAnalysisRequest(Stream stream, Model model)
        {
            // OcrResults text;
            VisionServiceClient    client         = new VisionServiceClient(SubscriptionKey, apiRoot);
            AnalysisInDomainResult analysisResult = await client.AnalyzeImageInDomainAsync(stream, model);

            return(analysisResult);
        }
Esempio n. 7
0
        public async Task <AllLandmarks> DescribePhoto(Stream photo)
        {
            try
            {
                var descReturn = await client.AnalyzeImageInDomainAsync(photo, landmark_model);

                if (!(descReturn.Result is JContainer container))
                {
                    return(null);
                }

                var landmarks = container.ToObject <AllLandmarks>();

                return(landmarks);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        private async Task <AnalysisInDomainResult> AnalyzePictureDomainAsync(Stream inputFile)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                await DisplayAlert("Network error",
                                   "Please check your network connection and retry.", "OK");

                return(null);
            }
            AnalysisInDomainResult analysisResult =
                await visionClient.AnalyzeImageInDomainAsync(inputFile, await GetDomainModel());

            return(analysisResult);
        }
Esempio n. 9
0
        /// <summary> Function which submits a frame to the Computer Vision API for celebrity
        ///     detection. </summary>
        /// <param name="frame"> The video frame to submit. </param>
        /// <returns> A <see cref="Task{LiveCameraResult}"/> representing the asynchronous API call,
        ///     and containing the celebrities returned by the API. </returns>
        private async Task <LiveCameraResult> CelebrityAnalysisFunction(VideoFrame frame)
        {
            // Encode image.
            var jpg = frame.Image.ToMemoryStream(".jpg", s_jpegParams);
            // Submit image to API.
            var result = await _visionClient.AnalyzeImageInDomainAsync(jpg, "celebrities");

            // Output.
            var celebs = JsonConvert.DeserializeObject <CelebritiesResult>(result.Result.ToString()).Celebrities;

            return(new LiveCameraResult
            {
                // Extract face rectangles from results.
                Faces = celebs.Select(c => CreateFace(c.FaceRectangle)).ToArray(),
                // Extract celebrity names from results.
                CelebrityNames = celebs.Select(c => c.Name).ToArray()
            });
        }
Esempio n. 10
0
        /// <summary>
        /// Detect all celebrities in a given image.
        /// </summary>
        /// <param name="image">The image to check for celebrities.</param>
        /// <returns>An AnalysisResult instance that describes each celebrity in the image.</returns>
        private async Task <Celebrity[]> DetectCelebrities(BitmapImage image)
        {
            // write the image to a stream
            var stream  = new MemoryStream();
            var encoder = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(image));
            encoder.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);

            // analyze image and look for celebrities
            var visionClient = new VisionServiceClient(VISION_KEY, VISION_API);
            var analysis     = await visionClient.AnalyzeImageInDomainAsync(stream, "celebrities");

            // cast result to c# class
            var celebritiesResults = JsonConvert.DeserializeObject <CelebritiesResult>(analysis.Result.ToString());

            return(celebritiesResults.Celebrities);
        }
        /// <summary>
        /// Uploads the image to Project Oxford and performs analysis against a given domain
        /// </summary>
        /// <param name="imageFilePath">The image file path.</param>
        /// <param name="domainModel">The domain model to analyze against</param>
        /// <returns></returns>
        private async Task<AnalysisInDomainResult> UploadAndAnalyzeInDomainImage(string imageFilePath, Model domainModel)
        {
            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE STARTS HERE
            // -----------------------------------------------------------------------

            //
            // Create Project Oxford Vision API Service client
            //
            VisionServiceClient VisionServiceClient = new VisionServiceClient(SubscriptionKey);
            Log("VisionServiceClient is created");

            using (Stream imageFileStream = File.OpenRead(imageFilePath))
            {
                //
                // Analyze the image for the given domain
                //
                Log("Calling VisionServiceClient.AnalyzeImageInDomainAsync()...");
                AnalysisInDomainResult analysisResult = await VisionServiceClient.AnalyzeImageInDomainAsync(imageFileStream, domainModel);
                return analysisResult;
            }

            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE ENDS HERE
            // -----------------------------------------------------------------------
        }
        /// <summary>
        /// Sends a url to Project Oxford and performs analysis against a given domain
        /// </summary>
        /// <param name="imageUrl">The url of the image to analyze</param>
        /// <param name="domainModel">The domain model to analyze against</param>
        /// <returns></returns>
        private async Task<AnalysisInDomainResult> AnalyzeInDomainUrl(string imageUrl, Model domainModel)
        {
            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE STARTS HERE
            // -----------------------------------------------------------------------

            //
            // Create Project Oxford Vision API Service client
            //
            VisionServiceClient VisionServiceClient = new VisionServiceClient(SubscriptionKey);
            Log("VisionServiceClient is created");

            //
            // Analyze the url against the given domain
            //
            Log("Calling VisionServiceClient.AnalyzeImageInDomainAsync()...");
            AnalysisInDomainResult analysisResult = await VisionServiceClient.AnalyzeImageInDomainAsync(imageUrl, domainModel);
            return analysisResult;

            // -----------------------------------------------------------------------
            // KEY SAMPLE CODE ENDS HERE
            // -----------------------------------------------------------------------
        }
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                ConnectorClient connector     = new ConnectorClient(new Uri(activity.ServiceUrl));
                Activity        reply         = activity.CreateReply();
                Activity        reply_cat     = activity.CreateReply();
                Activity        reply_tag     = activity.CreateReply();
                Activity        reply_face    = activity.CreateReply();
                Activity        reply_emotion = activity.CreateReply();
                Activity        reply_img     = activity.CreateReply();
                Activity        reply_bt      = activity.CreateReply();
                //List<Activity> reply_ptt_list=null;
                //db
                var cb = new SqlConnectionStringBuilder();
                cb.DataSource     = "nbadata.database.windows.net";
                cb.UserID         = "nbadata";
                cb.Password       = "******";
                cb.InitialCatalog = "NBADATA";
                //----s
                if (activity.Attachments?.Count > 0 && activity.Attachments.First().ContentType.StartsWith("image"))
                {
                    var url = activity.Attachments.First().ContentUrl;
                    //emotion api
                    EmotionServiceClient emo_client = new EmotionServiceClient("95a490338ba54f908c05e65d82e14b69", "https://westus.api.cognitive.microsoft.com/emotion/v1.0");
                    var emo_result = await emo_client.RecognizeAsync(url);

                    //辨識圖片
                    VisionServiceClient client = new VisionServiceClient("cf9176a0c5dd4784ad4cc3467a778924", "https://westcentralus.api.cognitive.microsoft.com/vision/v1.0");
                    //VisualFeature[] { VisualFeature.Description }矩陣列舉,在此指使用描述
                    var result = await client.AnalyzeImageAsync(url, new VisualFeature[] { VisualFeature.Description, VisualFeature.Categories, VisualFeature.Faces, VisualFeature.ImageType, VisualFeature.Tags });

                    var celebritiesResult = await client.AnalyzeImageInDomainAsync(url, "celebrities");

                    string tag_name = "Picture tags: ";
                    foreach (var item in result.Tags)
                    {
                        tag_name += item.Name.ToString() + ",";
                    }
                    //string cat_name = "Categories of picture: ";
                    string cname = JObject.Parse(celebritiesResult.Result.ToString())["celebrities"].ToString();
                    if (cname.Length > 2)
                    {
                        cname = JObject.Parse(JObject.Parse(celebritiesResult.Result.ToString())["celebrities"][0].ToString())["name"].ToString();
                    }
                    string cele = JObject.Parse(celebritiesResult.Result.ToString())["celebrities"].ToString();
                    if (cele.Length > 2)
                    {
                        cele = "Probably " + JObject.Parse(JObject.Parse(celebritiesResult.Result.ToString())["celebrities"][0].ToString())["name"].ToString();
                    }
                    else
                    {
                        cele = "unrecognized man";
                    }
                    //foreach (var item in result.Categories) cat_name += item.Name.ToString() + "\t";

                    /*string face = "Face in picture: ";
                     * if (result.Faces.Length == 0) face += "No face.";
                     * foreach (var item in result.Faces) face += "Gender: "+ item.Gender.ToString() + "\t"+"Age: "+item.Age.ToString()+"\n";
                     */
                    string emo = "Emotion detection: ";
                    if (emo_result.Length == 0)
                    {
                        emo += "No face.";
                    }
                    foreach (var item in emo_result)
                    {
                        if (item.Scores.Anger > 0.01)
                        {
                            emo += "Anger, ";
                        }
                        if (item.Scores.Contempt > 0.01)
                        {
                            emo += "Contempt, ";
                        }
                        if (item.Scores.Disgust > 0.01)
                        {
                            emo += "Disgust, ";
                        }
                        if (item.Scores.Fear > 0.01)
                        {
                            emo += "Fear, ";
                        }
                        if (item.Scores.Happiness > 0.01)
                        {
                            emo += "Happiness, ";
                        }
                        if (item.Scores.Neutral > 0.01)
                        {
                            emo += "Neutral, ";
                        }
                        if (item.Scores.Sadness > 0.01)
                        {
                            emo += "Sadness, ";
                        }
                        if (item.Scores.Surprise > 0.01)
                        {
                            emo += "Surprise, ";
                        }
                    }



                    reply.Text = "Description: " + result.Description.Captions.First().Text;
                    //reply_cat.Text = cat_name;
                    //reply_tag.Text = tag_name;
                    //reply_face.Text = face;
                    reply_emotion.Text = emo;
                    reply_img.Text     = cele;
                    if (reply_img.Text != "unrecognized man")
                    {
                        Service(reply_bt, cname);
                    }
                }
                else
                {
                    if (activity.Text.Contains("&"))
                    {
                        //reply.Text = activity.Text.Substring(0, activity.Text.IndexOf('-'));
                        switch (activity.Text.Substring(0, activity.Text.IndexOf('&')))
                        {
                        case "PTT":
                            //reply.Text = activity.Text.Substring(activity.Text.IndexOf('&') +1 , (activity.Text.Length - activity.Text.IndexOf('&') -1));
                            // select ptt by name
                            using (var connection = new SqlConnection(cb.ConnectionString))
                            {
                                connection.Open();
                                reply.Text = Submit_PTT_Select(connection, activity.Text.Substring(activity.Text.IndexOf('&') + 1, (activity.Text.Length - activity.Text.IndexOf('&') - 1)));
                            }
                            break;

                        case "career stat":
                            //reply.Text = activity.Text.Substring(activity.Text.IndexOf('&') +1 , (activity.Text.Length - activity.Text.IndexOf('&') -1));
                            // select stat by name
                            using (var connection = new SqlConnection(cb.ConnectionString))
                            {
                                connection.Open();
                                reply.Text = Submit_Player_Stat_Select(connection, activity.Text.Substring(activity.Text.IndexOf('&') + 1, (activity.Text.Length - activity.Text.IndexOf('&') - 1)));
                            }
                            break;

                        default:
                            reply.Text = activity.Text;
                            break;
                        }
                    }
                    else
                    {
                        /*string message = string.Empty;
                         * try
                         * {
                         *  var audioAttachment2 = activity.Attachments?.FirstOrDefault(a => a.ContentType.Equals("video/mp4") || a.ContentType.Contains("audio") || a.ContentType.Contains("video"));
                         *  var audioAttachment = activity.Attachments?.FirstOrDefault(a => a.ContentType.Equals("audio/wav") || a.ContentType.Equals("application/octet-stream"));
                         *  if (audioAttachment != null)
                         *  {
                         *
                         *      var stream = await GetAudioStream(connector, audioAttachment);
                         *      var text = await this.speechService.GetTextFromAudioAsync(stream);
                         *      message = ProcessText(text);
                         *      reply = activity.CreateReply(message);
                         *      await connector.Conversations.ReplyToActivityAsync(reply);
                         *
                         *  }
                         *  else if (audioAttachment2 != null)
                         *  {
                         *
                         *      IncomingFacebookVoiceMessage voice = new IncomingFacebookVoiceMessage(activity);
                         *      try
                         *      {
                         *
                         *          if (voice != null)
                         *          {
                         *
                         *              //Download original MP4 voice message
                         *              voice.DownloadFile();
                         *              throw new Exception("ddffdfdfdfdfdfdfdfdffdf");
                         *              var mp4 = voice.GetLocalPathAndFileName();
                         *
                         *              //Convert MP4 to WAV
                         *              var wavFolder = "D:" + @"\" + "home" + @"\" + "site" + @"\" + "wwwroot" + @"\" + "bin" + @"\" + "en";
                         *              var converter = new AudioFileFormatConverter(mp4, wavFolder);
                         *              var wav = converter.ConvertMP4ToWAV();
                         *
                         *
                         *              //Convert .WAV file to text
                         *              var bing = new MicrosoftCognitiveSpeechService(); //gets the path + filename
                         *
                         *
                         *
                         *              // convert string to stream
                         *
                         *              byte[] data = File.ReadAllBytes(wav);
                         *              //byte[] byteArray = Encoding.ASCII.GetBytes(contents);
                         *              MemoryStream stream = new MemoryStream(data);
                         *
                         *
                         *
                         *
                         *
                         *              var text = await this.speechService.GetTextFromAudioAsync(stream); //takes path+filename to WAV file, returns text
                         *
                         *              if (string.IsNullOrWhiteSpace(text))
                         *              {
                         *                  message = "Looks like you didn't say anything.";
                         *              }
                         *              else
                         *              {
                         *                  message = text;
                         *              }
                         *
                         *              //Clean up files from disk
                         *              voice.RemoveFromDisk();
                         *              converter.RemoveTargetFileFromDisk();
                         *          }
                         *
                         *      }
                         *      catch (Exception ex)
                         *      {
                         *          message = "Woah! " + ex.Message.Trim().Trim('.') + "!";
                         *      }
                         *
                         *
                         *
                         *  }
                         *  else
                         *  {
                         *      message = "Did you upload an audio file? I'm more of an audible person. Try sending me a wav file";
                         *  }
                         * }
                         * catch (Exception e)
                         * {
                         *  message = "Oops! Something went wrong. Try again later";
                         *  if (e is HttpException)
                         *  {
                         *      var httpCode = (e as HttpException).GetHttpCode();
                         *      if (httpCode == 401 || httpCode == 403)
                         *      {
                         *          message += $" [{e.Message} - hint: check your API KEY at web.config]";
                         *      }
                         *      else if (httpCode == 408)
                         *      {
                         *          message += $" [{e.Message} - hint: try send an audio shorter than 15 segs]";
                         *      }
                         *  }
                         *
                         *  Trace.TraceError(e.ToString());
                         * }
                         */
                        //-----------------------------------------

                        using (LuisClient client = new LuisClient("16f5717a-ee86-4074-abf4-603c9d6cd733", "c74954db4ddb4000bb6865cf07c2ad36"))
                        {
                            var result = await client.Predict(activity.Text);

                            List <string> Teams = new List <string>();
                            List <string> Date = new List <string>();
                            string        Players = "", temp, teamdate = "", playerdate = "";

                            List <string> OUTPUT = new List <string>();// team team date



                            foreach (var OneItem in result.Entities)
                            {
                                foreach (var Item in OneItem.Value)
                                {
                                    //reply.Text += Item.ParentType + "   " + Item.Value + "\n";
                                    //reply.Text += Item.Name + "   " + Item.Value + "   " + Item.Score + "   ";
                                    foreach (var r in Item.Resolution)
                                    {
                                        //reply.Text += r.Value.ToString() + "  \n";
                                        temp = r.Value.ToString();

                                        if (Item.Name == "Teams")
                                        {
                                            Teams.Add(temp);
                                        }
                                        else if (Item.Name == "Players")
                                        {
                                            Players = temp;
                                        }
                                        else if (Item.Name == "builtin.number")
                                        {
                                            Date.Add(temp);
                                        }
                                        //    Teams.Add(r.Value.ToString());
                                    }
                                }
                                //reply.Text += "Key = " + OneItem.Key + ", Value = " + OneItem.Value[0].Value + "\n";
                            }

                            //string[] DATE = Date.ToArray();
                            //reply.Text += Date.Count;
                            int digit = 1;
                            if (Date.Count > 1)
                            {
                                if (Date.Count == 2)
                                {
                                    teamdate   += "2017";
                                    playerdate += "2017";
                                    digit       = 0;
                                }
                                else
                                {
                                    teamdate   += Date[0];
                                    playerdate += Date[0];
                                }
                                int tem;
                                for (int i = digit; i < Date.Count; i++)
                                {
                                    tem = Convert.ToInt32(Date[i]);
                                    if (tem < 10)
                                    {
                                        temp        = Convert.ToString(tem);
                                        playerdate += "/" + temp;
                                        teamdate   += "/0" + temp;
                                    }
                                    else
                                    {
                                        playerdate += "/" + Date[i];
                                        teamdate   += "/" + Date[i];
                                    }
                                }
                            }
                            //reply.Text += result.TopScoringIntent.Name;

                            if (result.TopScoringIntent.Name == "Games" && teamdate != "")
                            {
                                for (int i = 0; i < Teams.Count; i++)
                                {
                                    Teams[i] = Teams[i].Remove(Teams[i].Length - 4, 4);
                                    Teams[i] = Teams[i].Remove(0, 6);
                                    OUTPUT.Add(Teams[i]);
                                    //reply.Text += Teams[i] + " ";
                                }
                                //reply.Text += teamdate;
                                OUTPUT.Add(teamdate);
                                //////////input Teams & Date
                            }
                            else if (result.TopScoringIntent.Name == "Personal Performance")
                            {
                                Players = Players.Remove(Players.Length - 4, 4);
                                Players = Players.Remove(0, 6);
                                //reply.Text += Players + playerdate;
                                OUTPUT.Add(Players);
                                if (playerdate != "")
                                {
                                    OUTPUT.Add(playerdate);
                                }
                                /////////input Players & Date
                            }
                            //else
                            //    reply.Text = "Please enter more details.";
                            //reply.Text += OUTPUT.Count;
                            switch (OUTPUT.Count)
                            {
                            case 3:    //team+team+date
                                //reply.Text += OUTPUT[0];
                                //reply.Text += OUTPUT[1];
                                //reply.Text += OUTPUT[2];
                                using (var connection = new SqlConnection(cb.ConnectionString))
                                {
                                    connection.Open();
                                    //reply.Text = OUTPUT[2]+OUTPUT[0]+ OUTPUT[1] ;
                                    reply.Text = Submit_Team_Select(connection, OUTPUT[2], OUTPUT[0], OUTPUT[1]);
                                }
                                break;

                            case 2:    //player+date
                                //reply.Text += OUTPUT[0];
                                //reply.Text += OUTPUT[1];
                                using (var connection = new SqlConnection(cb.ConnectionString))
                                {
                                    connection.Open();
                                    reply.Text = Submit_Player_Stat_Select(connection, OUTPUT[0], OUTPUT[1]);
                                }
                                break;

                            case 1:    //player
                                //reply.Text += OUTPUT[0];
                                Service(reply_bt, OUTPUT[0]);
                                break;

                            default:
                                reply.Text = "Please enter more details.";
                                break;
                            }
                            //reply.Text = team1 + team2 + player + dt;
                        }
                    }
                }



                await connector.Conversations.ReplyToActivityAsync(reply);

                //await connector.Conversations.ReplyToActivityAsync(reply_cat);

                /*await connector.Conversations.ReplyToActivityAsync(reply_tag);
                 * await connector.Conversations.ReplyToActivityAsync(reply_face);*/
                await connector.Conversations.ReplyToActivityAsync(reply_emotion);

                await connector.Conversations.ReplyToActivityAsync(reply_img);

                await connector.Conversations.ReplyToActivityAsync(reply_bt);

                /*foreach (var item in reply_ptt_list)
                 * {
                 *  await connector.Conversations.ReplyToActivityAsync(item);
                 * }*/
            }



            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
Esempio n. 14
0
        public static CelebrityAnalysisResult AnalyzeImageForCelebrities(Bitmap sourceImage)
        {
            VisionServiceClient VisionServiceClient = ComputerVisionService.GetClient();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                sourceImage.SaveAsPng(memoryStream);
                memoryStream.Position = 0;

                Console.WriteLine("Calling VisionServiceClient.AnalyzeImageInDomainAsync()...");

                // This is how you'd recognize celebrities like Henry Clay
                Microsoft.ProjectOxford.Vision.Contract.AnalysisInDomainResult result = VisionServiceClient.AnalyzeImageInDomainAsync(memoryStream, "celebrities").GetAwaiter().GetResult();

                Newtonsoft.Json.Linq.JObject jsonObj = result.Result as Newtonsoft.Json.Linq.JObject;

                CelebrityAnalysisResult celebResult = jsonObj.ToObject <CelebrityAnalysisResult>() as CelebrityAnalysisResult;
                return(celebResult);
            }
        }