public void handleHandMovement(InteractionHandPointer hand) { if (handMoved == null) { return; } currentHandType = hand.HandType; //handle horizontal hand movement if (Math.Abs(hand.X - prevMoveLocation.X) > horizontalSensitivity) { double speed = horizontalSensitivity / DateTime.Now.Subtract(lastHMoveTime).Milliseconds; lastHMoveTime = DateTime.UtcNow; HandMovedDirection dir = (hand.X - prevMoveLocation.X) > 0 ? HandMovedDirection.right : HandMovedDirection.left; var e = new HandMovedEventArgs(dir, MovementType.grip, hand.HandType, new Point(hand.X, hand.Y), speed); handMoved(this, e); prevMoveLocation = new Point(hand.X, hand.Y); } //handle vertical hand movement if (Math.Abs(hand.Y - prevMoveLocation.Y) > verticalSensitivity) { double speed = verticalSensitivity / DateTime.Now.Subtract(lastVMoveTime).Milliseconds; lastVMoveTime = DateTime.UtcNow; HandMovedDirection dir = (hand.Y - prevMoveLocation.Y) > 0 ? HandMovedDirection.down : HandMovedDirection.up; var e = new HandMovedEventArgs(dir, MovementType.grip, hand.HandType, new Point(hand.X, hand.Y), speed); handMoved(this, e); prevMoveLocation = new Point(hand.X, hand.Y); } }
private void ParseHandEvent(InteractionHandPointer hand) { if (hand.HandEventType == InteractionHandEventType.None) { return; } if (hand.HandType == InteractionHandType.Right) { if (hand.HandEventType == InteractionHandEventType.Grip) { status.Text = "右手握拳"; } else { status.Text = "右手張開"; } } else if (hand.HandType == InteractionHandType.Left) { if (hand.HandEventType == InteractionHandEventType.Grip) { status.Text = "左手握拳"; } else { status.Text = "左手張開"; } } }
public override bool isInteractionActive(ReadOnlyCollection <InteractionHandPointer> hands) { // if primary hand is active and secondary hand is active, secondary hand is above certain height -> return true foreach (var hand in hands) { if (hand.HandType != InteractionHandType.None) { if (hand.IsPrimaryForUser) { primaryHand = hand; } else { secondaryHand = hand; } } } if (primaryHand == null || secondaryHand == null || !primaryHand.IsActive) { return(false); } if (secondaryHand.Y < 1.2) { return(true); } else { return(false); } }
public override bool isInteractionActive(ReadOnlyCollection<InteractionHandPointer> hands) { // if primary hand is active and secondary hand is active, secondary hand is above certain height -> return true foreach (var hand in hands) { if (hand.HandType != InteractionHandType.None) { if (hand.IsPrimaryForUser) { primaryHand = hand; } else { secondaryHand = hand; } } } if (primaryHand == null || secondaryHand == null || !primaryHand.IsActive) return false; if (secondaryHand.Y < 1.2) return true; else return false; }
private static string FormatHandData(InteractionHandPointer hand) { string rawxloc = String.Format("X座標:{0:0.0}", hand.RawX); string rawyloc = String.Format(",Y座標:{0:0.0}", hand.RawY); string rawzloc = String.Format(",Z座標:{0:0.0}", hand.RawZ); //string xloc = String.Format(",校正X座標:{0:0.0}", hand.X); //string yloc = String.Format(",校正Y座標:{0:0.0}", hand.Y); return(rawxloc + rawyloc + rawzloc); }
public void fireGripReleaseEvent(InteractionHandPointer hand) { if (handGripRelease != null) { handGripRelease(this, new HandGripReleaseEventArgs(hand.HandType)); } //startInertiaScroll(hand); //clear scroll Type scrollType = InertiaScroller.ScrollType.none; }
public void saveHandLocation(InteractionHandPointer hand) { if (hand.HandType == InteractionHandType.Left) { prevFrameLeftLocation.X = hand.X; prevFrameLeftLocation.Y = hand.Y; } if (hand.HandType == InteractionHandType.Right) { prevFrameRightLocation.X = hand.X; prevFrameRightLocation.Y = hand.Y; } }
public void fireGripEvent(InteractionHandPointer hand) { if (handGrip != null) { //stop inertia scrolling if (inertiaScroller.status == InertiaScroller.ScrollStatus.scrolling) { inertiaScroller.stopScrolling(); } //fire grip event handGrip(this, new HandGripEventArgs(hand.HandType)); } }
private InteractionHandEventType DetermineLastHandEvent(InteractionHandPointer hand, int userID) { var lastHandEvents = hand.HandType == InteractionHandType.Left ? _lastLeftHandEvents : _lastRightHandEvents; if (hand.HandEventType != InteractionHandEventType.None) { lastHandEvents[userID] = hand.HandEventType; } var lastHandEvent = lastHandEvents.ContainsKey(userID) ? lastHandEvents[userID] : InteractionHandEventType.None; return(lastHandEvent); }
public void handleHandPress(InteractionHandPointer hand) { if (hand.HandType == InteractionHandType.Left && hand.IsPressed != leftHandPressed) { if (leftHandPressed == true && handPressed != null) { handPressed(this, new HandPressedEventArgs(hand.HandType)); } leftHandPressed = hand.IsPressed; } if (hand.HandType == InteractionHandType.Right && hand.IsPressed != rightHandPressed) { if (rightHandPressed == true && handPressed != null) { handPressed(this, new HandPressedEventArgs(hand.HandType)); } rightHandPressed = hand.IsPressed; } }
public override bool isInteractionActive(ReadOnlyCollection <InteractionHandPointer> hands) { // if primary hand is event is grip -> return true foreach (var hand in hands) { if (hand.HandType != InteractionHandType.None) { if (hand.IsPrimaryForUser) { primaryHand = hand; break; } else { continue; } } } if (primaryHand == null) { return(false); } if (primaryHand.HandEventType != InteractionHandEventType.None) { lastHandEvent = primaryHand.HandEventType; } if (primaryHand == null || !primaryHand.IsActive) { return(false); } if (lastHandEvent == InteractionHandEventType.Grip) { return(true); } else { return(false); } }
public override bool isInteractionActive(ReadOnlyCollection<InteractionHandPointer> hands) { // if primary hand is event is grip -> return true foreach (var hand in hands) { if (hand.HandType != InteractionHandType.None) { if (hand.IsPrimaryForUser) { primaryHand = hand; break; } else { continue; } } } if (primaryHand == null) return false; if(primaryHand.HandEventType != InteractionHandEventType.None) lastHandEvent = primaryHand.HandEventType; if (primaryHand == null || !primaryHand.IsActive) return false; if (lastHandEvent == InteractionHandEventType.Grip) { return true; } else { return false; } }
public void startInertiaScroll(InteractionHandPointer hand) { currentHandType = hand.HandType; //start horizontal inertia scrolling if (hInertiaEnabled && scrollType == InertiaScroller.ScrollType.horizontal) { //with *1000 factor speed will be ~ 1<speed<8 double speed = (1000 * (hand.X - prevMoveLocation.X) / (DateTime.UtcNow.Subtract(lastHMoveTime).Milliseconds)); inertiaScroller.keepScrolling(speed, hand.HandType, scrollType); //Debug //Console.WriteLine("speed: {0} type: {1}", speed, scrollType); } //keep vertical inertia scrolling if (vInertiaEnabled && scrollType == InertiaScroller.ScrollType.vertical) { //with *1000 factor speed will be ~ 1<speed<8 double speed = (1000 * (hand.Y - prevMoveLocation.Y) / (DateTime.UtcNow.Subtract(lastVMoveTime).Milliseconds)); inertiaScroller.keepScrolling(speed, hand.HandType, scrollType); //Debug //Console.WriteLine("speed: {0} type: {1}", speed, scrollType); } }
private void InteractionStreamOnInteractionFrameReady(object sender, InteractionFrameReadyEventArgs e) { TrackClosestSkeleton(); using (var iaf = e.OpenInteractionFrame()) { if (iaf == null) { return; } iaf.CopyInteractionDataTo(_userInfos); } if (distanciaManoCabeza(true) > 0 && distanciaManoCabeza(true) < 0.2) { vaciarCanvas(); } // for activating and disabling draw //pinta o no pinta //es decir cuando esta abierta la mana (!isDrawActive) if (controlManager.isDrawActive(_userInfos, _skeletons)) { newPoint = controlManager.getCursorLocation(kinectRegion); if (oldDepth == null || stopDraw == true) { oldDepth = newDepth; } if (oldPoint == null || stopDraw == true) { oldPoint = newPoint; } newDepth = controlManager.getHandLocation(); if (stopDraw) { if (isHandOver(oldPoint, buttons)) { stopDraw = false; primeraProfundidad = getprofundidad(); if (selected.Uid != "elegido") { stopDraw = true; var nuevo = ClonarBoton(selected); Canvas.SetLeft(nuevo, newPoint.X - selected.Width / 2); Canvas.SetTop(nuevo, newPoint.Y - selected.Height / 2); this.canvasKinect.Children.Add(nuevo); selected = nuevo; buttons.Insert(0, nuevo); } } } if (!stopDraw && selected.Uid == "elegido") { InformacionObra(selected.Name); Canvas.SetLeft(selected, newPoint.X - selected.Width / 2); Canvas.SetTop(selected, newPoint.Y - selected.Height / 2); profundidad = getprofundidad(); double widthNuevo = selected.Width - (primeraProfundidad - profundidad) * 1.5; double heightNuevo = selected.Height - (primeraProfundidad - profundidad) * 1.5; if (widthNuevo > 75 && heightNuevo > 75 && widthNuevo < 500 && heightNuevo < 500) { selected.Width = widthNuevo; selected.Height = heightNuevo; } } } else { kinectRegion.Tag = ""; if (selected != null) { double margenIzquierdo = Canvas.GetLeft(selected); double margenSuperior = Canvas.GetTop(selected); if (!EnviarPapelera(selected)) { if (margenSuperior < 0) { Canvas.SetTop(selected, 0); } if (margenSuperior > 800 - selected.Height) { Canvas.SetTop(selected, 800 - selected.Height); } if (margenIzquierdo < margenIzquierdoMin) { Canvas.SetLeft(selected, margenIzquierdoMin); } if (margenIzquierdo > margenDerechoMax - selected.Width) { Canvas.SetLeft(selected, margenDerechoMax - selected.Width); } } } selected = null; stopDraw = true; primeraProfundidad = 0; profundidad = 0; //Detector de gestos mano abierta if (!reconociendo) { puntoInicial = getManoPrincipal(); if (puntoInicial != null) { start = new TimeSpan(DateTime.Now.Ticks); reconociendo = true; } } else { InteractionHandPointer puntoActual = getManoPrincipal(); if (puntoActual != null) { if (Math.Abs(puntoActual.Y - puntoInicial.Y) > 0.1) { reconociendo = false; } else { if (puntoActual.X - puntoInicial.X > 0.4) { TimeSpan stop_local = new TimeSpan(DateTime.Now.Ticks); if ((stop_local - start).TotalMilliseconds < 200) { CambiarPagina(1); reconociendo = false; } else { reconociendo = false; } } else if (puntoActual.X - puntoInicial.X < -0.4) { TimeSpan stop_local = new TimeSpan(DateTime.Now.Ticks); if ((stop_local - start).TotalMilliseconds < 250) { CambiarPagina(-1); reconociendo = false; } else { reconociendo = false; } } } } TimeSpan stop = new TimeSpan(DateTime.Now.Ticks); if ((stop - start).TotalMilliseconds > 200) { reconociendo = false; } } } }
private void HandleHandPointerData(long timeStamp, UserInfo userInfo, int userIndex, InteractionHandPointer handPointer) { var interactionData = new InteractionFrameData { TimeStampOfLastUpdate = timeStamp, TrackingId = userInfo.SkeletonTrackingId, PlayerIndex = userIndex, HandType = EnumHelper.ConvertHandType(handPointer.HandType), IsTracked = handPointer.IsTracked, IsActive = handPointer.IsActive, IsInteractive = handPointer.IsInteractive, IsPressed = handPointer.IsPressed, IsPrimaryHandOfUser = handPointer.IsPrimaryForUser, IsPrimaryUser = (userInfo.SkeletonTrackingId == this.PrimaryUserTrackingId) && (userInfo.SkeletonTrackingId != KinectPrimaryUserTracker.InvalidUserTrackingId), HandEventType = EnumHelper.ConvertHandEventType(handPointer.HandEventType), X = handPointer.X, Y = handPointer.Y, Z = handPointer.PressExtent }; this.kinectAdapter.HandleHandPointerData(interactionData); }
public static Point WindowPointFromHandPointer( InteractionHandPointer p ) { double offset = 0.325; double min = 0; double max = 1.5; double pointX = p.X + offset; double pointY = p.Y + offset; if ( pointX < min ) pointX = min; else if ( pointX > max ) pointX = max; if ( pointY < min ) pointY = min; else if ( pointY > max ) pointY = max; float x = (float)( pointX / 1.5 * KinectSensorController.DEPTH_FRAME_WIDTH ); float y = (float)( pointY / 1.5 * KinectSensorController.DEPTH_FRAME_HEIGHT ); return new System.Windows.Point( x, y ); }
//function to update the model of the hand and to draw the cursor corresponding to the given hand private void updateHand(InteractionHandPointer h) { //current Hand Hand hand = h.HandType == InteractionHandType.Left ? hands.Item1 : hands.Item2; //update the model of the hand hand.x = h.X * window.canvas.Width; hand.y = h.Y * window.canvas.Height; //check if the hand is grip if (!hand.grip && h.HandEventType == InteractionHandEventType.Grip) { hand.grip = true; } else if (hand.grip && h.HandEventType == InteractionHandEventType.GripRelease) { hand.grip = false; hand.attachedObjectName = ""; } //check if the hand is pressed if (h.PressExtent > 1 && !hand.pressed) { hand.pressed = true; } else if (h.PressExtent == 0 && hand.pressed) { hand.pressed = false; } //set the just grip or just release value if (h.HandEventType == InteractionHandEventType.Grip && hand.lastEvent != "Grip") { hand.justGrip = true; Hand.distance = ImageTools.getDistance(hands.Item1, hands.Item2); } else hand.justGrip = false; //set just release value if (h.HandEventType == InteractionHandEventType.GripRelease && hand.lastEvent != "GripRelease") { hand.justReleased = true; Hand.distance = ImageTools.getDistance(hands.Item1, hands.Item2); } else hand.justReleased = false; //update of the lastHandEvent switch (h.HandEventType) { case InteractionHandEventType.Grip: hand.lastEvent = "Grip"; break; case InteractionHandEventType.GripRelease: hand.lastEvent = "GripRelease"; break; case InteractionHandEventType.None: hand.lastEvent = "None"; break; } }
public static Boolean IsInGrip(InteractionHandPointer hand) { return (hand.HandEventType == InteractionHandEventType.Grip); }
private void HandleHandPointerData(long timeStamp, UserInfo userInfo, int userIndex, InteractionHandPointer handPointer) { //var parameters = this.KinectSensor.CoordinateMapper.ColorToDepthRelationalParameters; //byte[] mapper = new byte[parameters.Count]; //parameters.CopyTo(mapper, 0); var interactionData = new InteractionFrameData { TimeStampOfLastUpdate = timeStamp, TrackingId = userInfo.SkeletonTrackingId, PlayerIndex = userIndex, HandType = EnumHelper.ConvertHandType(handPointer.HandType), IsTracked = handPointer.IsTracked, IsActive = handPointer.IsActive, IsInteractive = handPointer.IsInteractive, IsPressed = handPointer.IsPressed, //IsPrimaryHandOfUser = handPointer.IsPrimaryForUser, IsPrimaryHandOfUser = false, IsPrimaryUser = (userInfo.SkeletonTrackingId == this.PrimaryUserTrackingId) && (userInfo.SkeletonTrackingId != KinectPrimaryUserTracker.InvalidUserTrackingId), HandEventType = EnumHelper.ConvertHandEventType(handPointer.HandEventType), X = handPointer.X, Y = handPointer.Y, Z = handPointer.PressExtent }; this.kinectAdapter.HandleHandPointerData(interactionData); }
private void trackLeftHandState(UserSkeletonState skeletonState, InteractionHandPointer handPointer) { if (handPointer.HandEventType == InteractionHandEventType.Grip) { skeletonState.IsLeftHandGripped = true; } else if (handPointer.HandEventType == InteractionHandEventType.GripRelease) { skeletonState.IsLeftHandGripped = false; } }
private void trackRightHandState(UserSkeletonState skeletonState, InteractionHandPointer handPointer) { if (handPointer.IsPressed) { //Do not repeat output //if (pressState != 2) //Output.Debug("KinectControl", "Hand Pressed " + handPointer.PressExtent.ToString()); pressState = 2; } else if (handPointer.PressExtent > 0.5d) { //Do not repeat output //if (pressState != 1) //Output.Debug("KinectControl", "Hand Almost Pressed " + handPointer.PressExtent.ToString()); pressState = 1; } if (handPointer.HandEventType == InteractionHandEventType.Grip) { skeletonState.IsRightHandGripped = true; } else if (handPointer.HandEventType == InteractionHandEventType.GripRelease) { skeletonState.IsRightHandGripped = false; } }
public void analyzeHandPointer(InteractionHandPointer hand) { saveHandLocation(hand); switch (hand.HandEventType) { case InteractionHandEventType.Grip: if (hand.HandType == InteractionHandType.Right) { if (countingRightGripReleaseFrames) { countingRightGripReleaseFrames = false; break; } countingRightGripFrames = true; framesSinceRightHandGrip = 0; } if (hand.HandType == InteractionHandType.Left) { fireGripEvent(hand); } break; case InteractionHandEventType.GripRelease: if (hand.HandType == InteractionHandType.Right) { if (countingRightGripFrames) { countingRightGripFrames = false; break; } countingRightGripReleaseFrames = true; framesSinceRightHandGripRelease = 0; } if (hand.HandType == InteractionHandType.Left) { fireGripReleaseEvent(hand); } break; case InteractionHandEventType.None: if (countingRightGripFrames) { framesSinceRightHandGrip++; if (framesSinceRightHandGrip > 3) { countingRightGripFrames = false; fireGripEvent(hand); } } if (countingRightGripReleaseFrames) { framesSinceRightHandGripRelease++; if (framesSinceRightHandGripRelease > 3) { countingRightGripReleaseFrames = false; fireGripReleaseEvent(hand); } } break; default: break; } if (hand.HandEventType == InteractionHandEventType.Grip) { //Console.WriteLine("{0} Grip frame", hand.HandType); fireGripEvent(hand); } if (hand.HandEventType == InteractionHandEventType.GripRelease) { //Console.WriteLine("{0} GripRelease frame", hand.HandType); fireGripReleaseEvent(hand); } //handle clicks handleHandPress(hand); //handles all movement events(left/right/horizontal/vertical) handleHandMovement(hand); }