2013-06-27 14 views
5

Pobrałem zestaw narzędzi Kinect SDK 1.7 i pobrałem następujące próbki.Kinect SDK 1.7 | Zmień obraz i rozmiar KinectCursor

  • ControlBasics WPF
  • InteractionGallery WPF.

Odkryłem, że narzędzie Kinect Toolkit wykorzystuje wewnętrznie ramkę interakcyjną do wykrywania pozycji/gestu ręki i odpowiednio odwzorowuje ją za pomocą kontrolek Kinect.

Mam wymóg, w którym chcę uchwycić zdarzenie związane z uchwytem na przycisku płytki Kinect. Ponieważ domyślny element KinectTileButton nie zapewnia zdarzenia Grip. Dodałem funkcję obsługi zdarzenia grip na moim przycisku.

KinectRegion.AddHandPointerGripHandler(kinectButton, OnHandPointerCaptured); 

private void OnHandPointerCaptured(object sender, HandPointerEventArgs handPointerEventArgs) 
{ 
    // Add code here 
} 

umieściłem przerwania debugowania wewnątrz metody OnHandPointerCaptured i był w stanie otrzymać odpowiednie ciosy, kiedy uchwyt na KinectTileButton. Ale z jakiegoś powodu nie widzę zmiany obrazu KinectCursor w uchwycie, jak to się dzieje w kontrolce KinectScrollViewer. Próbowałem ustawić właściwość isGripTarget w klasie KinectButtonBase, ale to nie pomaga.

private void InitializeKinectButtonBase() 
{ 
    KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress); 
    KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured); 
    KinectRegion.AddHandPointerPressReleaseHandler(this, this.OnHandPointerPressRelease); 
    KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture); 
    KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter); 
    KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave); 

    // Use the same OnHandPointerPress handler for the grip event 
    KinectRegion.AddHandPointerGripHandler(this, this.OnHandPointerPress); 

    //Set Kinect button as Grip target 
    // KinectRegion.SetIsPressTarget(this, true); 
    KinectRegion.SetIsGripTarget(this, true);     
} 

Jak zmienić obraz KinectCursor z ikony otwartej na uchwyt, a także rozmiar.

Odpowiedz

6

Oto co założe-

1) kursora i wielkość - Obie te próbki wykorzystać projekt Microsoft.Kinect.Toolkit.Controls definiujący Przetwarzania (KinectTileButton, KinectScrollViwer, KinectRegion itd.) Stosowanych w te próbki. Obraz i rozmiar Kinect Cursor jest zdefiniowany jako zasób w Microsoft.Kinect.Toolkit.Controls -> Themes-> Generic.xaml. Wyszukaj w pliku -

<Style TargetType="{x:Type local:KinectCursor}"> 

Możesz modyfikować to zgodnie ze swoimi potrzebami. Nie udało się znaleźć żadnych właściwości/haków narażonych na kontrolowanie tego bezpośrednio z interfejsu użytkownika.

2) Zdarzenie związane z uchwytem na przycisku kafelkowym - Przycisk Kinect Obsługuje różne zdarzenia, które można śledzić i działać zgodnie z Twoimi oczekiwaniami. zobaczyć ten Hand over button event in Kinect SDK 1.7

3) Zmiana kursora obrazu do przyczepność na Tile Buttona - projekt Microsoft.Kinect.Toolkit.Controls wykorzystuje KinectCursorVisualizer.cs i KinectCursor.cs do renderowania kursora wirtualną dłoń na UI. Stan wizualny "Otwarta dłoń/uchwyt" jest kontrolowany za pośrednictwem tej właściwości zależności zdefiniowanej w pliku KinectCursor.cs.

public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(
     "IsOpen", 
     typeof(bool), 
     typeof(KinectCursor), 
     new UIPropertyMetadata(true, (o, args) => ((KinectCursor)o).EnsureVisualState())); 

Szybkie znaleźć wszelkie odniesienia na posesji ISOpen mówi, że jedynym miejscem, gdzie ta właściwość jest ustawiona jest w KinectCursorVisualizer.cs-> OnHandPointersUpdated metody. Line- 229

// Set open state 
cursor.IsOpen = !pointer.IsInGripInteraction; 

I ta właściwość jest ustawiona na pointer.IsInGripInteraction KinectAdapter.cs Linia 678

handPointer.IsInGripInteraction = newIsInGripInteraction; 

Jeśli spojrzeć na kod tuż powyżej tej linii przekonasz się, że ta właściwość jest ustawiona na wartość true tylko wtedy, gdy element docelowy zawiera QueryInteractionStatusHandler zdefiniowany i ustawia args.Handled, args. Właściwość IsInGripInteraction na true.

Ponieważ funkcja KinectScrollViewer ma zdefiniowany ten program obsługi, zobaczysz obraz uchwytu.

private void InitializeKinectScrollViewer() 
     { 
      KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured); 
      KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture); 
      KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter); 
      KinectRegion.AddHandPointerMoveHandler(this, this.OnHandPointerMove); 
      KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress); 
      KinectRegion.AddHandPointerGripHandler(this, this.OnHandPointerGrip); 
      KinectRegion.AddHandPointerGripReleaseHandler(this, this.OnHandPointerGripRelease); 
//This is the QueryInteractionStatusHandler 
      KinectRegion.AddQueryInteractionStatusHandler(this, this.OnQueryInteractionStatus); 
      KinectRegion.SetIsGripTarget(this, true); 
      this.scrollMoveTimer.Tick += this.OnScrollMoveTimerTick; 
      this.scrollViewerInertiaScroller.SlowEnoughForSelectionChanged += this.OnSlowEnoughForSelectionChanged; 

      // Create KinectRegion binding 
      this.kinectRegionBinder = new KinectRegionBinder(this); 
      this.kinectRegionBinder.OnKinectRegionChanged += this.OnKinectRegionChanged;  
     } 

ale KinectTileButton (rozciąga KinectButtonBase) nie posiada uchwyt ten zdefiniowany

private void InitializeKinectButtonBase() 
     { 
      KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress); 
      KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured); 
      KinectRegion.AddHandPointerPressReleaseHandler(this, this.OnHandPointerPressRelease); 
      KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture); 
      KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter); 
      KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave); 

      KinectRegion.SetIsPressTarget(this, true); 

     } 

Jak zdefiniować tę obsługi? - Proste dodanie do swojego interfejsu użytkownika. Można dodać do konstruktora

//Add the handler 
KinectRegion.AddQueryInteractionStatusHandler(kinectButton, OnQuery); 

zdefiniować Handler

//Variable to track GripInterationStatus 
bool isGripinInteraction = false; 

     private void OnQuery(object sender, QueryInteractionStatusEventArgs handPointerEventArgs) 
     { 

      //If a grip detected change the cursor image to grip 
      if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.Grip) 
      { 
       isGripinInteraction = true; 
       handPointerEventArgs.IsInGripInteraction = true; 
      } 

      //If Grip Release detected change the cursor image to open 
      else if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.GripRelease) 
      { 
       isGripinInteraction = false; 
       handPointerEventArgs.IsInGripInteraction = false; 
      } 

      //If no change in state do not change the cursor 
      else if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.None) 
      { 
       handPointerEventArgs.IsInGripInteraction = isGripinInteraction; 
      } 

      handPointerEventArgs.Handled = true; 
     } 

Być może trzeba będzie dostosować to jak na swoje wymagania. Happy Kinecting :)

+0

Czy mogę po prostu podziękować tak bardzo za to. Uratowałeś mi wiele godzin i prawdopodobnie moje zdrowie psychiczne. Doszedłem do tego, że potrzebowałem KinectRegion.SetIsGripTarget(), ale nie mogłem wykonać następnego kroku. Jeszcze raz dziękuję, działa idealnie; Szkoda, że ​​nie mogłem przegłosować 1000 razy ... –

+0

Cieszę się, że to zadziałało. Dziękuję za miłe słowa :) – Gaurav

Powiązane problemy