protected virtual void PaintCovexHull(HandData cluster, DrawingContext drawingContext)
 {
     if (cluster.ConvexHull.Count > 3)
     {
         this.DrawLines(drawingContext, this.whitePen, cluster.ConvexHull.Points.Select(p => new System.Windows.Point(p.X, p.Y)).ToArray());
     }
 }
 protected virtual void DrawFingerPoints(HandData cluster, DrawingContext drawingContext)
 {
     foreach (var point in cluster.FingerPoints)
     {
         PaintFingerPoint(point, drawingContext);
     }
 }
 protected virtual void PaintContour(HandData hand, DrawingContext drawingContext)
 {
     if (hand.Contour.Points.Count > 1)
     {
         var points = hand.Contour.Points.Select(p => new System.Windows.Point(p.X, p.Y)).ToArray();
         DrawLines(drawingContext, this.yellowPen, points);
     }
 }
 private void DrawHand(HandData hand, DrawingContext drawingContext)
 {
     this.PaintCovexHull(hand, drawingContext);
     if (hand.Contour != null)
     {
         this.PaintContour(hand, drawingContext);
     }
     this.DrawFingerPoints(hand, drawingContext);
     this.DrawCenter(hand, drawingContext);
 }
 protected virtual void DrawCenter(HandData hand, DrawingContext drawingContext)
 {
     drawingContext.DrawEllipse(Brushes.Blue, null, new System.Windows.Point(hand.Location.X, hand.Location.Y), 5, 5);
     if (hand.HasPalmPoint)            
     {
         drawingContext.DrawEllipse(Brushes.SpringGreen, null, new System.Windows.Point(hand.PalmPoint.Value.X, hand.PalmPoint.Value.Y), 5, 5);
         var palmSize = hand.PalmDistance;
         drawingContext.DrawEllipse(null, this.greenPen, new System.Windows.Point(hand.PalmPoint.Value.X, hand.PalmPoint.Value.Y), palmSize, palmSize);
     }
 }
        internal void DrawHand(HandData handData, DrawingContext drawingContext)
        {
            if (this.AnimationInProgress)
            {
                var brush = new SolidColorBrush(Color.FromArgb(this.Opacity, 255, 255, 255));
                this.CreateText((int)this.Center.X + " | " + (int)this.Center.Y + "\n" + new Random().NextDouble(), brush);
                this.CreateNumberText(handData.FingerCount.ToString(), brush);

                drawingContext.DrawText(this.text, this.Center);
                drawingContext.DrawText(this.number, new Point(this.Center.X, this.Center.Y - this.Radius - 40));
                drawingContext.DrawEllipse(null, new Pen(brush, 4), this.Center, this.Radius - 20, this.Radius - 20);
                drawingContext.DrawEllipse(null, new Pen(brush, 4), this.Center, this.Radius + 10, this.Radius + 10);
                this.DrawFingerPoints(handData, drawingContext);
                this.UpdateProgress(brush);
                drawingContext.DrawGeometry(brush, null, path.Data);
            }
        }
Exemple #7
0
 private void PaintHand(Graphics g, HandData hand)
 {
     g.TranslateTransform(hand.Location.X * this.zoomFactor, hand.Location.Y * this.zoomFactor);
     g.ScaleTransform(this.zoomHandFactor, this.zoomHandFactor);
     g.TranslateTransform(-hand.Location.X * this.zoomFactor, -hand.Location.Y * this.zoomFactor);
     g.ScaleTransform(this.zoomFactor, this.zoomFactor);
     if (this.ShowConvexHull)
     {
         this.PaintCovexHull(hand, g);
     }
     if (this.ShowContour && hand.Contour != null)
     {
         this.PaintContour(hand, g);
     }
     DrawFingerPoints(hand, g);
     this.DrawCenter(hand, g);
     g.ResetTransform();
 }
        private HandData Create(int id, Shape shape, IList <FingerPoint> lastFrameFingerPoints)
        {
            var newFingerPoints = this.DetectFingerPoints(shape);
            var fingerPoints    = this.MapFingerPoints(lastFrameFingerPoints, newFingerPoints);
            var palm            = DetectPalm(shape, shape.Contour);

            if (settings.DetectFingerDirection)
            {
                this.fingerBaseDetector.Detect(shape.Contour, fingerPoints);
            }

            var handData = new HandData(id, shape, palm, fingerPoints.Where(f => f.FrameCount >= this.settings.FramesForNewFingerPoint).ToList())
            {
                NewlyDetectedFingerPoints = fingerPoints.Where(f => f.FrameCount < this.settings.FramesForNewFingerPoint).ToList()
            };

            return(handData);
        }
 private HandData Create(HandData lastFrameData, Shape shape)
 {
     return this.Create(lastFrameData.Id, shape, lastFrameData.FingerPoints.Union(lastFrameData.NewlyDetectedFingerPoints).ToList());
 }
 private static double CalculateFingerDistance(HandData hand)
 {
     double distance = 0;
     foreach (var finger in hand.FingerPoints)
     {
         distance = Math.Max(distance, CCT.NUI.Core.Point.Distance2D(finger.Location, hand.PalmPoint.Value));
     }
     return distance;
 }
        private void UpdateHandValues(HandData hand)
        {
            var distance = CalculateFingerDistance(hand);
            this.painter.UpdateCenter(hand, distance);
            this.painter.UpdateRadius(distance);

            if (this.InterfaceOpacity <= 1 && fingerPointCount == 5)
            {
                this.StartAnimation(1000);
            }
        }
 private void UpdateFingerCount(HandData hand)
 {
     this.countHistory.Add(hand.FingerCount);
     if (this.countHistory.AllEqual())
     {
         this.fingerPointCount = hand.FingerCount;
     }
 }
Exemple #13
0
 private HandData Create(HandData lastFrameData, Shape shape)
 {
     return(this.Create(lastFrameData.Id, shape, lastFrameData.FingerPoints));
 }
Exemple #14
0
        protected virtual void DrawCenter(HandData hand, Graphics g)  
        {
            g.FillEllipse(Brushes.Blue, hand.Location.X - 5, hand.Location.Y - 5, 10, 10);

            if (hand.HasPalmPoint)
            {
                g.FillEllipse(Brushes.SpringGreen, hand.PalmPoint.Value.X - 5, hand.PalmPoint.Value.Y - 5, 10, 10);
                var palmSize = hand.PalmDistance;
                g.DrawEllipse(Pens.SpringGreen, (int)(hand.PalmPoint.Value.X - palmSize), (int)(hand.PalmPoint.Value.Y - palmSize), (int)(palmSize * 2), (int)(palmSize * 2));
            }
        } 
Exemple #15
0
 public void SetHandData(HandData newData)
 {
     this.handData = newData;
 }
Exemple #16
0
 public HandTracker(HandData handData)
 {
     this.handData = handData;
 }
 private void CancelMode(HandData leftHand)
 {
     var fingerTip = leftHand.Fingers.First().Fingertip;
     ExecuteOnHitResult(fingerTip, (hitTestResult) =>
         {
             this.Remove(GetByHitTest(hitTestResult));
         });
 }
 internal void UpdateCenter(HandData hand, double distance)
 {
     var newCenter = new Point(hand.PalmX, hand.PalmY - distance / 3);
     if (CCT.NUI.Core.Point.Distance(newCenter.X, newCenter.Y, this.Center.X, this.Center.Y) > 75)
     {
         this.Center = newCenter;
     }
     else
     {
         this.Center = new Point(this.Center.X + (newCenter.X - this.Center.X) / 5, this.Center.Y + (newCenter.Y - this.Center.Y) / 5);
     }
 }
        private HandData Create(int id, Shape shape, IList<FingerPoint> lastFrameFingerPoints)
        {   
            var newFingerPoints = this.DetectFingerPoints(shape);
            var fingerPoints = this.MapFingerPoints(lastFrameFingerPoints, newFingerPoints);
            var palm = DetectPalm(shape, shape.Contour);

            if (settings.DetectFingerDirection)
            {
                this.fingerBaseDetector.Detect(shape.Contour, fingerPoints);
            }

            var handData = new HandData(id, shape, palm, fingerPoints.Where(f => f.FrameCount >= this.settings.FramesForNewFingerPoint).ToList()) 
            { 
                NewlyDetectedFingerPoints = fingerPoints.Where(f => f.FrameCount < this.settings.FramesForNewFingerPoint).ToList() 
            };

            return handData;
        }
Exemple #20
0
 public void Stop()
 {
     openHandArea = -1;
     openHandDistance = -1;
     ReadyForSign = false;
     //dataSourceFactory.Dispose();
     handDataSource.Stop();
     handDataSource.NewDataAvailable -= new NewDataHandler<HandCollection>(handDataSource_NewDataAvailable);
     handDataSource.Dispose();
     hand = null;
 }
Exemple #21
0
 private HandData Create(HandData lastFrameData, Shape shape)
 {
     return(this.Create(lastFrameData.Id, shape, lastFrameData.FingerPoints.Union(lastFrameData.NewlyDetectedFingerPoints).ToList()));
 }
Exemple #22
0
 private void handDataSource_NewDataAvailable(HandCollection data)
 {
     for (int index = 0; index < data.Count; index++)
     {
         if (!ReadyForSign)
         {
             hand = data.Hands[index];
             if (hand.FingerCount == 5)
             { //Takes the area of an open hand(when five fingers are detected)
                 openHandArea = handArea();
                 openHandDistance = ClosestPoint();
                 ReadyForSign = true;
             }
         }
         else
         {
             hand = data.Hands[index];
         }
     }
 }
Exemple #23
0
 protected virtual void PaintContour(HandData hand, Graphics g)
 {
     if (hand.Contour.Points.Count > 1)
     {
         var points = hand.Contour.Points.Select(p => new System.Drawing.Point((int)p.X, (int)p.Y)).ToArray();
         g.DrawLines(yellowPen, points);
     }
 }
 private void TimeShiftMode(HandData rightHand)
 {
     this.Dispatcher.Invoke(new Action(() =>
     {
         if (this.selectedVideo != null && this.selectedVideo.IsPaused)
         {
             this.selectedVideo.Play();
         }
         var rightFinger = rightHand.Fingers.OrderBy(f => f.Location.X).FirstOrDefault();
         if (rightFinger != null)
         {
             if (!moveMode)
             {
                 if (this.selectedVideo !=null && this.selectedVideo.Duration.HasTimeSpan)
                 {
                     moveMode = true;
                     moveStartTime = this.selectedVideo.Position;
                     moveStart = rightFinger.Location;
                     this.slider.Opacity = 0.8;
                     this.slider.Maximum = this.selectedVideo.Duration.TimeSpan.TotalMilliseconds;
                     this.slider.Value = this.selectedVideo.Position.TotalMilliseconds;
                     this.slider.SetValue(Canvas.LeftProperty, (double)rightFinger.Location.X);
                     this.slider.SetValue(Canvas.TopProperty, (double)rightFinger.Location.Y);
                 }
             }
             else
             {
                 this.CalcTimeSpan(rightFinger.Fingertip);
                 this.selectedVideo.Position = TimeSpan.FromMilliseconds(this.slider.Value);
                 this.slider.SetValue(Canvas.TopProperty, (double)rightFinger.Location.Y);
             }
         }
     }));
 }
Exemple #25
0
 protected virtual void PaintCovexHull(HandData hand, Graphics g)
 {
     if (hand.ConvexHull.Count > 3)
     {
         g.DrawLines(Pens.White, hand.ConvexHull.Points.Select(p => new System.Drawing.Point((int)p.X, (int)p.Y)).ToArray());
     }
 }
Exemple #26
0
 protected virtual void DrawFingerPoints(HandData hand, Graphics g)
 {
     foreach (var point in hand.FingerPoints)
     {
         PaintFingerPoint(g, point);
     }
 }
 private HandData Create(HandData lastFrameData, Shape shape)
 {
     return this.Create(lastFrameData.Id, shape, lastFrameData.FingerPoints);
 }
Exemple #28
0
 protected virtual void PaintContour(HandData hand, Graphics g)
 {
     if (hand.Contour.Points.Count > 1)
     {
         var points = hand.Contour.Points.Select(p => new System.Drawing.Point((int)p.X, (int)p.Y)).ToArray();
         int alpha = (int)hand.PalmDistance * 64 - 2040;
         if (alpha > 255)
             alpha = 255;
         if (alpha < 0)
             alpha = 0;
         Pen hand_pen = new Pen(Color.FromArgb(alpha,127,255,0),10);
         //g.DrawString(hand.PalmDistance.ToString(), this.font, Brushes.White, hand.PalmX + 3, hand.PalmY + 3);
         g.DrawLines(hand_pen, points);
     }
 }