public async void RegionManipulation() { using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "RegionManipulation", RecorderMode); using (var project = CreateTrainedObjDetectionProject()) using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient()) { var existingImage = (await client.GetTaggedImagesAsync(project.ProjectId)).First(); Assert.NotNull(existingImage); var testTag = await client.CreateTagAsync(project.ProjectId, tagName); var proposal = await client.GetImageRegionProposalsAsync(project.ProjectId, existingImage.Id); Assert.True(proposal.Proposals.Count > 0); Assert.Equal(project.ProjectId, proposal.ProjectId); Assert.Equal(existingImage.Id, proposal.ImageId); Assert.InRange(proposal.Proposals[0].Confidence, 0, 1); var bbox = proposal.Proposals[0].BoundingBox; List <ImageRegionCreateEntry> newRegions = new List <ImageRegionCreateEntry>(); newRegions.Add(new ImageRegionCreateEntry(existingImage.Id, testTag.Id, bbox.Left, bbox.Top, bbox.Width, bbox.Height)); var regions = await client.CreateImageRegionsAsync(project.ProjectId, new ImageRegionCreateBatch(newRegions)); Assert.Equal(1, regions.Created.Count); Assert.Equal(0, regions.Duplicated.Count); Assert.Equal(0, regions.Exceeded.Count); Assert.Equal(bbox.Top, regions.Created[0].Top); Assert.Equal(bbox.Left, regions.Created[0].Left); Assert.Equal(bbox.Width, regions.Created[0].Width); Assert.Equal(bbox.Height, regions.Created[0].Height); Assert.Equal(existingImage.Id, regions.Created[0].ImageId); Assert.Equal(testTag.Id, regions.Created[0].TagId); Assert.NotEqual(Guid.Empty, regions.Created[0].RegionId); var image = await client.GetImagesByIdsAsync(project.ProjectId, new List <Guid>(new Guid[] { existingImage.Id })); Assert.Equal(1, image.Count); Assert.Equal(2, image[0].Regions.Count); await client.DeleteImageRegionsAsync(project.ProjectId, new List <Guid>(new Guid[] { regions.Created[0].RegionId })); image = await client.GetImagesByIdsAsync(project.ProjectId, new List <Guid>(new Guid[] { existingImage.Id })); Assert.Equal(1, image.Count); Assert.Equal(1, image[0].Regions.Count); await client.DeleteTagAsync(project.ProjectId, testTag.Id); } } }
public async void GetImagesByIds() { using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "GetImagesByIds", RecorderMode); using (var project = CreateTrainedImageClassificationProject()) { ICustomVisionTrainingClient client = BaseTests.GetTrainingClient(); var tags = await client.GetTagsAsync(project.ProjectId); var imagesForTag = await client.GetTaggedImagesAsync(project.ProjectId, null, new List <Guid>(new Guid[] { tags[0].Id })); Assert.Equal(5, imagesForTag.Count); var images = await client.GetImagesByIdsAsync(project.ProjectId, imagesForTag.Select(img => img.Id).ToList()); Assert.Equal(5, images.Count); foreach (var image in images) { Assert.Equal(1, image.Tags.Count); var tag = image.Tags[0]; Assert.Equal(tags[0].Id, tag.TagId); Assert.Equal(tags[0].Name, tag.TagName); Assert.NotNull(image.ThumbnailUri); Assert.NotEmpty(image.OriginalImageUri); Assert.NotEmpty(image.ResizedImageUri); Assert.True(image.Width > 0); Assert.True(image.Height > 0); } } } }