Kinect – DECODE https://decode.red/blog data decode, decoder or decoded ... design of code Mon, 15 Dec 2025 06:15:00 +0000 ja hourly 1 https://wordpress.org/?v=4.7.29 Kinect Bone ../../../201907071009/ Sun, 07 Jul 2019 07:51:31 +0000 ../../../?p=1009 Microsoftのゲーム機XBOXをジェスチャー・音声認識で操作できるデバイスKinect for Xbox 360。
PCでも接続して利用できるためさまざまなライブラリが開発されました。発売当初(2010年)はいろいろと遊んだのですが、最近Processingで簡単に使えることを知り試してみました。

参考: https://kkblab.com/make/processing/kinect.html
環境: Processing 3.3.5 / Windows 10

import kinect4WinSDK.*; 

Kinect kn = new Kinect(this); 
SkeletonData user; 

void appearEvent(SkeletonData sd) {
    user = sd; 
    println("appear");
}
void disappearEvent(SkeletonData sd) {
    user = null; 
    println("disappear");
}

void setup() {
    size(640, 480); 
    user = new SkeletonData();
}     
void draw() {
    background(0); 
  
    if(user == null){
      return;
    }
    noStroke(); 
    fill(255, 255, 0); 
    ellipse(user.position.x * width, user.position.y * height,  30, 30);  
  
    PVector Head = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_HEAD];
    PVector Spine = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_SPINE];
    PVector C_Shoulder = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER];
    PVector R_Shoulder = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_SHOULDER_RIGHT];
    PVector L_Shoulder = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_SHOULDER_LEFT];
    PVector R_Elbow = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_ELBOW_RIGHT];
    PVector L_Elbow = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_ELBOW_LEFT];
    PVector R_Wrist = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_WRIST_RIGHT];
    PVector L_Wrist = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_WRIST_LEFT];
    PVector R_Hand = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_HAND_RIGHT];
    PVector L_Hand = user.skeletonPositions[Kinect.NUI_SKELETON_POSITION_HAND_LEFT];
    
    fill(0, 255, 0);
    ellipse(Head.x * width, Head.y * height, 30, 30);
    fill(255, 0, 0);
    ellipse(Spine.x * width, Spine.y * height, 10, 10);
    ellipse(C_Shoulder.x * width, C_Shoulder.y * height, 15, 15);
    ellipse(R_Shoulder.x * width, R_Shoulder.y * height, 10, 10);
    ellipse(L_Shoulder.x * width, L_Shoulder.y * height, 10, 10);
    ellipse(R_Elbow.x * width, R_Elbow.y * height, 15, 15);
    ellipse(L_Elbow.x * width, L_Elbow.y * height, 15, 15);
    ellipse(R_Wrist.x * width, R_Wrist.y * height, 10, 10);
    ellipse(L_Wrist.x * width, L_Wrist.y * height, 10, 10);
    ellipse(R_Hand.x * width, R_Hand.y * height, 15, 15);
    ellipse(L_Hand.x * width, L_Hand.y * height, 15, 15);

    stroke(0, 0, 255); 
    strokeWeight(4); 
    noFill(); 
    
    line(Head.x * width, Head.y * height, C_Shoulder.x * width, C_Shoulder.y * height);
    line(C_Shoulder.x * width, C_Shoulder.y * height, R_Shoulder.x * width, R_Shoulder.y * height);
    line(R_Shoulder.x * width, R_Shoulder.y * height, R_Elbow.x * width, R_Elbow.y * height);
    line(R_Elbow.x * width, R_Elbow.y * height, R_Wrist.x * width, R_Wrist.y * height);
    line(R_Wrist.x * width, R_Wrist.y * height, R_Hand.x * width, R_Hand.y * height);
    line(C_Shoulder.x * width, C_Shoulder.y * height, L_Shoulder.x * width, L_Shoulder.y * height);
    line(L_Shoulder.x * width, L_Shoulder.y * height, L_Elbow.x * width, L_Elbow.y * height);
    line(L_Elbow.x * width, L_Elbow.y * height, L_Wrist.x * width, L_Wrist.y * height);
    line(L_Wrist.x * width, L_Wrist.y * height, L_Hand.x * width, L_Hand.y * height);
    line(C_Shoulder.x * width, C_Shoulder.y * height, Spine.x * width, Spine.y * height); 
}

深度表示も魅力ですが、今回はリアルタイムのデータ入力をしたったので骨格を表示してみました。
(ここでは上半身のみ。パラメータをふやせば全身もできます。)

単純にこういうのは楽しいですね。なんか活用しないともったいない気がしてきました。
モノが古くなるとどんどん使えなくなるデバイスが多いなか、まだまだ使えそうなのはうれしいです。

https://ja.wikipedia.org/wiki/Kinect

]]>