Beispiel #1
0
        public void FindPeaksTest4()
        {
            Bitmap hand = Properties.Resources.rhand2;

            GaussianBlur median = new GaussianBlur(1.1);

            median.ApplyInPlace(hand);

            // Extract contour
            BorderFollowing bf      = new BorderFollowing(20);
            List <IntPoint> contour = bf.FindContour(hand);

            hand = hand.Clone(new Rectangle(0, 0, hand.Width, hand.Height), PixelFormat.Format24bppRgb);

            // Find peaks
            KCurvature kcurv = new KCurvature(30, new DoubleRange(0, 45));
            var        peaks = kcurv.FindPeaks(contour);

            List <IntPoint> supports = new List <IntPoint>();

            for (int i = 0; i < peaks.Count; i++)
            {
                int j = contour.IndexOf(peaks[i]);
                supports.Add(contour[(j + kcurv.K) % contour.Count]);
                supports.Add(contour[Accord.Math.Tools.Mod(j - kcurv.K, contour.Count)]);
            }

            // show(hand, contour, peaks, supports);

            Assert.AreEqual(1, peaks.Count);
            Assert.AreEqual(18, peaks[0].X);
            Assert.AreEqual(0, peaks[0].Y);
        }
Beispiel #2
0
        // New frame received by the player
        private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
        {
            lock (this)
            {
                if (tracker == null)
                {
                    return;
                }

                if (form != null && !form.IsDisposed)
                {
                    form.Image = image;
                }

                BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                                 ImageLockMode.ReadWrite, image.PixelFormat);

                UnmanagedImage img = new UnmanagedImage(data);

                tracker.ComputeOrientation = showAngle;

                tracker.ProcessFrame(img);

                Rectangle rect = tracker.TrackingObject.Rectangle;

                UnmanagedImage hand = tracker.TrackingObject.Image;


                if (hand != null && (showContour || showFingertips))
                {
                    UnmanagedImage grayhand = Grayscale.CommonAlgorithms.BT709.Apply(hand);

                    blur.ApplyInPlace(grayhand);

                    List <IntPoint> contour = bf.FindContour(grayhand);

                    for (int i = 0; i < contour.Count; i++)
                    {
                        contour[i] += new IntPoint(rect.X, rect.Y);
                    }

                    List <IntPoint> peaks = kcurv.FindPeaks(contour);

                    if (showContour)
                    {
                        cmarker.Points = contour;
                        cmarker.ApplyInPlace(img);
                    }

                    if (showFingertips)
                    {
                        pmarker.Points = peaks;
                        pmarker.ApplyInPlace(img);
                    }
                }

                if (showRectangle)
                {
                    RectanglesMarker marker = new RectanglesMarker(rect);
                    marker.ApplyInPlace(img);
                }

                if (showAngle)
                {
                    LineSegment axis = tracker.TrackingObject.GetAxis(AxisOrientation.Vertical);

                    if (axis != null)
                    {
                        // Draw X axis
                        Drawing.Line(img, axis.Start.Round(), axis.End.Round(), Color.Red);
                    }
                }

                image.UnlockBits(data);
            }
        }