Beispiel #1
0
        void UseLandmarkRecognitionModel()
        {
            var options = new VisionCloudDetectorOptions {
                ModelType  = VisionCloudModelType.Stable,
                MaxResults = 5
            };
            var landmarkDetector = vision.GetCloudLandmarkDetector(options);
            var image            = new VisionImage(ImgSample.Image);

            landmarkDetector.Detect(image, HandleVisionCloudLandmarkDetectionCallback);

            void HandleVisionCloudLandmarkDetectionCallback(VisionCloudLandmark [] landmarks, NSError error)
            {
                if (error != null)
                {
                    TxtData.Text = error.Description;
                    return;
                }

                if (landmarks == null || landmarks.Length == 0)
                {
                    TxtData.Text = "No landmarks were found.";
                    return;
                }

                var stringBuilder = new StringBuilder();

                foreach (var landmark in landmarks)
                {
                    stringBuilder.AppendLine($"Landmark: {landmark.Landmark}");
                    stringBuilder.AppendLine($"Entity Id: {landmark.EntityId}");
                    stringBuilder.AppendLine($"Confidence: {landmark.Confidence}");
                    stringBuilder.AppendLine();
                }

                TxtData.Text = stringBuilder.ToString();
            }
        }
        void UseCloudImageLabelingModel()
        {
            var options = new VisionCloudDetectorOptions {
                ModelType  = VisionCloudModelType.Latest,
                MaxResults = 5
            };
            var labelDetector = vision.GetCloudLabelDetector(options);
            var image         = new VisionImage(ImgSample.Image);

            labelDetector.Detect(image, HandleVisionCloudLabelDetectionCompletion);

            void HandleVisionCloudLabelDetectionCompletion(VisionCloudLabel [] labels, NSError error)
            {
                if (error != null)
                {
                    TxtData.Text = error.Description;
                    return;
                }

                if (labels == null || labels.Length == 0)
                {
                    TxtData.Text = "No labels were found.";
                    return;
                }

                var stringBuilder = new StringBuilder();

                foreach (var label in labels)
                {
                    stringBuilder.AppendLine($"Label: {label.Label}");
                    stringBuilder.AppendLine($"Entity Id: {label.EntityId}");
                    stringBuilder.AppendLine($"Confidence: {label.Confidence}");
                    stringBuilder.AppendLine();
                }

                TxtData.Text = stringBuilder.ToString();
            }
        }