private void ProcessImage(Image <Bgr, byte> image) { 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.DetectStopSign(image, stopSignList, stopSignBoxList); watch.Stop(); //stop the timer processTimeLabel.Text = String.Format("Stop Sign Detection time: {0} milli-seconds", watch.Elapsed.TotalMilliseconds); panel1.Controls.Clear(); Point startPoint = new Point(10, 10); for (int i = 0; i < stopSignList.Count; i++) { Rectangle rect = stopSignBoxList[i]; AddLabelAndImage( ref startPoint, String.Format("Stop Sign [{0},{1}]:", rect.Location.Y + rect.Width / 2, rect.Location.Y + rect.Height / 2), stopSignList[i]); image.Draw(rect, new Bgr(Color.Aquamarine), 2); } imageBox1.Image = image; }
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"); }; }
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); } } }; }
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()); } }; }
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); } } }; }
private void ProcessImage() { if (tick % 5 == 0) { // Stopwatch watch = Stopwatch.StartNew(); // time the detection process Image <Bgr, byte> image; image = img0; List <Image <Gray, Byte> > stopSignList = new List <Image <Gray, byte> >(); List <Rectangle> stopSignBoxList = new List <Rectangle>(); List <String> id = new List <String>(); _stopSignDetector.DetectStopSign(image, stopSignList, stopSignBoxList, id); // watch.Stop(); //stop the timer //processTimeLabel.Text = String.Format("Stop Sign Detection time: {0} milli-seconds", watch.Elapsed.TotalMilliseconds); panel1.Controls.Clear(); Point startPoint = new Point(10, 10); for (int i = 0; i < stopSignList.Count; i++) { Rectangle rect = stopSignBoxList[i]; AddLabelAndImage( ref startPoint, String.Format("{0} Sign [{1},{2}]:", id[i], rect.Location.Y + rect.Width / 2, rect.Location.Y + rect.Height / 2), stopSignList[i]); last_rectangle[i] = rect; checks_after_detection[i] = 7; } } for (int i = 0; i < last_rectangle.Length; i++) { if (checks_after_detection[i]-- > 0) { img0 = add_x(img0, last_rectangle[i]); } } imageBox1.Image = img0; // imageBox1.Refresh(); }