Processing 基于depthMap生成的二值图像的OpenNi Blob跟踪

Processing 基于depthMap生成的二值图像的OpenNi Blob跟踪,processing,openni,Processing,Openni,我正试图从OpenNI中的depthMap()函数生成一个二进制图像,该函数提供int类型的数组。我想用该图像进行blob跟踪。 问题是我无法从深度贴图生成清晰的二值图像。据我所知,深度图像为离传感器越近的所有物体生成一个明亮的像素,距离传感器越远,像素越暗。因此,我询问(一维)数组中的每个像素是否超过我的最小值,是否低于我的最大值阈值,以弥补我希望获得数据的范围。 这是我的密码: // import library import SimpleOpenNI.*; import processi

我正试图从OpenNI中的depthMap()函数生成一个二进制图像,该函数提供int类型的数组。我想用该图像进行blob跟踪。 问题是我无法从深度贴图生成清晰的二值图像。据我所知,深度图像为离传感器越近的所有物体生成一个明亮的像素,距离传感器越远,像素越暗。因此,我询问(一维)数组中的每个像素是否超过我的最小值,是否低于我的最大值阈值,以弥补我希望获得数据的范围。 这是我的密码:

 // import library
import SimpleOpenNI.*;
import processing.opengl.*; // opengl
import blobDetection.*; // blobs

// declare SimpleOpenNI object
SimpleOpenNI context;
BlobDetection theBlobDetection;
BlobBall blobBalls;
PrintWriter output;

// threshold for binaryImage
int minThreshold, maxThreshold;
// Size of the kinect Image
int kinectWidth = 640;
int kinectHeight = 480;
//
float globalX, globalY;
// Colors
color bgColor = color(0, 0, 123);
color white = color(255,255,255);
color black = color(0,0,0);

// PImage to hold incoming imagery
int[] distanceArray;
PImage cam, forBlobDetect;

void setup() {
  output = createWriter("positions.txt");
  // init threshold
  minThreshold = 960;
  maxThreshold = 2500;
  // same as Kinect dimensions
  size(kinectWidth, kinectHeight);
  background(bgColor);
  // initialize SimpleOpenNI object
  context = new SimpleOpenNI(this);
  if (context.isInit() == false) {
    println("Can't init SimpleOpenNI, maybe the camera is not connected!"); 
    exit();
  } 
  else {
    // mirror the image to be more intuitive
    context.setMirror(true);
    context.enableDepth();
    // context.enableScene();
    distanceArray = context.depthMap();
    forBlobDetect = new PImage(width, height);
    theBlobDetection = new BlobDetection(forBlobDetect.width, forBlobDetect.height);
    theBlobDetection.setThreshold(0.2);
  }
}

void draw() {
  noStroke();
  // update the SimpleOpenNI object
  context.update();
  // put the image into a PImage
  cam = context.depthImage();
  // copy the image into the smaller blob image
  // forBlobDetect.copy(cam, 0, 0, cam.width, cam.height, 0, 0, forBlobDetect.width, forBlobDetect.height);
  // blur the blob image
  forBlobDetect.filter(BLUR, 2);
  //
  int pos = 0;
  int currentDepthValue = 0;
  distanceArray = context.depthMap();
  for(int x = 0; x < cam.width; x++) {
    for(int y = 0; y < cam.height; y++) {
      pos = y*cam.width+x;
      currentDepthValue = distanceArray[pos];
//      println(currentDepthValue);
      if((currentDepthValue > minThreshold) && (currentDepthValue < maxThreshold)) {
        forBlobDetect.pixels[pos] = black; 
      } else {
        forBlobDetect.pixels[pos] = white;
      }
    }
  }
//  for(int i=0; i < distanceArray.length; i++) {
//    currentDepthValue = distanceArray[i];
//    // println(currentDepthValue);
//    if(currentDepthValue > minThreshold) /*&& (currentDepthValue < maxThreshold)*/) {
//      forBlobDetect.pixels[pos] = white;
//    } else {
//      forBlobDetect.pixels[pos] = black;
//    }
//  }
  // detect the blobs
  theBlobDetection.computeBlobs(forBlobDetect.pixels); 
  // display the image
  image(cam, 0, 0);
  image(forBlobDetect, 0, 0, width/2, height/2);

  // image(context.sceneImage(), context.depthWidth(), 0);
}
//导入库
导入SimplePenni。*;
导入处理。opengl。*;//opengl
导入Blob检测。*;//斑点
//声明SimplePenni对象
simplepenni语境;
blob检测blob检测;
水滴水滴;
打印机输出;
//二值图像的阈值
int minThreshold,maxThreshold;
//kinect图像的大小
int kinectWidth=640;
int kinectHeight=480;
//
浮动globalX,globalY;
//颜色
颜色bgColor=color(0,0,123);
颜色白色=颜色(255255);
颜色黑色=颜色(0,0,0);
//保存传入图像的图像
int[]距离数组;
PImage凸轮,forBlobDetect;
无效设置(){
输出=createWriter(“positions.txt”);
//初始阈值
minThreshold=960;
最大阈值=2500;
//与Kinect尺寸相同
尺寸(kinectWidth、kinectHeight);
背景色;
//初始化SimplePenni对象
上下文=新的SimplePenni(此);
if(context.isInit()==false){
println(“无法初始化SimplePenni,可能相机未连接!”);
退出();
} 
否则{
//镜像图像以使其更直观
context.setMirror(true);
enableDepth();
//enableSecene();
distanceArray=context.depthMap();
forBlobDetect=新的图像(宽度、高度);
theBlobDetection=新的BlobDetection(forBlobDetect.width,forBlobDetect.height);
BlobDetection.setThreshold(0.2);
}
}
作废提款(){
仰泳();
//更新SimplePenni对象
update();
//将图像放入图像中
cam=context.depthImage();
//将图像复制到较小的blob图像中
//FORBLOBDECT.copy(cam,0,0,cam.WITH,cam.height,0,0,FORBLOBDECT.WITH,FORBLOBDECT.height);
//模糊斑点图像
forBlobDetect.filter(模糊,2);
//
int pos=0;
int currentDepthValue=0;
distanceArray=context.depthMap();
对于(int x=0;xminThreshold)&&(currentDepthValueminThreshold)/*&&(currentDepthValue
我自己犯了一个非常愚蠢的错误,因为我误解了11位数组。 多亏了“让事情看清楚”的例子,我解决了这个问题。

我还不能给出答案的主要问题是如何处理11位整数数组,将深度信息转换为二进制图像。现在我将尝试灰度深度图像值