Ejemplo n.º 1
0
        public BottleDetectionUseCases(CompositeDisposable disposables)
            : base(disposables)
        {
            photoCamera = new PhotoCamera();
            client      = new CustomVisionClient();

            CanTakePhoto = Observable.CombineLatest(photoCamera.CanTakePhoto, client.CanPost)
                           .Select(x => !x.Contains(false))
                           .ToReactiveProperty();

            PhotoCamera.ShootingPlan plan = null;
            byte[] imageData = null;
            photoCamera.OnPhotoCaptured
            .Do(b =>
            {
                plan      = photoCamera.Plan;
                imageData = b;
            })
            .SelectMany(x => client.Post(x))
            .Do(res =>
            {
                var positions = client.Convert(plan, imageData, res);
                var status    = new DetectedStatus
                {
                    Plan      = plan,
                    Positions = positions,
                };
                onBottleDetected.OnNext(status);
            })
            .Subscribe()
            .AddTo(disposables);
        }
        public static async Task <ImagePredictionResult> PredictImageAsync(this CustomVisionClient client, Guid projectId, Stream image, int width, int height, Guid?iterationId = null)
        {
            using (var output = await ResizeImageAsync(image, width, height))
            {
                var result = await client.PredictImageAsync(projectId, output, iterationId);

                return(result);
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            var url             = "https://brazilsouth.api.cognitive.microsoft.com";
            var token           = Environment.GetEnvironmentVariable("AZURE-COGNITIVESERVICES-TOKEN", EnvironmentVariableTarget.User);
            var predictionToken = Environment.GetEnvironmentVariable("AZURE-CUSTOMVISION-PREDICTION-TOKEN", EnvironmentVariableTarget.User);

            token           = "bf5c88d9a9a84747a2d4bd0170bb4f7c";
            predictionToken = "7222807f92cc4776aa6da5c888ec06f5";

            _visionClient            = new VisionClient(token, url);
            _customVisionClient      = new CustomVisionClient(predictionToken);
            _localCustomVisionClient = new LocalCustomVisionClient();
            _currentProjectId        = _projectIdBolacha;
        }
Ejemplo n.º 4
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;

            if (activity.Attachments.Count > 0)
            {
                if (ModelId == "" || PredictionKey == "")
                {
                    await context.PostAsync("Please specify ModelID and Key before use");
                }
                else
                {
                    var cli  = new CustomVisionClient(ModelId, PredictionKey);
                    var hcli = new HttpClient();
                    var str  = await hcli.GetStreamAsync(activity.Attachments[0].ContentUrl);

                    var res = await cli.AnalyseAsync(str);

                    if (res.Count <= 0 || res.Top.Probability < 0)
                    {
                        await context.PostAsync("No object found. Make sure you set the default iteration to use through custom vision portal.");
                    }
                    else
                    {
                        var top = res.Top;
                        await context.PostAsync($"I found brand {top.Name} with confidence={top.Probability}");
                    }
                }
            }
            else
            {
                var t = activity.Text.Split(' ');
                if (t.Length != 2)
                {
                    await context.PostAsync("Please specify ModelId and Key separated by space");
                }
                else
                {
                    ModelId       = t[0];
                    PredictionKey = t[1];
                    await context.PostAsync($"Set model id={ModelId}, key={PredictionKey}");
                }
            }
            context.Wait(MessageReceivedAsync);
        }
Ejemplo n.º 5
0
 public CustomVisionManager(CustomVisionClient client)
 {
     _apiClient = client;
 }