【发布时间】:2016-06-21 10:17:43
【问题描述】:
我正在阅读 Greg Borenstein 的书“让事物看得见”,并想出了如何创建一个光标来跟踪最接近 Kinect 的事物的移动。现在光标是一个简单的红球。所以我可以追踪我的手指
image(kinect.getVideoImage(), 0, 0)
当我将光标球放在按钮区域时,我还创建了对视频图像应用过滤器的按钮。
它很有趣,但新颖性已经用完了,所以现在我想使用粒子或类似的东西将光标球变成动画图形。此动画图形仍应跟踪我的手指并绘制在视频图像上。
当我尝试编写此内容时,图形出现错误,因为视频图像不断重绘粒子,因此看起来不正确。
我在想我可以使用 capture() 方法在图形下绘制视频图像,但我不知道如何使用来自 Kinect 的视频来做到这一点。
有人对我如何做到这一点有任何想法吗?任何帮助将不胜感激。
下面是我的 kinect 跟踪器和过滤器按钮的示例。如果您将其复制并粘贴到处理中并插入 kinect,它应该会运行。我为代码缺乏雄辩而道歉。我还在学习如何编写漂亮的代码。
我想为红球触发一个新图形而不是过滤器,可能会应用粒子或其他东西。
//my kinect tracker
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
Kinect kinect;
boolean ir = true;
boolean colorDepth = true;
boolean mirror = true;
float closestValue;
float closestX;
float closestY;
// create arrays to store recent closest x- and y-coordinates for averaging
int[] recentXValues = new int[3];
int[] recentYValues = new int[3];
// keep track of which is the current value in the array to be changed
int currentIndex = 0;
float circleButtonX, circleButtonY; // position of circle button
float circleButtonSize; // diameter of circle button
color circleButtonColor; // color of circle button
void setup() {
size(640, 480, P3D);
kinect = new Kinect(this);
kinect.initDepth();
kinect.initVideo();
//kinect.enableIR(ir);
kinect.enableMirror(mirror);
kinect.enableColorDepth(colorDepth);
circleButtonColor = color(0, 0, 255);
}
void draw() {
closestValue = 1700;
int[] depthValues = kinect.getRawDepth();
for(int y = 0; y < 480; y++) {
for(int x = 0; x < 640; x++) {
int i = x + y * 640;
int currentDepthValue = depthValues[i];
if(currentDepthValue > 0 && currentDepthValue < closestValue) {
//save its value
closestValue = currentDepthValue;
recentXValues[currentIndex] = x;
recentYValues[currentIndex] = y;
}
}
}
currentIndex++;
if(currentIndex > 2) {
currentIndex = 0;
}
// closetX and ClosestY become a running average
// with currentX and CurrentY
closestX = (recentXValues[0] + recentXValues[1] + recentXValues[2]) / 3;
closestY = (recentYValues[0] + recentYValues[1] + recentYValues[2]) / 3;
//draw the depth image on the screen
image(kinect.getVideoImage(), 0, 0);
fill(0, 0, 250);
ellipse(75, 75, 100, 100);
ellipse(200, 75, 100, 100);
ellipse(75, 200, 100, 100);
rect(540, 25, 75, 100);
//buttons
fill(255,0,0);
textSize(24);
text("Invert", 40, 85);
text("Blur", 50, 210);
textSize(18);
text("Threshold", 155, 85);
text("Stop", 560, 75);
ellipse(closestX, closestY, 25, 25);
if (closestX > 25 && closestX < 125 && closestY > 25 && closestY < 125) {
filter(INVERT);
};
if (closestX > 150 && closestX < 250 && closestY > 25 && closestY < 125) {
filter(THRESHOLD);
};
if (closestX > 25 && closestX < 125 && closestY > 150 && closestY < 250) {
filter(BLUR, 6);
};
if (closestX > 540 && closestX < 615 && closestY > 25 && closestY < 100) {
noLoop();
loop();
background(0);
};
【问题讨论】:
标签: computer-vision processing kinect