Exemple #1
0
        private void onDownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (e != null && e.Error != null)
            {
                SetMessage(e.Error.Message);
                return;
            }

            Stopwatch watch = Stopwatch.StartNew();
            var result = _mobilenet.Recognize(_imageFiles[0], 0.5f);
            watch.Stop();

            Annotation[] annotations = new Annotation[result.Length];
            for (int i = 0; i < result.Length; i++)
            {
                Annotation annotation = new Annotation();
                annotation.Rectangle = result[i].Rectangle;
                annotation.Label = String.Format("{0}:({1:0.00}%)", result[i].Label, result[i].Score * 100);
                annotations[i] = annotation;
            }


            JpegData jpeg = NativeImageIO.ImageFileToJpeg(_imageFiles[0], annotations);
            //NativeImageIO.JpegData jpeg = NativeImageIO.ImageFileToJpeg(_imageFiles[0]);
            //String names = String.Join(";", Array.ConvertAll(result, r => r.Label));
            SetImage(jpeg.Raw, jpeg.Width, jpeg.Height);


            String resStr = String.Format("Detected {1} objects in {0} milliseconds.", watch.ElapsedMilliseconds, result.Length);
            SetMessage(resStr);

        }
Exemple #2
0
        private async void OnButtonClicked(Object sender, EventArgs args)
        {
            SetMessage("Please wait while the Coco SSD Mobilenet Model is being downloaded...");
#if !DEBUG
            try
#endif
            {
                await _mobilenet.Init();
            }
#if !DEBUG
            catch (Exception e)
            {
                String msg = e.Message.Replace(System.Environment.NewLine, " ");
                SetMessage(msg);
            }
#endif

            if (this.TopButton.Text.Equals("Stop"))
            {
                // Stop camera
#if __IOS__ || __MACOS__
                this.StopCaptureSession();
#endif
                this.TopButton.Text = "Perform Object Detection";
            }
            else
            {
                String[] imageFiles = await LoadImages(new string[] { "dog416.png" });

                String imageFileName = imageFiles[0];

                if (imageFileName.Equals("Camera Stream"))
                {
#if __MACOS__ || __IOS__
                    SetMessage(String.Format("Model trained to recognize the following objects: {0}", String.Join("; ", _mobilenet.Labels)));
                    this.TopButton.Text = "Stop";
                    CheckVideoPermissionAndStart();
#else
#endif
                }
                else
                {
                    Stopwatch watch  = Stopwatch.StartNew();
                    var       result = _mobilenet.Recognize(imageFileName, 0.5f);
                    watch.Stop();

                    Annotation[] annotations = GetAnnotations(result);

                    JpegData jpeg = NativeImageIO.ImageFileToJpeg(imageFileName, annotations);
                    //NativeImageIO.JpegData jpeg = NativeImageIO.ImageFileToJpeg(_imageFiles[0]);
                    //String names = String.Join(";", Array.ConvertAll(result, r => r.Label));
                    SetImage(jpeg.Raw, jpeg.Width, jpeg.Height);

                    String resStr = String.Format("Detected {1} objects in {0} milliseconds.", watch.ElapsedMilliseconds, result.Length);
                    SetMessage(resStr);
                }
            }
        }
        private void onDownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (e != null && e.Error != null)
            {
                SetMessage(e.Error.Message);
                return;
            }

            String _imageFileName = _imageFiles[0];

            if (_imageFileName.Equals("Camera Stream"))
            {
#if __MACOS__ || __IOS__
                SetMessage(String.Format("Model trained to recognize the following objects: {0}", String.Join("; ", _mobilenet.Labels)));
                this.TopButton.Text = "Stop";
                CheckVideoPermissionAndStart();
#else
#endif
            }
            else
            {
                Stopwatch watch  = Stopwatch.StartNew();
                var       result = _mobilenet.Recognize(_imageFiles[0], 0.5f);
                watch.Stop();

                Annotation[] annotations = GetAnnotations(result);

                /*
                 * Annotation[] annotations = new Annotation[result.Length];
                 * for (int i = 0; i < result.Length; i++)
                 * {
                 *  Annotation annotation = new Annotation();
                 *  annotation.Rectangle = result[i].Rectangle;
                 *  annotation.Label = String.Format("{0}:({1:0.00}%)", result[i].Label, result[i].Score * 100);
                 *  annotations[i] = annotation;
                 * }*/


                JpegData jpeg = NativeImageIO.ImageFileToJpeg(_imageFiles[0], annotations);
                //NativeImageIO.JpegData jpeg = NativeImageIO.ImageFileToJpeg(_imageFiles[0]);
                //String names = String.Join(";", Array.ConvertAll(result, r => r.Label));
                SetImage(jpeg.Raw, jpeg.Width, jpeg.Height);


                String resStr = String.Format("Detected {1} objects in {0} milliseconds.", watch.ElapsedMilliseconds, result.Length);
                SetMessage(resStr);
            }
        }