2016年5月12日 星期四

02160740_莊鎧旭_Week12

打地鼠
安裝 Kinect sdk 以及 KinectDeveloperToolkit


2.執行Processing並將OpenNI放入...\processing2.2.1\modes\java\libraries
3.測試是否能執行
import SimpleOpenNI.*;
SimpleOpenNI show;
void setup()
{
   size(640,480);
   show=new SimpleOpenNI(this);
   show.enableRGB();
   show.enableDepth();
}
void draw()
{
   show.update();
    image(show.rgbImage(),0,0,320,240);
    image(show.depthImage(),0,240,320,240);

}

左手

import SimpleOpenNI.*; 
SimpleOpenNI show;
void setup()
{
  size(640, 480);
  show=new SimpleOpenNI(this);
  show.enableRGB();
  show.enableDepth(); 
  show.enableUser();
}
float xpos(PVector pos) 
{
  return width/2+pos.x*500/pos.z;
}
float ypos(PVector pos) 
{
  return height/2-pos.y*500/pos.z;
}
void draw()
{
  show.update();
  background(255);
  image(show.userImage(), 0, 0, 640, 480);
  int [] userlist=show.getUsers();
  PVector pos = new PVector(0, 0, 0);
  for (int userId : show.getUsers ()) 
  {
    show.getJointPositionSkeleton(userId,   SimpleOpenNI.SKEL_LEFT_HAND, pos);
  }
  ellipse(xpos(pos), ypos(pos), 50, 50); 
}
void onNewUser(SimpleOpenNI curContext, int userId) 
{
  curContext.startTrackingSkeleton(userId);
}


全身
import SimpleOpenNI.*;
SimpleOpenNI openni;
void setup(){
  size(600,400);
  openni = new SimpleOpenNI(this);
  openni.enableRGB();
  openni.enableDepth();
  openni.enableUser();
  imgBG = loadImage("bg.png");
}
PImage imgBG;
void draw(){
  openni.update();
  background(255);
  image(imgBG,0,0,640,480);
  image(openni.userImage(),0,0,64,48);
  int[]userList = openni.getUsers();
  PVector pos = new PVector(0,0,0), hand1 = new PVector(0,0,0), hand2 = new PVector(0,0,0);
  for(int userID : userList){
    openni.getJointPositionSkeleton(userID, SimpleOpenNI.SKEL_LEFT_HAND, pos);
    openni.convertRealWorldToProjective(pos, pos);
    fill(0,0,255);
    ellipse(pos.x, pos.y, 50, 50);
    hand1.set(pos);
    hand1.z=0;
    fill(0,0,255);
    ellipse(pos.x/10, pos.y/10, 5, 5);
    openni.getJointPositionSkeleton(userID, SimpleOpenNI.SKEL_RIGHT_HAND, pos);
    openni.convertRealWorldToProjective(pos, pos);
    fill(255,0,0);
    ellipse(pos.x/10, pos.y/10, 5, 5);
    fill(255,0,0);
    ellipse(pos.x, pos.y, 50, 50);
    hand2.set(pos);
    hand2.z=0;
    //openni.getJointPositionSkeleton(userID, SimpleOpenNI.SKEL_HEAD, pos);
    //openni.convertRealWorldToProjective(pos, pos);
    //fill(255,255,0);
    //ellipse(pos.x, pos.y, 50, 50);
  }
  PVector mouse1 = new PVector(mouseX, mouseY, 0);
  if(PVector.dist(mouse1, hand1)<100 || PVector.dist(mouse1, hand2)<100){
    ellipse(mouseX, mouseY, 200, 200);
    //fill(255,255,0);
  }
}
void onNewUser(SimpleOpenNI curContext,int userId){
  openni.startTrackingSkeleton(userId);
}

沒有留言:

張貼留言