Beispiel #1
0
        public HandTracker(KinectSensor mySensor)
        {
            this.kinectSensor = mySensor;
            this.kinectSensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
            this.kinectSensor.DepthFrameReady += this.sensorDepthFrameReady;
            this.hand = new Point3d();
            this.imagePixelList = new List<DepthImagePixel>();
            this.closestPoint = new DepthImagePixel();

            // Start the sensor!
            try
            {
                this.kinectSensor.Start();
            }
            catch (IOException)
            {
                this.kinectSensor = null;
            }
        }
        public HandTracking()
        {
            if (leftWristDepths == null)
            {
                leftWristDepths = new Point3d[MINDATAPOINTSREQ];
            }

            if (rightWristDepths == null)
            {
                rightWristDepths = new Point3d[MINDATAPOINTSREQ];
            }

            if (leftWrist == null)
            {
                leftWrist = new Point3d();
            }

            if (rightWrist == null)
            {
                rightWrist = new Point3d();
            }
        }
Beispiel #3
0
        public void updatePath(Point3d point)
        {
            GridSquare currentSquare = grid.getGridSquareContainingPoint(point);
            if (currentSquare != null)
            {
                currentPath.AddLast(currentSquare);
            }

            // Advance to the next target
            if (currentSquare == currentTarget)
            {
                currentTarget = manipulatableTargetSequence.Dequeue();
            }

            double currentDistance = euclideanDistance(new Point2d(point.X, point.Y), currentTarget.getCenter());
            if (currentDistance > previousDistance)
            {
                failedAuthentication = true;
            }
            else
            {
                previousDistance = currentDistance;
            }
        }
        private void drawHands(DrawingContext drawingContext, ThreeDAuth.DepthPoint hand, bool drawHand, DepthImageFrame depthFrame)
        {
            //showDepthView(depthFrame, drawingContext);
            //return;

            //Start Siavash

            double resetButtonTimePercentage = 0.0;
            double doneButtonTimePercentage = 0.0;
            if (userImage != null)
            {
                drawingContext.DrawImage(userImage, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                // Draw the reset button regardless
                //Pen buttonPen = new Pen(Brushes.Black, 0.1);
                //Brush resetButtonBrush = new SolidColorBrush(Color.FromRgb());
                //drawingContext
                if (resetButtonTimer.IsRunning)
                {
                    resetButtonTimePercentage = (double) resetButtonTimer.ElapsedMilliseconds / (double) BUTTON_HOLD_CUTOFF;
                }
                if (resetButtonTimePercentage > 1.0)
                {
                    drawingContext.DrawEllipse(Brushes.Green, null, new System.Windows.Point(0, 0), 50, 50);
                    resetButtonTimePercentage = 1.0;
                }
                else
                {
                    drawingContext.DrawEllipse(Brushes.White, null, new System.Windows.Point(0, 0), 50, 50);
                }

                DrawWedge(drawingContext, 0, 0, SweepDirection.Counterclockwise, resetButtonTimePercentage);
                drawingContext.DrawText(
                    new FormattedText("Reset",
                                      System.Globalization.CultureInfo.CurrentCulture,
                                      FlowDirection.LeftToRight,
                                      new Typeface("Arial"),
                                      14.0,
                                      Brushes.Black),
                    new System.Windows.Point(3, 12.5));

                // Draw the done button if we're learning
                if (gLearner.isRecording)
                {
                    if (doneButtonTimer.IsRunning)
                    {
                        doneButtonTimePercentage = (double)doneButtonTimer.ElapsedMilliseconds / (double)BUTTON_HOLD_CUTOFF;
                    }
                    if (doneButtonTimePercentage > 1.0) doneButtonTimePercentage = 1.0;
                    drawingContext.DrawEllipse(Brushes.White, null, new System.Windows.Point(depthFrame.Width, 0), 50, 50);
                    DrawWedge(drawingContext, depthFrame.Width, 0, SweepDirection.Clockwise, doneButtonTimePercentage);
                    drawingContext.DrawText(
                        new FormattedText("Done",
                                          System.Globalization.CultureInfo.CurrentCulture,
                                          FlowDirection.LeftToRight,
                                          new Typeface("Arial"),
                                          14.0,
                                          Brushes.Black),
                        new System.Windows.Point(depthFrame.Width - 35.0, 12.5));
                }
            }

            //End Siavash
            drawHand = true;
            if (drawHand)
            {
                if (myFrame.AvgTorsoPosition != null)
                //if (myFrame.torsoPosition != null)
                {
                    // Anton's code
                    // when a new frame is available, we check if the wrists are crossing the plane and we draw an appropriately colored
                    // rectangle over them to give the user feedback
                    double planeDepth = myFrame.armLength * .8;
                    int planeDepthPixels = (int)((planeDepth / myFrame.armLength) * myFrame.AvgArmLengthPixels);
                    //ThreeDAuth.FlatPlane myPlane = new ThreeDAuth.FlatPlane(myFrame.torsoPosition, planeDepth);
                    ThreeDAuth.FlatPlane myPlane = new ThreeDAuth.FlatPlane(myFrame.AvgTorsoPosition, planeDepth);
                    //Console.WriteLine("Torso depth: " + torsoSkeletonPoint.Z);
                    //ThreeDAuth.Point3d wristRight = new ThreeDAuth.Point3d(rightWrist.Position.X, rightWrist.Position.Y, rightWrist.Position.Z);

                    //ThreeDAuth.DepthPoint right = this.SkeletonPointToScreen(rightWrist.Position);

                    //ThreeDAuth.PlanePoint arrived = new ThreeDAuth.PlanePoint(right.x, right.y, myPlane.crossesPlane(right));

                    //pDistributor.GivePoint(arrived);
                    //Console.WriteLine("Depth: " + hand.depth);

                    short planeDepthmm = (short)(planeDepth * 1000); // convert m to mm
                    Tuple<int, int> handTuple = new Tuple<int, int>(hand.x, hand.y);
                    handTuple = ProjectPoint(handTuple,
                                             myFrame.AvgTorsoPosition,
                                             myFrame.AvgArmLengthPixels,
                                             planeDepthPixels,
                                             .9,
                                             depthFrame.Width,
                                             depthFrame.Height);
                    if (handTuple == null)
                    {
                        // encountered a problem and won't be able to project this point, so drop this frame
                        return;
                    }

                    ThreeDAuth.PlanePoint planePoint = new ThreeDAuth.PlanePoint(handTuple.Item1, handTuple.Item2, myPlane.crossesPlane(hand));
                    //ThreeDAuth.PlanePoint planePoint = new ThreeDAuth.PlanePoint(hand.x, hand.y, myPlane.crossesPlane(hand));
                    pDistributor.GivePoint(planePoint);

                    //drawingContext.DrawRoundedRectangle(Brushes.Green, null, new Rect(hand.x, hand.y, 30, 30), null, 14, null, 14, null);

                    // Check if the point is in the buttons

                    // reset button
                    bool inButton = false;
                    if (Math.Sqrt((planePoint.x * planePoint.x) + (planePoint.y * planePoint.y)) < 50.0)
                    {
                        // in reset button
                        inButton = true;
                        if (!resetButtonTimer.IsRunning)
                        {
                            resetButtonTimer.Start();

                        }
                    }
                    else
                    {
                        if (resetButtonTimer.IsRunning)
                        {

                            resetButtonTimer.Reset();

                        }
                    }

                    // done button
                    if (gLearner.isRecording)
                    {
                        if (Math.Sqrt(((planePoint.x - depthFrame.Width) * (planePoint.x - depthFrame.Width)) +
                                      (planePoint.y * planePoint.y)) < 50.0)
                        {
                            // in done button
                            inButton = true;
                            if (!doneButtonTimer.IsRunning)
                            {

                                doneButtonTimer.Start();
                            }
                        }
                        else
                        {
                            if (doneButtonTimer.IsRunning)
                            {
                                doneButtonTimer.Reset();
                            }
                        }
                    }

                    //drawingContext.DrawRoundedRectangle(Brushes.Yellow, null, new Rect(hand.x, hand.y, 30, 30), null, 14, null, 14, null);

                    //if (arrived.inPlane)
                    if (planePoint.inPlane)
                    {
                        //drawingContext.DrawRoundedRectangle(Brushes.Blue, null, new Rect(right.x, right.y, 30, 30), null, 14, null, 14, null);
                        //drawingContext.DrawRoundedRectangle(Brushes.Blue, null, new Rect(hand.x, hand.y, 30, 30), null, 14, null, 14, null);
                        drawingContext.DrawRoundedRectangle(Brushes.Blue, null, new Rect(planePoint.x, planePoint.y, 30, 30), null, 14, null, 14, null);
                    }
                    else
                    {
                        //drawingContext.DrawRoundedRectangle(Brushes.Red, null, new Rect(right.x, right.y, 30, 30), null, 14, null, 14, null);
                        //drawingContext.DrawRoundedRectangle(Brushes.Red, null, new Rect(hand.x, hand.y, 30, 30), null, 14, null, 14, null);
                        drawingContext.DrawRoundedRectangle(Brushes.Red, null, new Rect(planePoint.x, planePoint.y, 30, 30), null, 14, null, 14, null);
                    }

                    ThreeDAuth.Point3d wristLeft = new ThreeDAuth.Point3d(leftWrist.Position.X, leftWrist.Position.Y, leftWrist.Position.Z);

                    ThreeDAuth.DepthPoint left = this.SkeletonPointToScreen(leftWrist.Position);

                    if (myPlane.crossesPlane(left))
                    {
                        //drawingContext.DrawRoundedRectangle(Brushes.Blue, null, new Rect(left.X, left.Y, 30, 30), null, 14, null, 14, null);
                    }
                    else
                    {
                        //drawingContext.DrawRoundedRectangle(Brushes.Red, null, new Rect(left.X, left.Y, 30, 30), null, 14, null, 14, null);
                    }

                    // Mason's code
                    // If we're learning a gesture, draw the learned points
                    if (gLearner != null && gLearner.isRecording)
                    {
                        System.Collections.Generic.Queue<ThreeDAuth.Point2d> currentPoints = gLearner.getGesturePath();
                        foreach (ThreeDAuth.Point2d point in currentPoints)
                        {
                            drawingContext.DrawRoundedRectangle(Brushes.Green, null, new Rect(point.x, point.y, 30, 30), null, 14, null, 14, null);

                        }
                    }

                    if (gLearner != null && gLearner.isRecording && doneButtonTimePercentage >= 1.0)
                    {
                        // Done recording
                        gLearner.stopRecording();
                        this.myImageBox.Visibility = System.Windows.Visibility.Collapsed;
                        List<ThreeDAuth.Point2d> password = new List<ThreeDAuth.Point2d>(gLearner.getGesturePath());
                        this.currentUser.password = password;
                        this.gestureMassage.Text = "Success. Your account has been created. Welcome to 3DAuth!";
                        SaveUser(currentUser);
                    }

                    if (inButton && resetButtonTimePercentage >= 1.0)
                    {
                        if (gLearner != null && gLearner.isRecording)
                        {
                            // Reset the learner
                            gLearner.restart();
                        }
                        else if (gValidator != null)
                        {
                            // Reset the validator
                            gValidator.restart();
                        }
                    }

                    /*
                    // If we're learning a gesture and we've been out of the plane for 5 seconds, stop learning
                    if (gLearner.isRecording && !planePoint.inPlane)
                    {
                        if (!outOfPlaneTimer.IsRunning)
                        {
                            outOfPlaneTimer.Start();
                        }
                        if (outOfPlaneTimer.ElapsedMilliseconds > BUTTON_HOLD_CUTOFF)
                        {
                            gLearner.stopRecording();
                            this.myImageBox.Visibility = System.Windows.Visibility.Collapsed;
                            List<ThreeDAuth.Point2d> password = new List<ThreeDAuth.Point2d>(gLearner.getGesturePath());
                            this.currentUser.password = password;
                            this.gestureMassage.Text = "Success. Your account has been created. Welcome to 3DAuth!";
                            SaveUser(currentUser);
                        }
                    }
                    else if (gLearner.isRecording)
                    {
                        outOfPlaneTimer.Reset();
                    }
                     * */
                }
            }
        }
Beispiel #5
0
 public bool containsPoint(Point3d point)
 {
     return containsPoint(new Point2d(point.X, point.Y));
 }
Beispiel #6
0
 public void updatePath(Point3d point)
 {
     GridSquare currentSquare = grid.getGridSquareContainingPoint(point);
     if (currentSquare != null)
     {
         currentPath.AddLast(currentSquare);
     }
 }
Beispiel #7
0
 public GridSquare getGridSquareContainingPoint(Point3d point)
 {
     // Initially we just naively search over the entire grid, later we can build in knowledge of closeness to improve performance
     for (int row = 0; row < dimX; row++)
     {
         for (int col = 0; col < dimY; col++)
         {
             if (grid[row, col].containsPoint(point))
             {
                 return grid[row, col];
             }
         }
     }
     return null; // Didn't find a square containing it
 }
Beispiel #8
0
 public Vec3d(Point3d p1, Point3d p2)
 {
     this.p1 = p1;
     this.p2 = p2;
 }
Beispiel #9
0
 public Vec2d(Point3d p1, Point3d p2)
 {
     this.p1 = new Point2d(p1.X, p1.Y);
     this.p2 = new Point2d(p2.X, p2.Y);
 }
Beispiel #10
0
 public static Point3d operator +(Point3d firstPoint, Point3d secondPoint)
 {
     Point3d sumPoint = new Point3d();
     sumPoint.X = firstPoint.X + secondPoint.X;
     sumPoint.Y = firstPoint.Y + secondPoint.Y;
     sumPoint.Z = firstPoint.Z + secondPoint.Z;
     return sumPoint;
 }
Beispiel #11
0
 public static Point3d operator *(Point3d firstPoint, double constant)
 {
     Point3d multPoint = new Point3d();
     multPoint.X = firstPoint.X * constant;
     multPoint.Y = firstPoint.Y * constant;
     multPoint.Z = firstPoint.Z * constant;
     return multPoint;
 }