I was interested with converting body gesture to another type of expression. Kinect is one of the best apparatus to capture the motion of body. Using one of KinectV2 libraries, I create body painting program.
) has "Skeleton 3D" example which present each reference points of joints in a body. I selected two of joints, right and left hand, this two selected "Joints" draw circles on a screen. The Skeleton 3D program offers x,y,z coordinate on the virtual space, I stored only x,y reference points, using these the program draw multiple circles on a background.
Major problem was that I couldn't fix was make the linear arrangement of circles as a single curved line. The current solution is draw circles in every frame, but if the user moves their hands fast, we can see the gap or empty space between the two. Instead of draw individual circle, I'll try to line function to make the motion is actually creating a "Drawing".
I borrowed two code from different places.
I attached source code below, but I used Windows that requires Kinect SDK. It won't work on Mac OS.
Code: Select all
/*
MAT 265 class project No.1 20160403
This code is the modified version from one of examples in Thomas Sanchez Lengeling's KniectPV2 Library
and amnon.owed's answer (https://forum.processing.org/one/topic/eraser.html)
Copyright (C) 2014 Thomas Sanchez Lengeling.
KinectPV2, Kinect for Windows v2 library for processing
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
https://forum.processing.org/one/topic/eraser.html
*/
import KinectPV2.KJoint;
import KinectPV2.*;
PGraphics canvas;
KinectPV2 kinect;
Skeleton [] skeleton;
float storeX;
float storeY;
float zVal = 400;
float rotX = PI;
void setup() {
size(1024, 768, P3D);
kinect = new KinectPV2(this);
kinect.enableColorImg(true);
kinect.enableSkeleton(true );
//enable 3d Skeleton with (x,y,z) position
kinect.enableSkeleton3dMap(true);
kinect.init();
smooth();
canvas = createGraphics(width,height,P3D);
canvas.beginDraw();
canvas.smooth();
canvas.endDraw();
}
void draw() {
background(255);
image(kinect.getColorImage(), 0, 0, 320, 240);
skeleton = kinect.getSkeleton3d();
//translate the scene to the center
pushMatrix();
translate(width/2, height/2, 0);
scale(zVal);
rotateX(rotX);
for (int i = 0; i < skeleton.length; i++) {
if (skeleton[i].isTracked()) {
KJoint[] joints = skeleton[i].getJoints();
//draw different color for each hand state
drawHandState(joints[KinectPV2.JointType_HandRight]);
//drawHandState(joints[KinectPV2.JointType_HandLeft]);
}
}
popMatrix();
fill(255, 0, 0);
text(frameRate, 50, 50);
drawFunction();
image(canvas,0,0);
//println(storeX,storeY);
//saveFrame("frames/####.png");
}
void drawFunction() {
canvas.beginDraw();
canvas.noStroke();
canvas.fill(255,0,0);
//canvas.ellipse(mouseX, mouseY,50,50);
canvas.ellipse(storeX*zVal+width/2, -storeY*zVal+height/2,20,20);
canvas.endDraw();
}
//use different color for each skeleton tracked
color getIndexColor(int index) {
color col = color(255);
if (index == 0)
col = color(255, 0, 0);
if (index == 1)
col = color(0, 255, 0);
if (index == 2)
col = color(0, 0, 255);
if (index == 3)
col = color(255, 255, 0);
if (index == 4)
col = color(0, 255, 255);
if (index == 5)
col = color(255, 0, 255);
return col;
}
void drawJoint(KJoint[] joints, int jointType) {
strokeWeight(2.0f + joints[jointType].getZ()*8);
point(joints[jointType].getX(), joints[jointType].getY(), joints[jointType].getZ());
}
void drawBone(KJoint[] joints, int jointType1, int jointType2) {
strokeWeight(2.0f + joints[jointType1].getZ()*8);
point(joints[jointType2].getX(), joints[jointType2].getY(), joints[jointType2].getZ());
}
void drawHandState(KJoint joint) {
handState(joint.getState());
strokeWeight(5.0f + joint.getZ()*8);
point(joint.getX(), joint.getY(), joint.getZ());
storeX = joint.getX();
storeY = joint.getY();
//println(joint.getX(), joint.getY());
}
void drawBody(KJoint[] joints) {
drawBone(joints, KinectPV2.JointType_Head, KinectPV2.JointType_Neck);
drawBone(joints, KinectPV2.JointType_Neck, KinectPV2.JointType_SpineShoulder);
drawBone(joints, KinectPV2.JointType_SpineShoulder, KinectPV2.JointType_SpineMid);
drawBone(joints, KinectPV2.JointType_SpineMid, KinectPV2.JointType_SpineBase);
drawBone(joints, KinectPV2.JointType_SpineShoulder, KinectPV2.JointType_ShoulderRight);
drawBone(joints, KinectPV2.JointType_SpineShoulder, KinectPV2.JointType_ShoulderLeft);
drawBone(joints, KinectPV2.JointType_SpineBase, KinectPV2.JointType_HipRight);
drawBone(joints, KinectPV2.JointType_SpineBase, KinectPV2.JointType_HipLeft);
// Right Arm
drawBone(joints, KinectPV2.JointType_ShoulderRight, KinectPV2.JointType_ElbowRight);
drawBone(joints, KinectPV2.JointType_ElbowRight, KinectPV2.JointType_WristRight);
drawBone(joints, KinectPV2.JointType_WristRight, KinectPV2.JointType_HandRight);
drawBone(joints, KinectPV2.JointType_HandRight, KinectPV2.JointType_HandTipRight);
drawBone(joints, KinectPV2.JointType_WristRight, KinectPV2.JointType_ThumbRight);
// Left Arm
drawBone(joints, KinectPV2.JointType_ShoulderLeft, KinectPV2.JointType_ElbowLeft);
drawBone(joints, KinectPV2.JointType_ElbowLeft, KinectPV2.JointType_WristLeft);
drawBone(joints, KinectPV2.JointType_WristLeft, KinectPV2.JointType_HandLeft);
drawBone(joints, KinectPV2.JointType_HandLeft, KinectPV2.JointType_HandTipLeft);
drawBone(joints, KinectPV2.JointType_WristLeft, KinectPV2.JointType_ThumbLeft);
// Right Leg
drawBone(joints, KinectPV2.JointType_HipRight, KinectPV2.JointType_KneeRight);
drawBone(joints, KinectPV2.JointType_KneeRight, KinectPV2.JointType_AnkleRight);
drawBone(joints, KinectPV2.JointType_AnkleRight, KinectPV2.JointType_FootRight);
// Left Leg
drawBone(joints, KinectPV2.JointType_HipLeft, KinectPV2.JointType_KneeLeft);
drawBone(joints, KinectPV2.JointType_KneeLeft, KinectPV2.JointType_AnkleLeft);
drawBone(joints, KinectPV2.JointType_AnkleLeft, KinectPV2.JointType_FootLeft);
drawJoint(joints, KinectPV2.JointType_HandTipLeft);
drawJoint(joints, KinectPV2.JointType_HandTipRight);
drawJoint(joints, KinectPV2.JointType_FootLeft);
drawJoint(joints, KinectPV2.JointType_FootRight);
drawJoint(joints, KinectPV2.JointType_ThumbLeft);
drawJoint(joints, KinectPV2.JointType_ThumbRight);
drawJoint(joints, KinectPV2.JointType_Head);
}
void handState(int handState) {
switch(handState) {
case KinectPV2.HandState_Open:
stroke(0, 255, 0);
break;
case KinectPV2.HandState_Closed:
stroke(255, 0, 0);
break;
case KinectPV2.HandState_Lasso:
stroke(0, 0, 255);
break;
case KinectPV2.HandState_NotTracked:
stroke(100, 100, 100);
break;
}
}