Exemplo n.º 1
0
        public GestureStatus TestBody(Z3Body body, int precision, Context localContext)
        {
            StatisticsEntryMatch matchStat = new StatisticsEntryMatch();

            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var time0 = stopwatch.ElapsedMilliseconds;

            var time1 = stopwatch.ElapsedMilliseconds - time0;

            // NOT THREAD SAFE XXX
            this.LastDistanceVectors = this.UpdateDistanceVectors(body, localContext);

            var time2 = stopwatch.ElapsedMilliseconds - time1;

            // Check distance to target transformed joints and if body satisfies restrictions
            var distance = 2.0;

            if (this.Target.TransformedJoints.Count > 0)
                distance = CalcMaxDistance(this.LastDistanceVectors, this.Target.TransformedJoints);

            this.AccumulatedError += distance - this.LastDistance;
            this.LastDistance = distance;

            var time3 = stopwatch.ElapsedMilliseconds - time2;

            bool transformSucceeded = distance < TrigonometryHelper.GetDistance(precision);

            var time4 = stopwatch.ElapsedMilliseconds - time3;

            // NOT THREAD SAFE XXX
            bool restrictionSucceeded = this.Gesture.Steps[CurrentStep].Pose.IsBodyAccepted(body);

            var time5 = stopwatch.ElapsedMilliseconds - time4;

            matchStat.timeMs = time5;
            matchStat.gestureName = this.Gesture.Name;
            matchStat.uid = frameCount;
            matchStat.poseName = this.Gesture.Steps[CurrentStep].Pose.Name;

            bool succeeded =
                (transformSucceeded || this.Target.TransformedJoints.Count == 0) &&
                (restrictionSucceeded || this.Target.RestrictedJoints.Count == 0);

            // Overall succeeded represents whether the entire gesture was matched on this test, not just a single pose
            bool overallSucceeded = false;

            // If body is accepted move to matching the next pose in sequence
            if (succeeded)
            {
                this.CurrentStep += 1;
                this.AccumulatedError = 0;

                // Check if gesture is completed (all steps are finished)
                if (this.CurrentStep >= this.Gesture.Steps.Count)
                {
                    this.Reset(body);
                    this.CompletedCount += 1;
                    overallSucceeded = true;
                }

                this.UpdateTargetBody(body);
            }
            // If body was not accepted then check if error is higher than threshold
            // If accumulated error is too high the gesture is broken
            else if (this.AccumulatedError > 1)
            {
                //gesture.Reset(body);
            }

            var result = this.GetStatus();

            // The VisualGestureBuilder API for DiscreteGestureResult cares about whole gestures,
            // not about individual poses. We need to check for this case explicitly.
            // We then expose succeededDetection in a DiscreteGestureResult .
            result.succeededDetection = overallSucceeded;

            // TODO: check the semantics of succeededDetectionFirstFrame in the VisualGestureBuilder API
            // We here are assuming that firstFrame means this is the first frame where we successfully detected the gesture
            // We are assuming that firstFrame does NOT mean this is the first frame where we started tracking the gesture
            if (CompletedCount == 1 & overallSucceeded)
                result.succeededDetectionFirstFrame = true;
            else
                result.succeededDetectionFirstFrame = false;

            // TODO: check the semantics of confidence in the VisualGestureBuilder API.
            // Here confidence is the same as distance from the target body.
            // That is NOT the same as if confidence were a probability that we are correct
            // We want to have as close semantics as possible to the VisualGestureBuilder API, so we need to double check this
            result.confidence = (float)distance;

            var time6 = stopwatch.ElapsedMilliseconds - time5;
            frameCount++;

            // Record the statistics entry here
            GestureStatistics.matchTimes.Add(matchStat);
            return result;
        }
Exemplo n.º 2
0
        public GestureStatus TestBody(Z3Body body, int precision, Context localContext)
        {
            StatisticsEntryMatch matchStat = new StatisticsEntryMatch();

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var time0 = stopwatch.ElapsedMilliseconds;


            var time1 = stopwatch.ElapsedMilliseconds - time0;

            // NOT THREAD SAFE XXX
            this.LastDistanceVectors = this.UpdateDistanceVectors(body, localContext);

            var time2 = stopwatch.ElapsedMilliseconds - time1;

            // Check distance to target transformed joints and if body satisfies restrictions
            var distance = 2.0;


            if (this.Target.TransformedJoints.Count > 0)
            {
                distance = CalcMaxDistance(this.LastDistanceVectors, this.Target.TransformedJoints);
            }


            this.AccumulatedError += distance - this.LastDistance;
            this.LastDistance      = distance;

            var time3 = stopwatch.ElapsedMilliseconds - time2;

            bool transformSucceeded = distance < TrigonometryHelper.GetDistance(precision);

            var time4 = stopwatch.ElapsedMilliseconds - time3;

            // NOT THREAD SAFE XXX
            bool restrictionSucceeded = this.Gesture.Steps[CurrentStep].Pose.IsBodyAccepted(body);

            var time5 = stopwatch.ElapsedMilliseconds - time4;

            matchStat.timeMs      = time5;
            matchStat.gestureName = this.Gesture.Name;
            matchStat.uid         = frameCount;
            matchStat.poseName    = this.Gesture.Steps[CurrentStep].Pose.Name;

            bool succeeded =
                (transformSucceeded || this.Target.TransformedJoints.Count == 0) &&
                (restrictionSucceeded || this.Target.RestrictedJoints.Count == 0);

            // Overall succeeded represents whether the entire gesture was matched on this test, not just a single pose
            bool overallSucceeded = false;

            // If body is accepted move to matching the next pose in sequence
            if (succeeded)
            {
                this.CurrentStep     += 1;
                this.AccumulatedError = 0;

                // Check if gesture is completed (all steps are finished)
                if (this.CurrentStep >= this.Gesture.Steps.Count)
                {
                    this.Reset(body);
                    this.CompletedCount += 1;
                    overallSucceeded     = true;
                }

                this.UpdateTargetBody(body);
            }
            // If body was not accepted then check if error is higher than threshold
            // If accumulated error is too high the gesture is broken
            else if (this.AccumulatedError > 1)
            {
                //gesture.Reset(body);
            }

            var result = this.GetStatus();

            // The VisualGestureBuilder API for DiscreteGestureResult cares about whole gestures,
            // not about individual poses. We need to check for this case explicitly.
            // We then expose succeededDetection in a DiscreteGestureResult .
            result.succeededDetection = overallSucceeded;

            // TODO: check the semantics of succeededDetectionFirstFrame in the VisualGestureBuilder API
            // We here are assuming that firstFrame means this is the first frame where we successfully detected the gesture
            // We are assuming that firstFrame does NOT mean this is the first frame where we started tracking the gesture
            if (CompletedCount == 1 & overallSucceeded)
            {
                result.succeededDetectionFirstFrame = true;
            }
            else
            {
                result.succeededDetectionFirstFrame = false;
            }

            // TODO: check the semantics of confidence in the VisualGestureBuilder API.
            // Here confidence is the same as distance from the target body.
            // That is NOT the same as if confidence were a probability that we are correct
            // We want to have as close semantics as possible to the VisualGestureBuilder API, so we need to double check this
            result.confidence = (float)distance;

            var time6 = stopwatch.ElapsedMilliseconds - time5;

            frameCount++;


            // Record the statistics entry here
            GestureStatistics.matchTimes.Add(matchStat);
            return(result);
        }
Exemplo n.º 3
0
        public GestureStatus MatchBody(Z3Body body, int precision, Context localContext)
        {
            var matchStat = new StatisticsEntryMatch();
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var time0 = stopwatch.ElapsedMilliseconds;

            // NOT THREAD SAFE
            this.LastDistanceVectors = this.UpdateDistanceVectors(body, localContext);

            // Check distance to target transformed joints and if body satisfies restrictions
            var transformsPercentage   = 0.0;
            var restrictionsPercentage = 0.0;
            var mainRestriction        = "";

            this.CalcPercentages(
                body,
                precision,
                out transformsPercentage,
                out restrictionsPercentage,
                out mainRestriction);
            this.MainRestriction = mainRestriction;

            var gestureSucceeded = false;
            var gestureBroke     = false;
            var stepPercentage   = Math.Min(transformsPercentage, restrictionsPercentage);
            var performanceError = Math.Max(0.0, this.StepLastPercentage - stepPercentage);
            var stepSucceeded    = stepPercentage >= 1.0;

            this.StepLastPercentage = stepPercentage;

            // Increase AccumulatedError only if performanceError is positive
            if (performanceError > 0.00001)
            {
                // delay error only applies if the performance is negative
                var baseError     = 0.1; // 0.1 base error allows no more than 0.3 sec of bad performance
                var weightedError = performanceError * 3;
                this.AccumulatedError += baseError + weightedError;

                // If accumulated error is too high the gesture is broken
                if (this.AccumulatedError > 1)
                {
                    this.Reset(body);
                    this.AccumulatedError = 0;
                    gestureBroke          = true;

                    // Immediatilly update step percentage
                    this.CalcPercentages(
                        body,
                        precision,
                        out transformsPercentage,
                        out restrictionsPercentage,
                        out mainRestriction);

                    this.StepLastPercentage = Math.Min(transformsPercentage, restrictionsPercentage);
                }
            }

            // If body is accepted move to matching the next pose in sequence
            if (stepSucceeded)
            {
                this.CurrentStep     += 1;
                this.AccumulatedError = 0;

                // Check if gesture is completed (all steps are finished)
                if (this.CurrentStep >= this.Gesture.Steps.Count)
                {
                    this.Reset(body);
                    this.CompletedCount += 1;
                    gestureSucceeded     = true;
                }
                this.UpdateTargetBody(body);

                // Immediatilly update step percentage
                this.CalcPercentages(
                    body,
                    precision,
                    out transformsPercentage,
                    out restrictionsPercentage,
                    out mainRestriction);

                this.StepLastPercentage = Math.Min(transformsPercentage, restrictionsPercentage);
            }
            var result = this.GetStatus();

            result.Broke = gestureBroke;

            // The VisualGestureBuilder API for DiscreteGestureResult cares about whole gestures,
            // not about individual poses. We need to check for this case explicitly.
            // We then expose succeededDetection in a DiscreteGestureResult .
            result.Succeeded = gestureSucceeded;

            // TODO: check the semantics of succeededDetectionFirstFrame in the VisualGestureBuilder API
            // We here are assuming that firstFrame means this is the first frame where we successfully detected the gesture
            // We are assuming that firstFrame does NOT mean this is the first frame where we started tracking the gesture
            if (CompletedCount == 1 & gestureSucceeded)
            {
                result.SucceededFirstFrame = true;
            }
            else
            {
                result.SucceededFirstFrame = false;
            }

            // TODO: check the semantics of confidence in the VisualGestureBuilder API.
            // Here confidence is the same as distance from the target body.
            // That is NOT the same as if confidence were a probability that we are correct
            // We want to have as close semantics as possible to the VisualGestureBuilder API,
            // so we need to double check this
            result.Confidence = (float)result.GetGesturePercentage();

            matchStat.timeMs      = stopwatch.ElapsedMilliseconds - time0;
            matchStat.gestureName = this.Gesture.Name;
            matchStat.uid         = frameCount;
            matchStat.poseName    = this.Gesture.Steps[CurrentStep].Pose.Name;

            // Record the statistics entry here
            GestureStatistics.matchTimes.Add(matchStat);
            frameCount++;

            return(result);
        }
Exemplo n.º 4
0
        public GestureStatus MatchBody(Z3Body body, int precision, Context localContext)
        {
            var matchStat = new StatisticsEntryMatch();
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var time0 = stopwatch.ElapsedMilliseconds;

            // NOT THREAD SAFE
            this.LastDistanceVectors = this.UpdateDistanceVectors(body, localContext);

            // Check distance to target transformed joints and if body satisfies restrictions
            var transformsPercentage = 0.0;
            var restrictionsPercentage = 0.0;
            var mainRestriction = "";
            this.CalcPercentages(
                body,
                precision,
                out transformsPercentage,
                out restrictionsPercentage,
                out mainRestriction);
            this.MainRestriction = mainRestriction;

            var gestureSucceeded = false;
            var gestureBroke = false;
            var stepPercentage = Math.Min(transformsPercentage, restrictionsPercentage);
            var performanceError = Math.Max(0.0, this.StepLastPercentage - stepPercentage);
            var stepSucceeded = stepPercentage >= 1.0;
            this.StepLastPercentage = stepPercentage;

            // Increase AccumulatedError only if performanceError is positive
            if (performanceError > 0.00001)
            {
                // delay error only applies if the performance is negative
                var baseError = 0.1; // 0.1 base error allows no more than 0.3 sec of bad performance
                var weightedError = performanceError * 3;
                this.AccumulatedError += baseError + weightedError;

                // If accumulated error is too high the gesture is broken
                if (this.AccumulatedError > 1)
                {
                    this.Reset(body);
                    this.AccumulatedError = 0;
                    gestureBroke = true;
                }
            }

            // If body is accepted move to matching the next pose in sequence
            if (stepSucceeded)
            {
                this.CurrentStep += 1;
                this.AccumulatedError = 0;

                // Check if gesture is completed (all steps are finished)
                if (this.CurrentStep >= this.Gesture.Steps.Count)
                {
                    this.Reset(body);
                    this.CompletedCount += 1;
                    gestureSucceeded = true;
                }
                this.UpdateTargetBody(body);

                // Immediatilly update step percentage
                this.CalcPercentages(
                    body,
                    precision,
                    out transformsPercentage,
                    out restrictionsPercentage,
                    out mainRestriction);

                this.StepLastPercentage = Math.Min(transformsPercentage, restrictionsPercentage);
            }
            var result = this.GetStatus();
            result.Broke = gestureBroke;

            // The VisualGestureBuilder API for DiscreteGestureResult cares about whole gestures,
            // not about individual poses. We need to check for this case explicitly.
            // We then expose succeededDetection in a DiscreteGestureResult .
            result.Succeeded = gestureSucceeded;

            // TODO: check the semantics of succeededDetectionFirstFrame in the VisualGestureBuilder API
            // We here are assuming that firstFrame means this is the first frame where we successfully detected the gesture
            // We are assuming that firstFrame does NOT mean this is the first frame where we started tracking the gesture
            if (CompletedCount == 1 & gestureSucceeded)
                result.SucceededFirstFrame = true;
            else
                result.SucceededFirstFrame = false;

            // TODO: check the semantics of confidence in the VisualGestureBuilder API.
            // Here confidence is the same as distance from the target body.
            // That is NOT the same as if confidence were a probability that we are correct
            // We want to have as close semantics as possible to the VisualGestureBuilder API,
            // so we need to double check this
            result.Confidence = (float) result.GetGesturePercentage();

            matchStat.timeMs = stopwatch.ElapsedMilliseconds - time0;
            matchStat.gestureName = this.Gesture.Name;
            matchStat.uid = frameCount;
            matchStat.poseName = this.Gesture.Steps[CurrentStep].Pose.Name;

            // Record the statistics entry here
            GestureStatistics.matchTimes.Add(matchStat);
            frameCount++;

            return result;
        }