Example #1
0
        public async Task PictureAnalyseAsync(Activity activity)
        {
            VisionServiceClient visionClient;

            string visionApiKey;

            visionApiKey = ConfigurationManager.AppSettings["VisionApiKey"];

            visionClient = new VisionServiceClient(visionApiKey);

            StringBuilder reply = new StringBuilder();

            //If the user uploaded an image, read it, and send it to the Vision API
            if (activity.Attachments.Any() && activity.Attachments.First().ContentType.Contains("image"))
            {
                //stores image url (parsed from attachment or message)
                string            uploadedImageUrl  = activity.Attachments.First().ContentUrl;
                StringConstructor stringConstructor = new StringConstructor();

                using (Stream imageFileStream = GetStreamFromUrl(uploadedImageUrl))
                {
                    StringConstructorSDK client = new StringConstructorSDK()
                    {
                        WebAppUrl = $"{ ConfigurationManager.AppSettings["WebAppUrl"] }"
                    };
                    reply.Append(await client.PictureAnalyseAsync(visionApiKey, imageFileStream));
                }
            }

            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(reply.ToString()));
        }
Example #2
0
        private async Task TakePicture(string conversID)
        {
            if (!WebcamService.IsInitialized)
            {
                await WebcamService.InitializeCameraAsync();

                await WebcamService.StartCameraPreviewAsync();
            }

            using (var stream = new InMemoryRandomAccessStream())
            {
                ImageEncodingProperties imgFormat = ImageEncodingProperties.CreatePng();

                // create storage file in local app storage
                StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                    "AdaPhotoTMP.png",
                    CreationCollisionOption.ReplaceExisting);

                // take photo
                await WebcamService.MediaCapture.CapturePhotoToStorageFileAsync(imgFormat, file);

                FileStream fileStream  = new FileStream(file.Path, FileMode.Open);
                Stream     streamFinal = fileStream.AsRandomAccessStream().AsStream();

                StringConstructorSDK client = new StringConstructorSDK()
                {
                    WebAppUrl = $"{ AppConfig.WebUri}"
                };

                try
                {
                    var activity = new Activity
                    {
                        From = new ChannelAccount("Jean"),
                        Text = "Picture from UWP",
                        Type = ActivityTypes.Message,
                        //Envoyer le stream
                        ChannelData = await client.PictureAnalyseAsync(AppConfig.Vision, streamFinal),
                        //ATTENTION CONVERSID DIFFERENT!!!!!
                        Name = conversID,
                        //Summary = serviceUrl
                    };
                    await _client.Conversations.PostActivityAsync(_conversation.ConversationId, activity);
                }
                catch (HttpRequestException)
                {
                    //Impossible to take picture
                }
            }
        }