private static void ProcessFrame() { var stopWatch = new Stopwatch(); stopWatch.Start(); Frame = Capture.QueryFrame(); Processor.ProcessImage(Frame); foreach (var found in Processor.FoundTemplates) { var foundRect = found.Sample.Contour.GetBoundsRect(); Console.WriteLine("Distanse: {0}", DistanceHelper.DistanceByRelation(foundRect.Height / CamHeight)); } Console.WriteLine(stopWatch.Elapsed); }
private void ibMain_Paint(object sender, PaintEventArgs e) { if (Frame == null) { return; } var font = new Font(Font.FontFamily, 24); //16 e.Graphics.DrawString(lbFPS.Text, new Font(Font.FontFamily, 16), Brushes.Yellow, new PointF(1, 1)); Brush bgBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 0)); Brush foreBrush = new SolidBrush(Color.FromArgb(255, 255, 255, 255)); var borderPen = new Pen(Color.FromArgb(150, 0, 255, 0)); // if (cbShowContours.Checked) { foreach (var contour in Processor.Contours) { if (contour.Total > 1) { e.Graphics.DrawLines(Pens.Red, contour.ToArray()); } } } // lock (Processor.FoundTemplates) foreach (var found in Processor.FoundTemplates) { if (found.Template.Name.EndsWith(".png") || found.Template.Name.EndsWith(".jpg")) { DrawAugmentedReality(found, e.Graphics); continue; } var foundRect = found.Sample.Contour.SourceBoundingRect; var p1 = new Point((foundRect.Left + foundRect.Right) / 2, foundRect.Top); var text = found.Template.Name; if (ShowAngle) { text += string.Format("\r\nangle={0:000}°\r\nrelation={1:0.0000}\r\ndistance={2:00.00}", 180 * found.Angle / Math.PI, found.Sample.Contour.GetBoundsRect().Height / CamHeight, DistanceHelper.DistanceByRelation(found.Sample.Contour.GetBoundsRect().Height / CamHeight)); } e.Graphics.DrawRectangle(borderPen, foundRect); e.Graphics.DrawString(text, font, bgBrush, new PointF(p1.X + 1 - font.Height / 3, p1.Y + 1 - font.Height)); e.Graphics.DrawString(text, font, foreBrush, new PointF(p1.X - font.Height / 3, p1.Y - font.Height)); } }