首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在处理-不推荐使用OpenKinect库

正在处理-不推荐使用OpenKinect库
EN

Stack Overflow用户
提问于 2015-10-30 10:03:17
回答 1查看 259关注 0票数 1

我正在尝试为this music video的Kinect复制一个项目,但是代码已经严重过时了。

经过几周的搜索,我没有找到任何关于这方面的东西。

我将非常感谢向我指出以下代码中不推荐使用的内容的任何人:

(我使用的是Processing 3)

代码语言:javascript
复制
import org.openkinect.*;
import org.openkinect.processing.*;

import java.io.*;

// Kinect Library object
Kinect kinect;

float a = 0;

// Size of kinect image
int w = 640;
int h = 480;

// writing state indicator
boolean write = false;

// treshold filter initial value
int fltValue = 950;


// "recording" object. each vector element holds a coordinate map vector
Vector <Object> recording = new Vector<Object>(); 


// We'll use a lookup table so that we don't have to repeat the math over and     over
float[] depthLookUp = new float[2048];

 void setup() {
 size(800,600,P3D);
 kinect = new Kinect(this);
 kinect.start();
 kinect.enableDepth(true);
 // We don't need the grayscale image in this example
 // so this makes it more efficient
 kinect.processDepthImage(false);

 // Lookup table for all possible depth values (0 - 2047)
 for (int i = 0; i < depthLookUp.length; i++) {
  depthLookUp[i] = rawDepthToMeters(i);
 }

}

void draw() {

background(0);
fill(255);
textMode(SCREEN);
text("Kinect FR: " + (int)kinect.getDepthFPS() + "\nProcessing FR: " +   (int)frameRate,10,16);

// Get the raw depth as array of integers
int[] depth = kinect.getRawDepth();

// We're just going to calculate and draw every 4th pixel (equivalent of 160x120)
int skip = 4;

// Translate and rotate
translate(width/2,height/2,-50);
rotateY(a);

//noStroke();
 //lights();


int index = 0;


PVector[] frame = new PVector[19200];


for(int x=0; x<w; x+=skip) {
  for(int y=0; y<h; y+=skip) {
    int offset = x+y*w;

  // Convert kinect data to world xyz coordinate
  int rawDepth = depth[offset];

  boolean flt = true;
  PVector v = depthToWorld(x,y,rawDepth);
  if (flt && rawDepth > fltValue)
  {
    v = depthToWorld(x,y,2047);
  }

  frame[index] = v;

  index++;   

  stroke(map(rawDepth,0,2048,0,256));
  pushMatrix();
  // Scale up by 200
  float factor = 400;
  translate(v.x*factor,v.y*factor,factor-v.z*factor);
  //sphere(1);
  point(0,0);

  //line (0,0,1,1);
  popMatrix();
  }
 }

if (write == true) {
recording.add(frame);    

}


// Rotate
//a += 0.015f;
}

// These functions come from:http://graphics.stanford.edu/~mdfisher/Kinect.html
 float rawDepthToMeters(int depthValue) {
  if (depthValue < 2047) {
   return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
  }
 return 0.0f;
 }

 PVector depthToWorld(int x, int y, int depthValue) {

final double fx_d = 1.0 / 5.9421434211923247e+02;
final double fy_d = 1.0 / 5.9104053696870778e+02;
final double cx_d = 3.3930780975300314e+02;
final double cy_d = 2.4273913761751615e+02;

PVector result = new PVector();
double depth =  depthLookUp[depthValue];//rawDepthToMeters(depthValue);
result.x = (float)((x - cx_d) * depth * fx_d);
result.y = (float)((y - cy_d) * depth * fy_d);
result.z = (float)(depth);
return result;
}

void stop() {
kinect.quit();
super.stop();
}


int currentFile = 0;

void saveFile() {

}

void keyPressed() { // Press a key to save the data

if (key == '1')
{
fltValue += 50;
println("fltValue: " + fltValue);
}
else if (key == '2')
{
fltValue -= 50;
println("fltValue: " + fltValue);
}
else if (key=='4'){
if (write == true) {
    write = false;

    println( "recorded " + recording.size() + " frames.");

    // saveFile();

    // save    

  Enumeration e = recording.elements();

  println("Stopped Recording " + currentFile);
  int i = 0;
  while (e.hasMoreElements()) {

     // Create one directory
     boolean success = (new File("out"+currentFile)).mkdir(); 


    PrintWriter output = createWriter("out"+currentFile+"/frame" + i++ +".txt");
    PVector [] frame = (PVector []) e.nextElement();

    for (int j = 0; j < frame.length; j++) {
     output.println(j + ", " + frame[j].x + ", " + frame[j].y + ", " + frame[j].z );

    }
    output.flush(); // Write the remaining data
    output.close();
  }
  currentFile++;



  }
}
else if (key == '3') {
    println("Started Recording "+currentFile);
    recording.clear();

    write = true;
 }

}
EN

回答 1

Stack Overflow用户

发布于 2015-10-30 21:36:31

如果代码可以工作,那么我就不会太担心了。弃用可能只是意味着有新版本可用,而不是旧版本停止工作。

然而,如果代码不能工作,那么更新到一个较新的库可能是一个好主意。查看Processing主页的library部分,其中列出了几个Kinect库。

实际上,其中一个库就是您正在使用的旧库的更新版本:Open Kinect for Processing

编辑:看起来你提到的两个错误都是由于缺少import语句造成的。您需要同时导入VectorEnumeration才能使用它们:

代码语言:javascript
复制
import java.util.Vector;
import java.util.Enumeration;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33427636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档