private void UpdateDebugText(LaserTrackerResult result) { var sb = new StringBuilder(); var rects = result.Rectangles; processingTimeLabel.Text = String.Format("Process: {0:F1}ms", result.ProcessingTime.TotalMilliseconds); sb.AppendFormat("Contours: {0}\n", rects.Count); foreach (var rectangle in rects) { sb.AppendFormat("{0}\n", rectangle); } label1.Text = sb.ToString(); }
private void UpdateDebugImage(LaserTrackerResult result) { result.ApplyDebugToImage(); if (_debugImage == null || _debugImage.Height != debugPictureBox.Height || _debugImage.Width != debugPictureBox.Width) { Util.Dispose(ref _debugImage); _debugImage = new Bitmap(debugPictureBox.Width, debugPictureBox.Height, PixelFormat.Format32bppArgb); } using (var g = Graphics.FromImage(_debugImage)) { var camBitmap = result.CamBitmap; var threshBitmap = result.ThreshBitmap; if (!(camBitmap != null && threshBitmap != null)) return; g.Clear(Color.Transparent); g.ResetTransform(); g.DrawImage(camBitmap, 0, 0); g.DrawRectangle(Pens.Orange, 0, 0, camBitmap.Width, camBitmap.Height); if (!_tracker.Warp) { var points = (new[] {_tracker.Quad1, _tracker.Quad2, _tracker.Quad3, _tracker.Quad4, _tracker.Quad1}).Select(p => p.Rescale(camBitmap.Width, camBitmap.Height)).ToArray(); g.DrawLines(Pens.Silver, points); } g.TranslateTransform(0, camBitmap.Height + 2); g.DrawImage(threshBitmap, 0, 0); g.DrawRectangle(Pens.LimeGreen, 0, 0, threshBitmap.Width, threshBitmap.Height); var stroke = _strokeRecognizer.CurrentStroke; if (stroke != null) { var points = stroke.Points.Select(point => point.Rescale(threshBitmap.Width, threshBitmap.Height)).ToArray(); if (points.Length >= 2) { using (var p = new Pen(Color.YellowGreen, 2) {DashStyle = DashStyle.Dot}) { g.DrawLines(p, points); } } } } debugPictureBox.Image = _debugImage; }