2013年5月1日 星期三

99160522_沈奕均, HW10, Week10

本週目標:期中作品計畫書+改程式碼做小遊戲
一.安裝
(一定要下載32不然會慘)

開始過processing 1.5.1版後,SimpleOpenNI 資夾放在\文件\processing\libraries
(libraries不要拼錯喔!)
(接kinect的延長線記得開電源)

二.式寫最短的程式碼
import SimpleOpenNI.*;
SimpleOpenNI openni;
void setuup(){
openni= newSimpleOpenNI(this);
openni.enableRGB();
openni.enableDepth();
size(640+640,480);
}
void draw(){
openni.update();
image(openni.depthImage(),0,0);
image(openni.RGBImage(),640,0);
}

三.改寫範例hand3D

import SimpleOpenNI.*;
//import processing.opengl.*;

SimpleOpenNI context;
float        zoomF =0.5f;
float        rotX = radians(180);  // by default rotate the hole scene 180deg around the x-axis,
                                   // the data from openni comes upside down
float        rotY = radians(0);
boolean      handsTrackFlag = false;
PVector      handVec = new PVector();
ArrayList    handVecList = new ArrayList();
int          handVecListSize = 30;
String       lastGesture = "";

PImage imgB;
PImage imgF; 


void setup()
{
  imgB=loadImage("b.jpg");
  imgF=loadImage("f.png"); 



  size(1024,768,P3D);  // strange, get drawing error in the cameraFrustum if i use P3D, in opengl there is no problem
  //size(1024,768,OPENGL);

  context = new SimpleOpenNI(this);
  
  // disable mirror
  context.setMirror(false);

  // enable depthMap generation
  if(context.enableDepth() == false)
  {
     println("Can't open the depthMap, maybe the camera is not connected!");
     exit();
     return;
  }

  // enable hands + gesture generation
  context.enableGesture();
  context.enableHands();

  // add focus gestures  / here i do have some problems on the mac, i only recognize raiseHand ? Maybe cpu performance ?
  context.addGesture("Wave");
  context.addGesture("Click");
  context.addGesture("RaiseHand");

  // set how smooth the hand capturing should be
  //context.setSmoothingHands(.5);

  stroke(255,255,255);
  smooth();

  perspective(radians(45),
              float(width)/float(height),
              10.0f,150000.0f);
 }

void draw()
{
  // update the cam
  context.update();

  image(imgB,0,0,1024,768);
  image(imgF,1024/2-handVec.x,768/2-handVec.y); 
  return;

}
//以下相同
結果:



本週心得:
經過老師精心講解範例程式碼後,相信自己也是有能力可以改寫程式碼的!覺得很有成就感,會繼續努力,慢慢越改越多程式碼,本週最大收穫就是從重獲自信~耶

沒有留言:

張貼留言