public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            ButtonText     = "Detect Stop Sign";
            OnButtonClick +=
                delegate
            {
                using (Image <Bgr, byte> stopSignModel = new Image <Bgr, byte>("stop-sign-model.png"))
                    using (Image <Bgr, Byte> image = new Image <Bgr, Byte>("stop-sign.jpg"))
                    {
                        Stopwatch watch = Stopwatch.StartNew(); // time the detection process

                        List <Image <Gray, Byte> > stopSignList    = new List <Image <Gray, byte> >();
                        List <Rectangle>           stopSignBoxList = new List <Rectangle>();
                        StopSignDetector           detector        = new StopSignDetector(stopSignModel);
                        detector.DetectStopSign(image, stopSignList, stopSignBoxList);

                        watch.Stop(); //stop the timer
                        foreach (Rectangle rect in stopSignBoxList)
                        {
                            image.Draw(rect, new Bgr(Color.Red), 2);
                        }
                        Size frameSize = FrameSize;
                        using (Image <Bgr, byte> resized = image.Resize(frameSize.Width, frameSize.Height, Emgu.CV.CvEnum.Inter.Cubic, true))
                        {
                            MessageText = String.Format("Detection time: {0} milli-seconds", watch.Elapsed.TotalMilliseconds);
                            SetImage(resized);
                        }
                    }
            };
        }
Beispiel #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            OnButtonClick += delegate
            {
                using (Image <Bgr, byte> stopSignModel = new Image <Bgr, byte>(Assets, "stop-sign-model.png"))
                    using (Image <Bgr, Byte> image = PickImage("stop-sign.jpg"))
                    {
                        if (image == null)
                        {
                            return;
                        }

                        Stopwatch watch = Stopwatch.StartNew(); // time the detection process

                        List <Mat>       stopSignList    = new List <Mat>();
                        List <Rectangle> stopSignBoxList = new List <Rectangle>();
                        StopSignDetector detector        = new StopSignDetector(stopSignModel);
                        detector.DetectStopSign(image.Mat, stopSignList, stopSignBoxList);

                        watch.Stop(); //stop the timer
                        SetMessage(String.Format("Detection time: {0} milli-seconds", watch.Elapsed.TotalMilliseconds));

                        foreach (Rectangle rect in stopSignBoxList)
                        {
                            image.Draw(rect, new Bgr(System.Drawing.Color.Red), 2);
                        }

                        SetImageBitmap(image.ToBitmap());
                    }
            };
        }
Beispiel #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            ButtonText     = "Detect Stop Sign";
            OnButtonClick +=
                delegate
            {
                using (Mat stopSignModel = new Mat("stop-sign-model.png"))
                    using (Mat image = new Mat("stop-sign.jpg"))
                    {
                        Stopwatch watch = Stopwatch.StartNew(); // time the detection process

                        List <Mat>       stopSignList    = new List <Mat>();
                        List <Rectangle> stopSignBoxList = new List <Rectangle>();
                        StopSignDetector detector        = new StopSignDetector(stopSignModel);
                        detector.DetectStopSign(image, stopSignList, stopSignBoxList);

                        watch.Stop(); //stop the timer
                        foreach (Rectangle rect in stopSignBoxList)
                        {
                            CvInvoke.Rectangle(image, rect, new MCvScalar(0, 0, 255), 2);
                        }
                        Size frameSize = FrameSize;
                        using (Mat resized = new Mat())
                        {
                            CvInvoke.ResizeForFrame(image, resized, frameSize);
                            MessageText = String.Format("Detection time: {0} milli-seconds", watch.Elapsed.TotalMilliseconds);
                            SetImage(resized);
                        }
                    }
            };
        }
Beispiel #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            OnImagePicked += (sender, image) =>
            {
                using (Mat stopSignModel = new Mat(Assets, "stop-sign-model.png"))
                {
                    if (image == null)
                    {
                        return;
                    }

                    Stopwatch watch = Stopwatch.StartNew(); // time the detection process

                    List <Mat>       stopSignList    = new List <Mat>();
                    List <Rectangle> stopSignBoxList = new List <Rectangle>();
                    StopSignDetector detector        = new StopSignDetector(stopSignModel);
                    detector.DetectStopSign(image, stopSignList, stopSignBoxList);

                    watch.Stop(); //stop the timer
                    SetMessage(String.Format("Detection time: {0} milli-seconds", watch.Elapsed.TotalMilliseconds));

                    foreach (Rectangle rect in stopSignBoxList)
                    {
                        CvInvoke.Rectangle(image, rect, new Bgr(System.Drawing.Color.Red).MCvScalar, 2);
                    }

                    SetImageBitmap(image.ToBitmap());
                    image.Dispose();
                }
            };

            OnButtonClick += (sender, args) =>
            {
                PickImage("stop-sign.jpg");
            };
        }