'openni'에 해당되는 글 4건

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

다음은 3장의 그림을 손으로 이동하거나 확대할 수 있는 예제이다.


SimpleOpenNI.*;

SimpleOpenNI kinect;


int closestValue;

int closestX;

int closestY;


float lastX;

float lastY;

float image1X;

float image1Y;

//이미지 크기 변환

float image1scale;

int image1width = 100;

int image1height = 100;


float image2X;

float image2Y;

float image2scale;

int image2width = 100;

int image2height = 100;


float image3X;

float image3Y;

float image3scale;

int image3width = 100;

int image3height = 100;


// 현재 어떤 이미지가 대상인지를 체크함

int currentImage = 1;

// 이미지를 옮기기 위한 프로세싱 이미지 선언

PImage image1;

PImage image2;

PImage image3;


void setup()

{

size(640, 480);

kinect = new SimpleOpenNI(this);

kinect.enableDepth();

image1 = loadImage("image1.jpg");

image2 = loadImage("image2.jpg");

image3 = loadImage("image3.jpg");

}

void draw(){

background(0);

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);

// 이미지를 선택하고

switch(currentImage){

case 1:

image1X = interpolatedX;

image1Y = interpolatedY;

// Scale 할 사이즈를 지정한다. 

// 610-1525 사이의 거리를 가지고 0.4 스케일로 이미지 사이즈를 변경한다.

image1scale = map(closestValue, 610,1525, 0,4);

break;

case 2:

image2X = interpolatedX;

image2Y = interpolatedY;

image2scale = map(closestValue, 610,1525, 0,4);

break;

case 3:

image3X = interpolatedX;

image3Y = interpolatedY;

image3scale = map(closestValue, 610,1525, 0,4);

break;

}

image(image1,image1X,image1Y,image1width * image1scale, image1height * image1scale);

image(image2,image2X,image2Y,image2width * image2scale, image2height * image2scale);

image(image3,image3X,image3Y,image3width * image3scale, image3height * image3scale);

lastX = interpolatedX;

lastY = interpolatedY;

}

void mousePressed(){

currentImage++;

if(currentImage > 3){

currentImage = 1;

}

println(currentImage);

}




반응형
Posted by alias
,