Middleware :
authorbastiena
Tue, 20 Mar 2012 18:00:55 +0100
changeset 7 8a21bec5d45f
parent 6 93dfb08dcc97
child 8 e4e7db2435f8
Middleware : No proximity bugs anymore. The skeleton disappear if a tracked person is too close or not tracked anymore. Processing : There are no laggs anymore when an user stay too long moving his hands and drawing tons of ellipses. (TUIO Cursors are not taken by their vectors, only the last position of the cursors are caught to be drawn).
front_processing/doc/readme.txt
front_processing/src/Trakers/Trakers.pde
middleware/dist/TraKERS.iss
middleware/doc/readme.txt
middleware/src/Debug/DebugWindow.xaml
middleware/src/Debug/DebugWindow.xaml.cs
middleware/src/Tracking/KinectMain.cs
--- a/front_processing/doc/readme.txt	Mon Mar 19 18:24:59 2012 +0100
+++ b/front_processing/doc/readme.txt	Tue Mar 20 18:00:55 2012 +0100
@@ -6,8 +6,6 @@
 
 Dans cette partie, il vous faudra installer Processing, disponible ici : http://processing.org/download/
 
-Vous les trouverez ici si vous le souhaitez : http://www.microsoft.com/en-us/kinectforwindows/develop/release-notes.aspx
-
 II) TraKERS - Structure :
 
 Dans le Front, se trouvent deux exécutables "Trakers" et "Trakers_gestures", respectivement pour le tracé de courbes via les coordonnées des positions des mains récupérées du Middleware et pour l'affichage des gestes détectés. Il aurait été possible de les rassembler en un programme, mais pour des raisons de clarté lors de l'utilisation, j'ai préféré procéder ainsi.
--- a/front_processing/src/Trakers/Trakers.pde	Mon Mar 19 18:24:59 2012 +0100
+++ b/front_processing/src/Trakers/Trakers.pde	Tue Mar 20 18:00:55 2012 +0100
@@ -1,15 +1,21 @@
 import TUIO.*;
 TuioProcessing tuioClient;
+//Indique s'il s'agit de la main gauche.
 boolean oneHandLeft;
 
+//Port du Client TUIO
+int port = 80;
+float minDistHands = 1;
+float maxDistHands = 1.5;
+
 /*FONCTION D'INITIALISATION
 Entrée :
 Sortie : Création de la fenêtre et du client TUIO*/
-void setup()
+public void setup()
 {
     size (640, 480);
     showMask();
-    tuioClient = new TuioProcessing(this, 80);
+    tuioClient = new TuioProcessing(this, port);
     textAlign(CENTER);
     imageMode(CENTER);
     smooth();
@@ -18,7 +24,7 @@
 /*FONCTION DE DESSIN
 Entrée :
 Sortie : Appel à la fonction de traitement d'input du serveur toutes les n millisecondes*/
-void draw()
+public void draw()
 {
     fill(0);
     tuioInput();
@@ -28,62 +34,61 @@
 /*FONCTION DE RECEPTION DES MESSAGES OSC
 Entrée :
 Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/
-void tuioInput()
+public void tuioInput()
 {
     noFill();
-  
     Vector tuioCursorList = tuioClient.getTuioCursors();
-
+    
     if(tuioCursorList.size() <= 0)
     {
         showMask();
-        text("Les mains sont trop loin ou trop près.", width/2 - 20, 20);
-        text("Je ne détecte aucune main.", width/2 - 20, 40);
+        refreshText("Les mains sont trop loin ou trop près.", "Je ne détecte aucune main.");
     }
-        
+    		
     if(tuioCursorList.size() == 1)
     {
         handleOneHand((TuioCursor)tuioCursorList.elementAt(0));
         fill(255);
-        text("Les mains sont dans la zone de captation.", width/2 - 20, 20);
-        text("Je détecte une main.", width/2 - 20, 40);
+        refreshText("Les mains sont dans la zone de captation.", "Je détecte une main.");
     }
     else if(tuioCursorList.size() == 2)
     {
         handleBothHands(tuioCursorList);
         fill(255);
-        text("Les mains sont dans la zone de captation.", width/2 - 20, 20);
-        text("Je détecte les deux mains.", width/2 - 20, 40);
+        refreshText("Les mains sont dans la zone de captation.", "Je détecte les deux mains.");
     }
 }
 
 /*FONCTION DE GENERATION DU MASQUE
 Entrée :
 Sortie : Place des rectangles autour de la zone de dessin*/
-void showMask()
+public void showMask()
 {
     background(0);
     fill(255);
     rect(0, 80, width, height-130);
 }
+	
+/*FONCTION DE RAFFRACHISSEMENT DU TEXTE SUPERIEUR
+Entrée : Texte à afficher
+Sortie : Place un rectangle au dessus de la zone de dessin et raffraichit le texte*/
+public void refreshText(String txt1, String txt2)
+{
+    fill(0);
+    rect(0, 0, width, 80);
+    fill(255);
+    text(txt1, width/2 - 20, 20);
+    text(txt2, width/2 - 20, 40);
+}
 
 /*FONCTION DE GESTION DES COURBES POUR UNE MAIN DETECTEE
 Entrée : Un curseur TUIO
 Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/
-void handleOneHand(TuioCursor handCursor)
+public void handleOneHand(TuioCursor handCursor)
 {
-    showMask();
-
-    Vector pointList = handCursor.getPath();
-    for (int j=0;j<pointList.size();j++)
-    {
-        TuioPoint pt = (TuioPoint)pointList.get(j);
-        fill(0);
-        drawEllipse(pt.getX(), pt.getY(), pt.getZ(), !oneHandLeft);
-        
-        if(tuioClient.getTuioCursors().size() == 2)
-            break;
-    }
+    TuioPoint pt = handCursor.getPosition();//(TuioPoint)pointList.get(j);
+    fill(0);
+    drawEllipse(pt.getX(), pt.getY(), pt.getZ(), !oneHandLeft);
 }
 
 /*FONCTION DE GESTION DES COURBES POUR DEUX MAINS DETECTEES
@@ -91,37 +96,14 @@
 Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/
 void handleBothHands(Vector tuioCursorList)
 {
-    showMask();
-
     TuioCursor handLeftCursor = (TuioCursor)tuioCursorList.elementAt(0);
-    TuioCursor rightLeftCursor = (TuioCursor)tuioCursorList.elementAt(1);
-    Vector handLeftPointList = handLeftCursor.getPath();
-    Vector handRightPointList = rightLeftCursor.getPath();
+    TuioCursor handRightCursor = (TuioCursor)tuioCursorList.elementAt(1);
     TuioPoint pt;
-    
-    for(int j = 0, k = 0 ; j < handLeftPointList.size() || k < handRightPointList.size() ; j++, k++)
-    {
-        if(j < handLeftPointList.size())
-        {
-            pt = (TuioPoint)handLeftPointList.get(j);
-            drawEllipse(pt.getX(), pt.getY(), pt.getZ(), true);
-        }
-        if(k < handRightPointList.size())
-        {
-            pt = (TuioPoint)handRightPointList.get(k);
-            drawEllipse(pt.getX(), pt.getY(), pt.getZ(), false);
-        }
-        
-        if(tuioCursorList.size() == 1)
-        {
-            if(j == handLeftPointList.size())
-                oneHandLeft = false;
-            else if(k == handRightPointList.size())
-                oneHandLeft = true;
-            //fill(0, 255, 0);
-            break;
-        }
-    }
+
+    pt = (TuioPoint)handLeftCursor.getPosition();//handLeftPointList.get(j);
+    drawEllipse(pt.getX(), pt.getY(), pt.getZ(), true);
+    pt = (TuioPoint)handRightCursor.getPosition();//handRightPointList.get(k);
+    drawEllipse(pt.getX(), pt.getY(), pt.getZ(), false);
 }
 
 /*FONCTION DE DESSIN D'UN POINT DE COURBE
@@ -133,8 +115,8 @@
     fill(0, 0, 255);
     stroke(0,0,0);
 
-    float weight = map(z, 1, 1.5, 50, 1);
-    float redColor = map(z, 1, 1.5, 255, 80);
+    float weight = map(z, minDistHands, maxDistHands, 50, 1);
+    float redColor = map(z, minDistHands, maxDistHands, 255, 80);
     
     if(leftHand)
         fill(redColor,0,0);
--- a/middleware/dist/TraKERS.iss	Mon Mar 19 18:24:59 2012 +0100
+++ b/middleware/dist/TraKERS.iss	Tue Mar 20 18:00:55 2012 +0100
@@ -17,7 +17,7 @@
 DefaultDirName={pf}\{#MyAppName}
 DefaultGroupName={#MyAppName}
 AllowNoIcons=yes
-OutputBaseFilename=setup
+OutputBaseFilename=TraKERS_setup
 Compression=lzma
 SolidCompression=yes
 
@@ -35,4 +35,9 @@
 
 [Icons]
 Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
-
+Name: "{group}\{#MyAppName}\Middleware"; Filename: "{app}\Middleware\Trakers.exe"
+Name: "{group}\{#MyAppName}\Hand Pointing"; Filename: "{app}\Front Processing\Trakers\application.windows\Trakers.exe"
+Name: "{group}\{#MyAppName}\Gesture Recognition"; Filename: "{app}\Front Processing\Trakers_gestures\application.windows\Trakers_gestures.exe"
+Name: "{commondesktop}\TraKERS - Middleware"; Filename: "{app}\Middleware\Trakers.exe"
+Name: "{commondesktop}\TraKERS - Hand Pointing"; Filename: "{app}\Front Processing\Trakers\application.windows\Trakers.exe"
+Name: "{commondesktop}\TraKERS - Gesture Recognition"; Filename: "{app}\Front Processing\Trakers_gestures\application.windows\Trakers_gestures.exe"
--- a/middleware/doc/readme.txt	Mon Mar 19 18:24:59 2012 +0100
+++ b/middleware/doc/readme.txt	Tue Mar 20 18:00:55 2012 +0100
@@ -65,7 +65,7 @@
 	Lorsque ce geste est détecté, le bas de la fenêtre se colore en noir s'il s'agit d'un pull.
 	
 	En développement :
-		JUMP - Action de sauter à pieds vers le haut.
+		JUMP - Action de sauter vers le haut.
 
 IV) Mentions importantes pour le debug :
 
--- a/middleware/src/Debug/DebugWindow.xaml	Mon Mar 19 18:24:59 2012 +0100
+++ b/middleware/src/Debug/DebugWindow.xaml	Tue Mar 20 18:00:55 2012 +0100
@@ -6,11 +6,11 @@
 
 Auteur : alexandre.bastien@iri.centrepompidou.fr
 
-Fonctionnalités : Affiche le rendu visuel du Middleware : Le squelette, la détection/position des mains, 
-les exceptions et la distance de l'utilisateur.
+Fonctionnalités : Affiche le rendu visuel du Middleware : Le squelette, afficher la détection des mains,
+des gestures et la distance de l'utilisateur.
 -->
     
-<Window x:Class="Trakers.Debug.DebugWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="DebugWindow" Height="480" Width="640" Closed="Window_Closed">
+<Window x:Class="Trakers.Debug.DebugWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="DebugWindow" Height="480" Width="640" Closed="Window_Closed" Loaded="Window_Loaded">
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition />
@@ -56,7 +56,7 @@
         </Grid>
 
         <!-- Ce bouton permet d'allumer/éteindre la Kinect. -->
-        <Button Name="Switch" Content="ON"  Grid.Row="1" Grid.Column="0" Width="30" Click="Switch_Click" />
+        <Button Name="Switch" Content="OFF"  Grid.Row="1" Grid.Column="0" Width="30" Click="Switch_Click" />
 
         <!-- Ce panneau affiche la distance actuelle de l'utilisateur à la Kinect et indique une couleur pour chaque mètre. -->
         <!-- 0-1 m : Rouge. 1-2 : Orange. 2-3 : Jaune. 3-4 : Blanc. -->
--- a/middleware/src/Debug/DebugWindow.xaml.cs	Mon Mar 19 18:24:59 2012 +0100
+++ b/middleware/src/Debug/DebugWindow.xaml.cs	Tue Mar 20 18:00:55 2012 +0100
@@ -61,7 +61,7 @@
             rm = new ResourceManager("Trakers.Properties.resources", Assembly.GetExecutingAssembly());
             InitializeComponent();
             kinectMain = main;
-            on = false;
+            on = true;
             closing = false;
         }
 
@@ -141,9 +141,13 @@
                     colorPixelData = new byte[colorImageFrameData.PixelDataLength];
                 else
                 {
-                    //Sinon on met à jour le tableau en copiant le contenu de la trame dans le tableau.
-                    colorImageFrameData.CopyPixelDataTo(colorPixelData);
-                    receivedData = true;
+                    try
+                    {
+                        //Sinon on met à jour le tableau en copiant le contenu de la trame dans le tableau.
+                        colorImageFrameData.CopyPixelDataTo(colorPixelData);
+                        receivedData = true;
+                    }
+                    catch (Exception){}
                 }
             }
             //Si on a des données dans le tableau et que la kinect est allumée.
@@ -319,6 +323,12 @@
             drawBone(ankleRight, footRight);
         }
 
+        public void hideSkeleton()
+        {
+            if(DebugCanvas.Children.Count > 1)
+                DebugCanvas.Children.RemoveRange(1, DebugCanvas.Children.Count - 1);
+        }
+
         /*
         * Affiche la position de la main gauche dans le rendu visuel.
         */
@@ -398,5 +408,10 @@
             kinectMain.KinectClose();
             Application.Current.Shutdown();
         }
+
+        private void Window_Loaded(object sender, RoutedEventArgs e)
+        {
+            kinectMain.KinectInitialization();
+        }
     }
 }
--- a/middleware/src/Tracking/KinectMain.cs	Mon Mar 19 18:24:59 2012 +0100
+++ b/middleware/src/Tracking/KinectMain.cs	Tue Mar 20 18:00:55 2012 +0100
@@ -118,8 +118,6 @@
         {
             //On fait appel au gestionnaire de ressources.
             rm = new ResourceManager("Trakers.Properties.resources", Assembly.GetExecutingAssembly());
-            //On crée la fenêtre de debug.
-            debug = new Debug.DebugWindow(this);
             
             //On tente de charger les paramètres du fichier params.ini.
             //Si on n'y arrive pas, on affiche une erreur et on charge les paramètres par défaut.
@@ -137,6 +135,9 @@
                 timerElapsing = 1000;
             }
 
+            //On crée la fenêtre de debug.
+            debug = new Debug.DebugWindow(this);
+
             //On crée les détecteurs de gestes.
             swipeDetector = new SwipeDetector(debug);
             pushDetector = new PushDetector(debug);
@@ -395,7 +396,7 @@
                     RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(handRight, handRight.Position.Z, debug, server);
                     OnRightHandQuitEvent(rightHandQuitEvent);
                 }
-                
+
                 //Si l'utilisateur effectue un swipe left.
                 if (swipeDetector.CheckForSwipeLeft())
                 {
@@ -434,29 +435,9 @@
 
                 //Si l'utilisateur se déplace dans la zone de détection.
                 //On traite le problème en plusieurs limites, on discrétise la zone.
-                if(first.TrackingState == SkeletonTrackingState.Tracked)
+                if (first.TrackingState == SkeletonTrackingState.Tracked)
                 {
                     float proximity = userPositionDetector.CalcProximity(first.Position.Z);
-                    /*if (proximity > 0f && proximity < 25f)
-                    {
-                        Console.Out.WriteLine("1/4");
-
-                    }
-                    else if (proximity > 25f && proximity < 50f)
-                    {
-                        Console.Out.WriteLine("1/2");
-
-                    }
-                    else if (proximity > 50f && proximity < 75f)
-                    {
-                        Console.Out.WriteLine("3/4");
-
-                    }
-                    else if (proximity == 100f)
-                    {
-                        Console.Out.WriteLine("TRUE");
-
-                    }*/
 
                     if (proximity > 0f)
                     {
@@ -464,13 +445,18 @@
                         OnUserPositionEvent(userPositionEvent);
                     }
                     else
+                    {
                         Console.Out.WriteLine("FAIL");
+                        debug.hideSkeleton();
+                    }
                 }
 
                 //Dessine le squelette dans le debug.
                 debug.drawJoints(first.Joints, first);
                 debug.showSkeleton(hipCenter, spine, shoulderCenter, head, shoulderLeft, elbowLeft, wristLeft, handLeft, shoulderRight, elbowRight, wristRight, handRight, hipLeft, kneeLeft, ankleLeft, footLeft, hipRight, kneeRight, ankleRight, footRight);
             }
+            else
+                debug.hideSkeleton();
         }
 
         /*