コード例 #1
0
        override public void GivePoint(Point point)
        {
            if (point is PlanePoint)
            {
                PlanePoint planePoint = (PlanePoint)point;
                if (planePoint.inPlane)
                {
                    Point2d newPoint  = (Point2d)point;
                    long    elapsedMS = stopwatch.ElapsedMilliseconds;
                    if (pointBuffer.Count == 0)
                    {
                        // Enqueue the first point
                        pointBuffer.Enqueue(new TimePointTuple(elapsedMS, newPoint));
                    }
                    else
                    {
                        if ((elapsedMS - pointBuffer.Peek().timeMark > holdTime) &&
                            (pointBuffer.Count >= minNumberOfPoints))
                        {
                            // Have a target point

                            Point2d p = pointBuffer.Peek().point;
                            //Console.WriteLine("Storing point : (" + p.X + ", " + p.Y + ")");
                            learnedGesturePath.Enqueue(pointBuffer.Dequeue().point.copy());
                            pointBuffer.Clear();
                        }
                        else if (Util.euclideanDistance(pointBuffer.Peek().point, newPoint) < motionEpsilon)
                        {
                            // Person is staying still
                            pointBuffer.Enqueue(new TimePointTuple(elapsedMS, newPoint));
                        }
                        else
                        {
                            // Not a target point and person has moved too much, so dump the queue
                            pointBuffer.Clear();
                        }
                    }
                }
                else
                {
                    if (!outOfPlaneTimer.IsRunning)
                    {
                        outOfPlaneTimer.Start();
                    }
                }
            }
        }
コード例 #2
0
 override public void GivePoint(Point point)
 {
     if (point is PlanePoint)
     {
         PlanePoint planePoint = (PlanePoint)point;
         if (planePoint.inPlane)
         {
             Point2d newPoint = (Point2d)point;
             if (stopwatch.ElapsedMilliseconds >= samplingCooldown)
             {
                 learnedGesturePath.Enqueue(newPoint.copy());
                 stopwatch.Stop();
                 stopwatch.Start();
             }
         }
     }
 }
コード例 #3
0
        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();
                    }
                     * */
                }
            }
        }
コード例 #4
0
        public void GivePoint(Point point)
        {
            if (manipulatableTargetPoints.Count > 0)
            {
                if (point is PlanePoint)
                {
                    PlanePoint planePoint = (PlanePoint)point;
                    if (planePoint.inPlane)
                    {
                        Point2d newPoint    = (Point2d)point;
                        Point2d target      = manipulatableTargetPoints.Peek();
                        double  newDistance = Util.euclideanDistance(newPoint, target);
                        if (!_startedPath)
                        {
                            if (newDistance < epsilon)
                            {
                                _startedPath = true;
                                Console.WriteLine("Started path");
                            }
                        }
                        else
                        {
                            if (target != null && !failedAuthentication)
                            {
                                if ((newDistance - 3 * epsilon) > oldDistance)
                                {
                                    // Made a move away from the target point, so failed authentication
                                    failedAuthentication = true;
                                    Console.WriteLine("Failure :( ");
                                    // Give them some time interval to reset it before marking it as a failure

                                    System.Timers.Timer failureTimer = new System.Timers.Timer();
                                    failureTimer.Elapsed  += new System.Timers.ElapsedEventHandler(failureTimer_Elapsed);
                                    failureTimer.Interval  = 3000;
                                    failureTimer.AutoReset = false;
                                    failureTimer.Enabled   = true;
                                }
                                else
                                {
                                    if (newDistance < epsilon)
                                    {
                                        // Hit the target point, so remove it and target the next one
                                        Console.WriteLine("Hit a target point");
                                        manipulatableTargetPoints.Dequeue();
                                        if (manipulatableTargetPoints.Count > 0)
                                        {
                                            oldDistance = Util.euclideanDistance(newPoint, manipulatableTargetPoints.Peek());
                                        }
                                        else
                                        {
                                            // Validated successfully
                                            timer.Stop();
                                            Console.WriteLine("*** Successfully Validated ***");
                                            ValidationComplete();
                                        }
                                    }
                                    else
                                    {
                                        // Didn't hit the target point, but getting closer
                                        oldDistance = newDistance;
                                    }
                                }
                            }
                            Notify();
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: Util.cs プロジェクト: siavash65/CSE481-3DAuth
 public static double euclideanDistance(PlanePoint p1, PlanePoint p2)
 {
     return euclideanDistance(p1.getPoint2d(), p2.getPoint2d());
 }
コード例 #6
0
ファイル: Util.cs プロジェクト: siavash65/CSE481-3DAuth
 public static double euclideanDistance(PlanePoint p1, PlanePoint p2)
 {
     return(euclideanDistance(p1.getPoint2d(), p2.getPoint2d()));
 }