Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

projektews2013:moperro:processingcode
import SimpleOpenNI.*;    //importiert fremdes Programm Simple...
 
import processing.serial.*;  //importiert Programm zum Senden von Werten aus dem Processing an Arduino
Serial myPort;  // Create object from Serial class
// The Number we will send to the Arduino
 
 
SimpleOpenNI  context; // zentrale Dings, wo die Kinect-Daten rauskommen
 
PVector com = new PVector(); // darin wird der Mittelpunkt eines Users gespeichert 
 
void setup ()
{
  size(640, 480);
 
  context = new SimpleOpenNI(this);   //startet Kinect
  if (context.isInit() == false)
  {
    println("Can't init SimpleOpenNI, maybe the camera is not connected!"); 
    exit();
    return;
  }
 
  // enable depthMap generation                           
  context.enableDepth();  
  // enable skeleton generation for all joints
  context.enableUser();
 
  background(200, 0, 0); // (rot, grün, blau)      AB HIER: 
  stroke(0, 0, 255);
  strokeWeight(3); //liniendicke
  smooth();          //FÜR BILDSCHRIMEINSTELLUNG
 
 
  String portName = Serial.list()[Serial.list().length-1];
  myPort = new Serial(this, portName, 9600); //open a connection with 115200Baud - this has to match the Baudrate in your Arduino sketch!
  frameRate(10);
}
 
void draw () 
{
  // update the cam
  context.update(); // holt die Daten aus von der Camera ein (immer wieder, denn ist in void draw)
 
  image(context.userImage(), 0, 0); //Wichtig! Bild malen
 
  // draw the skeleton if it's available
  int[] userList = context.getUsers();  // userList = array, das die ID's User enthält
  for (int i=0;i<userList.length;i++) // userList.length = Anzahl der User
  {
    if (userList.length>0 && context.isTrackingSkeleton(userList[0])) // wenn die userList mindestens eine User-ID enthält und Gelenkkordinaten für diesen user existieren
    {
      drawSkeleton(userList[0]); // Funktion!, färbt die Person ein
      context.getCoM(userList[0], com); // getCOM nimmt den ersten User als Parameter und gibt dessen Mittelpunkt im zweiten Parameter zurück
    }         
    if (com.x< 10000 && com.x>0.01) {   //falls die x-koordinate gößer als null und kleiner als 10000 ist
      myPort.write("xWert "+com.x+"\n"); //send a line containing the name and value separated by a space to the Serial.
 
      println(com.x, com.y, com.z); // druckt den x-,y-, und z-wert des Vektors von der Kinect zum CoM vom ersten user ; com = Vektor (siehe oben)!!!!
    }
  }
}
 
void onNewUser(SimpleOpenNI curContext, int userId)
{
  println("onNewUser - userId: " + userId);
  println("\tstart tracking skeleton");
 
  curContext.startTrackingSkeleton(userId);
}
 
void onLostUser(SimpleOpenNI curContext, int userId)
{
  println("onLostUser - userId: " + userId);
}
 
void onVisibleUser(SimpleOpenNI curContext, int userId)
{
  //println("onVisibleUser - userId: " + userId);
}
 
 
// draw the skeleton with the selected joints
void drawSkeleton(int userId)
{
  // to get the 3d joint data
  /*
  PVector jointPos = new PVector();
   context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_NECK,jointPos);
   println(jointPos);
   */
 
  context.drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);
 
  context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);
  context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);
  context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);
 
  context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);
  context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);
  context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);
 
  context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
  context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
 
  context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);
  context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);
  context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);
 
  context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);
  context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);
  context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT);
}
projektews2013/moperro/processingcode.txt · Zuletzt geändert: 2016/01/21 12:45 (Externe Bearbeitung)