'Kinect'에 해당되는 글 4건

  1. 2013.01.20 [kinect] Invisible Pencil
반응형

import SimpleOpenNI.*;

SimpleOpenNI kinect;


int closestValue;

int closestX;

int closestY;

float lastX;

float lastY;


void setup()

{

  size(640, 480);

  kinect = new SimpleOpenNI(this);

  kinect.enableDepth();

}

void draw()

{

  closestValue = 8000;

  kinect.update();

  int[] depthValues = kinect.depthMap();

  for(int y=0;y<480;y++){

    for(int x=0;x<640;x++){

      int reversedX=640-x-1;

 // Depth 이미지를 실제 화면에서 보여주려면 거울상으로 보여주어야 한다.

      int i=reversedX+y*640;

      int currentDepthValue=depthValues[i];

      if(currentDepthValue>610 && currentDepthValue<1525 && currentDepthValue < closestValue){

        //sensing range is from 2 to 5 feet away from kinect

        closestValue=currentDepthValue;

        closestX=x;

        closestY=y;

      }

    }

  }

  float interpolatedX=lerp(lastX,closestX,0.3f);

  //lerp는 linear interpolation 을 위한 프로세싱 함수이다.

  //좀더 부드럽게 움직이도록 만들어줌

  float interpolatedY=lerp(lastY,closestY,0.3f);

  stroke(255,0,0);

  strokeWeight(3);

  line(lastX,lastY,interpolatedX,interpolatedY);

  lastX=interpolatedX;

  lastY=interpolatedY;

}

void mousePressed(){   

  background(0);

}


다음은 손가락으로 움직여서 그려본 실행 화면 이다.


반응형
Posted by alias
,