'Kinect'에 해당되는 글 4건

  1. 2013.01.21 [kinect] Minority Report Photos 1
반응형

다음은 Kinect센서에서 가까운 포인트를 찾아서 그림을 이동 시키는 예제이다.


import SimpleOpenNI.*;

SimpleOpenNI kinect;


int closestValue;

int closestX;

int closestY;


float lastX;

float lastY;


// 이미지의 X,Y좌표를 위한 변수

float image1X;

float image1Y;


// 이미지가 움직이는지 확인하는 변수

boolean imageMoving;

// 프로세싱에서 이미지를 처리하기 위한 변수 

PImage image1;


void setup()

{

size(640, 480);

kinect = new SimpleOpenNI(this);

kinect.enableDepth();

//초기에는 이미지가 움직이도록 설정

imageMoving = true;

//이미지를 PImage에 로드한다.

image1 = loadImage("image1.jpg");

background(0);

}

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;

int i = reversedX + y * 640;

int currentDepthValue = depthValues[i];

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

{

closestValue = currentDepthValue;

closestX = x;

closestY = y;

}

}

}

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

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

// 기존에 그렸던 것들을 지움

background(0);

if(imageMoving){

// 이미지의 위치를 변경함

image1X = interpolatedX;

image1Y = interpolatedY;

}

//화면에 이미지를 출력한다.

image(image1,image1X,image1Y);

lastX = interpolatedX;

lastY = interpolatedY;

}

void mousePressed(){

//마우스를 클릭하면 imageMoving값을 변경한다.

imageMoving = !imageMoving;

}


다음은 실행 화면이다.



반응형
Posted by alias
,