Skip to content

Instantly share code, notes, and snippets.

@tatsuro-ueda
Created February 2, 2012 10:31
Show Gist options
  • Save tatsuro-ueda/1722806 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/1722806 to your computer and use it in GitHub Desktop.
KinectとProcessingでクロマキー
void draw()
{
// カメラ情報を更新する
context.update();
// sceneImageの人の部分を取り出すマスク用画像を作る
PImage maskImg = makeImgForMask(context.sceneImage());
PImage maskedImg = context.rgbImage(); // RGBカメラの映像がマスク対象
maskedImg.mask(maskImg); // 人物の形で繰り抜いて
PImage bg = loadImage("jiyu-no-megami.jpg");
background(bg);
image(maskedImg, 0, 0); // 表示する
}
background(0, 64, 0);
PImage bg = loadImage("jiyu-no-megami.jpg");
background(bg);
// 深度映像から人物だけを抜き出すようなマスク用画像を返す
PImage makeImgForMask(PImage img)
{
color cBlack = color(0, 0, 0);
color cWhite = color(255, 255, 255);
for (int x = 0; x < img.width; x++)
{
for (int y = 0; y < img.height; y++)
{
color c = img.get(x, y);
// 人が写っていない白、灰色、黒はRGB値が同じ
if (red(c) == green(c) & green(c) == blue(c))
{
img.set(x, y, cBlack); // 黒でマスクする
}
// 何らかの色が付いている部分は人が写っている
else
{
img.set(x, y, cWhite); // 白で人の部分を残す
}
}
}
return img;
}
import SimpleOpenNI.*;
SimpleOpenNI context;
void setup()
{
context = new SimpleOpenNI(this);
// 深度カメラを有効にする
if(context.enableDepth() == false)
{
println("Can't open the depthMap, maybe the camera is not connected!");
exit();
return;
}
// 人物検出を有効にする
context.enableScene();
// RGBカメラを有効にする
if(context.enableRGB() == false)
{
println("Can't open the rgbMap, maybe the camera is not connected or there is no rgbSensor!");
exit();
return;
}
// 画像データと深度データの位置合わせをする
context.alternativeViewPointDepthToImage();
// キャンバスの大きさ
size(context.depthWidth() , context.depthHeight());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment