public void AnnotateImagesTest_InvalidAPIKey() { ImageFeatures feature = new ImageFeatures(ImageType.LABEL_DETECTION, MAX_RESULTS, VALID_MODEL); imageFeaturesList.Add(feature); AnnotateImageRequest imageRequest = GenerateImageRequest(VALID_IMAGE_URL, imageFeaturesList); AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>() { imageRequest }); imageIntelligence.UpdateKey(INVALID_SETUP); Task <Tuple <AnnotateImageResponseList, ResponseStatus> > responses = imageIntelligence.AnnotateImages(imageRequestList); responses.Wait(); imageIntelligence.UpdateKey(VALID_SETUP); Assert.IsNull(responses.Result.Item1); Assert.AreSame(responses.Result.Item2, ImageAnnotationStatus.INVALID_API_KEY); imageRequestList.Requests.Clear(); }
public void AnnotateImagesTest_ValidRequestWithTextDetection() { ImageFeatures feature = new ImageFeatures(ImageType.TEXT_DETECTION, MAX_RESULTS, VALID_MODEL); imageFeaturesList.Add(feature); AnnotateImageRequest imageRequest = GenerateImageRequest(TEXT_DETECTION_URL_1, imageFeaturesList); AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>() { imageRequest }); Task <Tuple <AnnotateImageResponseList, ResponseStatus> > response = imageIntelligence.AnnotateImages(imageRequestList); response.Wait(); AnnotateImageResponseList responseList = response.Result.Item1; Assert.IsNotNull(responseList); Assert.AreSame(response.Result.Item2, ImageAnnotationStatus.OK); Assert.GreaterOrEqual(responseList.Responses.Count, 1); for (int i = 0; i < responseList.Responses.Count; i++) { Assert.IsNotNull(responseList.Responses[i].TextAnnotations); Assert.GreaterOrEqual(responseList.Responses[i].TextAnnotations.Count, 1); Assert.IsNotNull(responseList.Responses[i].FullTextAnnotations); Assert.IsNotNull(responseList.Responses[i].FullTextAnnotations.Text); Assert.GreaterOrEqual(responseList.Responses[i].FullTextAnnotations.Pages.Count, 1); } imageRequestList.Requests.Clear(); }
public void AnnotateImagesTest_ValidRequestWithImageProperties() { ImageFeatures feature = new ImageFeatures(ImageType.IMAGE_PROPERTIES, MAX_RESULTS, VALID_MODEL); imageFeaturesList.Add(feature); AnnotateImageRequest imageRequest = GenerateImageRequest(VALID_IMAGE_URL, imageFeaturesList); AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>() { imageRequest }); Task <Tuple <AnnotateImageResponseList, ResponseStatus> > response = imageIntelligence.AnnotateImages(imageRequestList); response.Wait(); AnnotateImageResponseList responseList = response.Result.Item1; Assert.IsNotNull(responseList); Assert.AreSame(response.Result.Item2, ImageAnnotationStatus.OK); Assert.GreaterOrEqual(responseList.Responses.Count, 1); for (int i = 0; i < responseList.Responses.Count; i++) { Assert.IsNotNull(responseList.Responses[i].ImagePropertiesAnnotation); Assert.IsNotNull(responseList.Responses[i].ImagePropertiesAnnotation.DominantColors); Assert.GreaterOrEqual(responseList.Responses[i].ImagePropertiesAnnotation.DominantColors.Colors.Count, 1); } imageRequestList.Requests.Clear(); }
public void AnnotateImagesTest_OneValidAndOneInvalidImageURL() { ImageFeatures feature = new ImageFeatures(ImageType.LANDMARK_DETECTION, MAX_RESULTS, VALID_MODEL); imageFeaturesList.Add(feature); AnnotateImageRequest imageRequest1 = GenerateImageRequest(IMAGE_URL, imageFeaturesList); AnnotateImageRequest imageRequest2 = GenerateImageRequest(LANDMARK_ANNOTATION_URL_1, imageFeaturesList); AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>() { imageRequest1, imageRequest2 }); Task <Tuple <AnnotateImageResponseList, ResponseStatus> > responses = imageIntelligence.AnnotateImages(imageRequestList); responses.Wait(); Assert.IsNotNull(responses.Result.Item1); AnnotateImageResponseList responseList = responses.Result.Item1; Assert.AreEqual(responseList.Responses.Count, 2); Assert.IsNotNull(responseList.Responses[0].Error); Assert.IsNotNull(responseList.Responses[0].Error.Message); Assert.IsNotEmpty(responseList.Responses[0].Error.Message); Assert.IsNotNull(responseList.Responses[1].LandmarkAnnotations); Assert.GreaterOrEqual(responseList.Responses[1].LandmarkAnnotations.Count, 1); imageRequestList.Requests.Clear(); }
private static float[] ToArray(this ImageFeatures features) { return(new[] { features.ChromatedPixelsRatio, features.EdgePixelsRatio, features.SaturationMean, features.SaturationStddev, features.ValueMean, features.ValueStddev, }); }
public static ImageFeatures CalculateFeatures(this Mat mat, Contour contour, bool isOccupied) { var hsvColorStats = ImageProcessor.GetHSVColorStats(contour, mat); var features = new ImageFeatures { IsOccupied = isOccupied, // counted edges and Chromated pixels EdgePixels = ImageProcessor.CountEdgePixels(contour, mat), ChromatedPixels = ImageProcessor.CountChromatedPixels(contour, mat), MaskPixels = ImageProcessor.CountMaskArea(contour, mat), //hsv stats SaturationMean = hsvColorStats.Item1.Item1, SaturationStddev = hsvColorStats.Item1.Item2, ValueMean = hsvColorStats.Item2.Item1, ValueStddev = hsvColorStats.Item2.Item2 }; return(features); }
public void AnnotateImagesTest_SingleInvalidImageURL() { ImageFeatures feature = new ImageFeatures(ImageType.LABEL_DETECTION, MAX_RESULTS, VALID_MODEL); imageFeaturesList.Add(feature); AnnotateImageRequest imageRequest = GenerateImageRequest(IMAGE_URL, imageFeaturesList); AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>() { imageRequest }); Task <Tuple <AnnotateImageResponseList, ResponseStatus> > responses = imageIntelligence.AnnotateImages(imageRequestList); responses.Wait(); Assert.IsNotNull(responses.Result.Item1); Assert.IsNotNull(responses.Result.Item1.Responses[0].Error); Assert.IsNotNull(responses.Result.Item1.Responses[0].Error.Message); Assert.IsNotEmpty(responses.Result.Item1.Responses[0].Error.Message); imageRequestList.Requests.Clear(); }
public void AnnotateImagesTest_ValidRequestWithMultipleAnnotations() { ImageFeatures feature = new ImageFeatures(ImageType.LANDMARK_DETECTION, MAX_RESULTS, VALID_MODEL); imageFeaturesList.Add(feature); AnnotateImageRequest imageRequest1 = GenerateImageRequest(LANDMARK_ANNOTATION_URL_1, imageFeaturesList); AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>() { imageRequest1 }); feature = new ImageFeatures(ImageType.FACE_DETECTION, MAX_RESULTS, VALID_MODEL); imageFeaturesList.Add(feature); AnnotateImageRequest imageRequest2 = GenerateImageRequest(FACE_ANNOTATION_URL, imageFeaturesList); imageRequestList.Requests.Add(imageRequest2); Task <Tuple <AnnotateImageResponseList, ResponseStatus> > response = imageIntelligence.AnnotateImages(imageRequestList); response.Wait(); AnnotateImageResponseList responseList = response.Result.Item1; Assert.IsNotNull(responseList); Assert.AreSame(response.Result.Item2, ImageAnnotationStatus.OK); Assert.AreEqual(responseList.Responses.Count, 2); Assert.IsNotNull(responseList.Responses[0].LandmarkAnnotations); Assert.GreaterOrEqual(responseList.Responses[0].LandmarkAnnotations.Count, 1); Assert.IsNotNull(responseList.Responses[1].FaceAnnotations); Assert.GreaterOrEqual(responseList.Responses[1].FaceAnnotations.Count, 1); imageRequestList.Requests.Clear(); }
public static Mat ToPredictionMat(this ImageFeatures features) { var array = features.ToArray(); return(new Mat(1, array.Length, MatType.CV_32FC1, array)); }
public bool Predict(ImageFeatures imageFeatures) { return(Convert.ToBoolean(_svm.Predict(imageFeatures.ToPredictionMat()))); }