Пример #1
0
        public void DescribeImageInStreamTest()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "DescribeImageInStreamTest");

                using (IComputerVisionClient client = GetComputerVisionClient(HttpMockServer.CreateInstance()))
                    using (FileStream stream = new FileStream(GetTestImagePath("house.jpg"), FileMode.Open))
                    {
                        ImageDescription result = client.DescribeImageInStreamAsync(stream).Result;

                        Assert.Matches("^\\d{4}-\\d{2}-\\d{2}(-preview)?$", result.ModelVersion);
                        Assert.Equal(result.Tags, new string[] {
                            "grass",
                            "outdoor",
                            "sky",
                            "house",
                            "building",
                            "green",
                            "lawn",
                            "residential",
                            "grassy"
                        });
                        Assert.Equal(1, result.Captions.Count);
                        Assert.Equal("a house with a flag on the front", result.Captions[0].Text);
                        Assert.True(result.Captions[0].Confidence > 0.41);
                    }
            }
        }
Пример #2
0
        public void DescribeImageInStreamTest()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "DescribeImageInStreamTest");

                using (IComputerVisionClient client = GetComputerVisionClient(HttpMockServer.CreateInstance()))
                    using (FileStream stream = new FileStream(GetTestImagePath("house.jpg"), FileMode.Open))
                    {
                        ImageDescription result = client.DescribeImageInStreamAsync(stream).Result;

                        Assert.Equal(result.Tags, new string[] {
                            "grass",
                            "outdoor",
                            "house",
                            "building",
                            "green",
                            "yard",
                            "lawn",
                            "front",
                            "small",
                            "field",
                            "home",
                            "red",
                            "sitting",
                            "grassy",
                            "brick",
                            "white",
                            "large",
                            "old",
                            "standing",
                            "grazing",
                            "sheep",
                            "parked",
                            "garden",
                            "woman",
                            "man",
                            "sign"
                        });
                        Assert.Equal(1, result.Captions.Count);
                        Assert.Equal("a large lawn in front of a house", result.Captions[0].Text);
                        Assert.True(result.Captions[0].Confidence > 0.96);
                    }
            }
        }
Пример #3
0
        public void DescribeImageModelVersionTest()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "DescribeImageModelVersionTest");

                using (IComputerVisionClient client = GetComputerVisionClient(HttpMockServer.CreateInstance()))
                    using (FileStream stream = new FileStream(GetTestImagePath("house.jpg"), FileMode.Open))
                    {
                        const string targetModelVersion = "2021-04-01";

                        ImageDescription result = client.DescribeImageInStreamAsync(
                            stream,
                            modelVersion: targetModelVersion).Result;

                        Assert.Equal(targetModelVersion, result.ModelVersion);
                    }
            }
        }
        public async Task <string> ProcessImageFileForCaptionAsync(
            FileInfo file, ImageInfo newImage)
        {
            string           caption = string.Empty;
            ImageDescription description;

            try
            {
                using (FileStream stream = file.OpenRead())
                {
                    description = await computerVisionClient.DescribeImageInStreamAsync(stream);
                }
                if (description.Captions.Count > 0)
                {
                    caption = description.Captions[0].Text;
                }
                newImage.Caption = caption;
            }
            catch (ComputerVisionErrorException cve)
            {
                Debug.WriteLine("ProcessImageFileForCaptionAsync: " + cve.Message);
            }
            return(caption);
        }