protected void DetectLeapGesture(Controller leap, Leap.Frame frame) { GestureList gestures = frame.Gestures(); foreach (Gesture gesture in gestures) { if (gesture.State != Gesture.GestureState.STATESTOP) { continue; } switch (gesture.Type) { case Gesture.GestureType.TYPESWIPE: SwipeGesture swipe = new SwipeGesture(gesture); if (swipe.StartPosition.x < 0 && swipe.Direction.x > 0) { TurnSlide(-1); } else if (swipe.StartPosition.x > 0 && swipe.Direction.x < 0) { TurnSlide(+1); } break; default: break; } } }
void newFrameHandler(Leap.Frame frame) { /*switch (frame.Gesture(frame.Gestures().Count).Type)*/ for (int g = 0; g < frame.Gestures().Count; g++) { Gesture gesture = frame.Gestures()[g]; switch (gesture.Type) { case Gesture.GestureType.TYPE_SWIPE: swipeDetected(frame.Gestures()[g], frame.Gestures()[g + 1]); break; case Gesture.GestureType.TYPE_CIRCLE: circleDetected(); break; case Gesture.GestureType.TYPE_SCREEN_TAP: screenTapDetected(); break; } } }
void newFrameHandler(Leap.Frame frame) { int rot_on = 0; currentTime = frame.Timestamp; timeChange = currentTime - previousTime; this.displayTimestamp.Content = timeChange; HandList hands = frame.Hands; Hand firstHand = hands[0]; Hand secondHand = hands[1]; if (timeChange > 100000) { if (hands[0].IsValid) { if (hands[0].IsRight) { this.displayID.Content = "오른손 작동"; } else { this.displayID.Content = "왼손 작동"; } if (hands[0].GrabStrength > 0.5) { if (hands[0].IsRight) { // this.displayFPS.Content = "오른손 주먹"; } else { // this.displayFPS.Content = "왼손 주먹"; } } else { // this.displayFPS.Content = "손 펴져있음"; } //양손일때 if (hands[1].IsValid) { this.displayID.Content = "양손 작동"; //Console.WriteLine(hands[1].PinchStrength); if (hands[1].GrabStrength > 0.5) { if (hands[0].GrabStrength == 0) { if (hands[1].IsRight) { // this.displayFPS.Content = "오른손 주먹"; } else { // this.displayFPS.Content = "왼손 주먹"; rot_on = 1; } } else { // this.displayFPS.Content = "양손 주먹"; } } } } else { this.displayID.Content = "손 없음"; } var handVelocity = (int)firstHand.PalmVelocity.Magnitude; if (handVelocity < 200)//1500 { // Console.WriteLine(handVelocity); //this.displayImageCount.Content = "손빠르기"; this.displayGestureCount.Content = " "; } else { for (int g = 0; g < frame.Gestures().Count; g++) { //switch(frame.Gesture(0).Type) Gesture gesture = frame.Gestures()[g]; if (swipe_d == 1) { } else if (swipe_d == -1) { } else if (swipe_d == 0) { switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: CircleGesture cir = new CircleGesture(frame.Gesture(g)); // CircleGesture cir = new CircleGesture(frame.Gesture(0)); String clockwiseness; if (cir.Pointable.Direction.AngleTo(cir.Normal) <= Math.PI / 2) { clockwiseness = "clockwise"; } else { clockwiseness = "counterclockwise"; } //this.displayImageCount.Content = frame.Gesture(g).ToString() + "의 지름은 " + cir.Radius + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State; this.displayGestureCount.Content = "원방향" + clockwiseness; Console.WriteLine("원방향" + clockwiseness); break; /* case Gesture.GestureType.TYPE_KEY_TAP: //Handle key tap gestures KeyTapGesture keytapGesture = new KeyTapGesture(frame.Gesture(g)); // this.displayImageCount.Content = "키탭"; Console.WriteLine(frame.Gesture(g).ToString() + "의 방향은 " + keytapGesture.Direction + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State); Console.WriteLine(frame.Gesture(g).ToString() + "의 포인터은 " + keytapGesture.Pointable + "그리고" + keytapGesture.Position); break; case Gesture.GestureType.TYPE_SCREEN_TAP: //Handle screen tap gestures // this.displayImageCount.Content = "스크린탭"; ScreenTapGesture screentapGesture = new ScreenTapGesture(frame.Gesture(g)); Console.WriteLine(screentapGesture.Direction); break; */ case Gesture.GestureType.TYPE_SWIPE: // this.displayImageCount.Content = "쓸기"; SwipeGesture swipeGesture = new SwipeGesture(gesture); //1. start position위치 확인 Leap.Vector start = iBox.NormalizePoint(swipeGesture.StartPosition); // if (start.x > 0.9 || start.x < 0.1 ) return; //2. swipe speed 확인 float speed = swipeGesture.Speed; // if (speed < 1500.0) return; //3. 방향 확인 this.displayFPS.Content = swipeGesture.Direction;//y < 0 ? "Swipe to left" : "Swipe to right"; Console.WriteLine(swipeGesture.Direction.y < 0 ? "Swipe to left" : "Swipe to right"); break; default: this.displayGestureCount.Content = " ";//this.displayImageCount.Content = 0; break; } } // } Finger finger = frame.Fingers[0]; // Get the closest screen intercepting a ray projecting from the finger Screen screen = controller.LocatedScreens.ClosestScreenHit(finger); if (screen != null && screen.IsValid) { // Get the velocity of the finger tip var tipVelocity = (int)finger.TipVelocity.Magnitude; // Use tipVelocity to reduce jitters when attempting to hold // the cursor steady if (tipVelocity > 25) { var xScreenIntersect = screen.Intersect(finger, true).x; var yScreenIntersect = screen.Intersect(finger, true).y; if (xScreenIntersect.ToString() != "NaN") { var x = (int)(xScreenIntersect * screen.WidthPixels); var y = (int)(screen.HeightPixels - (yScreenIntersect * screen.HeightPixels)); /* Console.WriteLine("Screen intersect X: " + xScreenIntersect.ToString()); Console.WriteLine("Screen intersect Y: " + yScreenIntersect.ToString()); Console.WriteLine("Width pixels: " + screen.WidthPixels.ToString()); Console.WriteLine("Height pixels: " + screen.HeightPixels.ToString()); Console.WriteLine("\n"); Console.WriteLine("x: " + x.ToString()); Console.WriteLine("y: " + y.ToString()); Console.WriteLine("\n"); Console.WriteLine("Tip velocity: " + tipVelocity.ToString()); // Move the cursor //MouseCursor.MoveCursor(x, y); Console.WriteLine("\n" + new String('=', 40) + "\n");*/ if (rot_on == 1) { this.displayGestureCount.Content = "x,y 좌표는 : " + x.ToString() + "," + y.ToString(); } } } } //this.displayID.Content = frame.Id.ToString(); //this.displayTimestamp.Content = frame.Timestamp.ToString(); //this.displayFPS.Content = frame.CurrentFramesPerSecond.ToString(); //this.displayIsValid.Content = frame.IsValid.ToString(); // this.displayGestureCount.Content = frame.Gestures().Count.ToString(); //this.displayImageCount.Content = frame.Images.Count.ToString(); } } previousTime = currentTime; } }
void newFrameHandler(Leap.Frame frame) { this.lblID.Content = "ID: " + frame.Id.ToString(); this.lblTimestamp.Content = "Timestamp: " + frame.Timestamp.ToString(); this.lblFPS.Content = "FPS: " + frame.CurrentFramesPerSecond.ToString(); this.lblIsValid.Content = "IsFrameValid: " + frame.IsValid.ToString(); this.lblGestureCount.Content = "Gesture Count: " + frame.Gestures().Count.ToString(); this.lblImageCount.Content = "Image Count: " + frame.Images.Count.ToString(); if (recordMode) { //write the recived frame to file writeFrameToFile(frame); //stimcode read from global //process image data from the frame Leap.Image image = frame.Images[0]; if (image.Width != 0 && image.Height != 0) { Bitmap bitmap = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); //set palette ColorPalette grayscale = bitmap.Palette; for (int i = 0; i < 256; i++) { grayscale.Entries[i] = System.Drawing.Color.FromArgb((int)255, i, i, i); } bitmap.Palette = grayscale; Rectangle lockArea = new Rectangle(0, 0, bitmap.Width, bitmap.Height); BitmapData bitmapData = bitmap.LockBits(lockArea, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); byte[] rawImageData = image.Data; System.Runtime.InteropServices.Marshal.Copy(rawImageData, 0, bitmapData.Scan0, image.Width * image.Height); bitmap.UnlockBits(bitmapData); imgFrame.Source = ConvertBitmap.BitmapToBitmapSource(bitmap); } } }
void newFrameHandler(Leap.Frame frame) { currentTime = frame.Timestamp; timeChange = currentTime - previousTime; HandList hands = frame.Hands; Hand firstHand = hands[0]; Hand secondHand = hands[1]; if (timeChange > 100000) { if (hands[0].IsValid) { if (hands[1].IsValid) { //Console.WriteLine(hands[1].PinchStrength); }else{ // Console.WriteLine("only 0"); } } var handVelocity = (int)firstHand.PalmVelocity.Magnitude; if (handVelocity > 10000)//1500 { Console.WriteLine(handVelocity); this.displayImageCount.Content = "손빠르기"; } else { for (int g = 0; g < frame.Gestures().Count; g++) { switch (frame.Gestures()[g].Type) { case Gesture.GestureType.TYPE_CIRCLE: CircleGesture cir = new CircleGesture(frame.Gesture(g)); //this.displayImageCount.Content = frame.Gesture(g).ToString() + "의 지름은 " + cir.Radius + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State; this.displayImageCount.Content = "원" +frame.Gesture(g).ToString() + "의 지름은 " + cir.Radius + "그리고 상태는 " + frame.Gesture(g).State; break; case Gesture.GestureType.TYPE_KEY_TAP: //Handle key tap gestures KeyTapGesture keytapGesture = new KeyTapGesture(frame.Gesture(g)); this.displayImageCount.Content = "키탭"; Console.WriteLine(frame.Gesture(g).ToString() + "의 방향은 " + keytapGesture.Direction + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State); Console.WriteLine(frame.Gesture(g).ToString() + "의 포인터은 " + keytapGesture.Pointable + "그리고" + keytapGesture.Position); break; case Gesture.GestureType.TYPE_SCREEN_TAP: //Handle screen tap gestures this.displayImageCount.Content = "스크린탭"; ScreenTapGesture screentapGesture = new ScreenTapGesture(frame.Gesture(g)); Console.WriteLine(screentapGesture.Direction); break; case Gesture.GestureType.TYPE_SWIPE: this.displayImageCount.Content = "쓸기"; break; default: //this.displayImageCount.Content = 0; break; } } this.displayID.Content = frame.Id.ToString(); this.displayTimestamp.Content = frame.Timestamp.ToString(); this.displayFPS.Content = frame.CurrentFramesPerSecond.ToString(); this.displayIsValid.Content = frame.IsValid.ToString(); this.displayGestureCount.Content = frame.Gestures().Count.ToString(); //this.displayImageCount.Content = frame.Images.Count.ToString(); } previousTime = currentTime; } }
public void checkGestures(Leap.Frame frame) { //create a gesture list GestureList gestures = frame.Gestures(); //access every getures that is detected foreach (Gesture gesture in gestures) { // Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: CircleGesture circle = new CircleGesture(gesture); // Calculate clock direction using the angle between circle normal and pointable String clockwiseness; if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2) { //Clockwise if angle is less than 90 degrees clockwiseness = "clockwise"; } else { clockwiseness = "counterclockwise"; } float sweptAngle = 0; // Calculate angle swept since last frame if (circle.State != Gesture.GestureState.STATE_START) { CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id)); sweptAngle = (circle.Progress - previousUpdate.Progress) * 360; } //fill things into labels: id, state, progress, radius, angle circleLB.Content = " Circle id: " + circle.Id + ", " + circle.State + ", progress: " + circle.Progress + ", radius: " + circle.Radius + ", angle: " + sweptAngle + ", " + clockwiseness; Debug.WriteLine(" Circle id: " + circle.Id + ", " + circle.State + ", progress: " + circle.Progress + ", radius: " + circle.Radius + ", angle: " + sweptAngle + ", " + clockwiseness); break; case Gesture.GestureType.TYPE_SWIPE: SwipeGesture swipe = new SwipeGesture(gesture); swipeLB.Content = " Swipe id: " + swipe.Id + ", " + swipe.State + ", position: " + swipe.Position + ", direction: " + swipe.Direction + ", speed: " + swipe.Speed; Debug.WriteLine(" Swipe id: " + swipe.Id + ", " + swipe.State + ", position: " + swipe.Position + ", direction: " + swipe.Direction + ", speed: " + swipe.Speed); break; case Gesture.GestureType.TYPE_KEY_TAP: KeyTapGesture keytap = new KeyTapGesture(gesture); keyTapLB.Content = " Tap id: " + keytap.Id + ", " + keytap.State + ", position: " + keytap.Position + ", direction: " + keytap.Direction; Debug.WriteLine(" Tap id: " + keytap.Id + ", " + keytap.State + ", position: " + keytap.Position + ", direction: " + keytap.Direction); break; case Gesture.GestureType.TYPE_SCREEN_TAP: ScreenTapGesture screentap = new ScreenTapGesture(gesture); screenTapLB.Content = " Tap id: " + screentap.Id + ", " + screentap.State + ", position: " + screentap.Position + ", direction: " + screentap.Direction; Debug.WriteLine(" Tap id: " + screentap.Id + ", " + screentap.State + ", position: " + screentap.Position + ", direction: " + screentap.Direction); break; default: Debug.WriteLine(" Unknown gesture type."); break; } } }