Ejemplo n.º 1
0
        private void VideoDevice_NewFrame(object sender, NewFrameEventArgs e)
        {
            var source    = new Bitmap(e.Frame);
            var unmanaged = UnmanagedImage.FromManagedImage(source);

            Grayscale grayscaleFilter = new Grayscale(1, 0, 0);
            var       grayscaleUnm    = grayscaleFilter.Apply(unmanaged);
            var       grayscale       = grayscaleUnm.ToManagedImage();

            var points            = PointDetector.FindHighlitedPoints(grayscaleUnm.ImageData, e.Frame.Width, e.Frame.Height);
            var points3Enumerable = from point in points
                                    select PointScanner.ConvertTo3D(point, e.Frame.Width, e.Frame.Height) into point3
                                        where Properties.Cylinder.Contains(point3)
                                    select point3;

            Vector3[] vertices = points3Enumerable.ToArray();
            using (var gr = System.Drawing.Graphics.FromImage(source))
            {
                foreach (var p in points)
                {
                    gr.FillEllipse(Brushes.Green, p.X - 4, p.Y - 4, 8, 8);
                }
                foreach (var v in vertices)
                {
                    var   p2    = PointScanner.ConvertTo2D(v, e.Frame.Width, e.Frame.Height);
                    Brush color = v.Z > 0 ? Brushes.Blue : Brushes.Red;
                    gr.FillEllipse(color, p2.X - 2, p2.Y - 2, 4, 4);
                }
            }

            using (var graphics = sourceImage.CreateGraphics())
                graphics.DrawImage(source, 0, 0, sourceImage.Width, sourceImage.Height);
            using (var graphics = grayscaleImage.CreateGraphics())
                graphics.DrawImage(grayscale, 0, 0, sourceImage.Width, sourceImage.Height);
        }
Ejemplo n.º 2
0
        private void HandleNewFrame(Bitmap frame)
        {
            var       unmanaged       = UnmanagedImage.FromManagedImage(frame);
            Grayscale grayscaleFilter = new Grayscale(1, 0, 0);
            var       grayscaleUnm    = grayscaleFilter.Apply(unmanaged);

            float      rotationAngle = (float)(-Slices.Count * PlatformStep);
            Quaternion rotation      = Quaternion.CreateFromYawPitchRoll(rotationAngle, 0, 0);

            Vector2[] points        = PointDetector.FindHighlitedPoints(grayscaleUnm.ImageData, frame.Width, frame.Height);
            var       sliceVertices = from point in points
                                      select PointScanner.ConvertTo3D(point, frame.Width, frame.Height) into vertex
                                          where Cylinder.Contains(vertex)
                                      select Vector3.Transform(vertex, rotation);

            AddSlice(sliceVertices.ToArray());
        }