【问题标题】:OpenNi Blob Tracking over binary image generated from depthMapOpenNi Blob 跟踪从 depthMap 生成的二进制图像
【发布时间】:2023-03-19 18:41:02
【问题描述】:

我正在尝试从 OpenNI 中的 depthMap() 函数生成二进制图像,该函数提供了一个 int 类型的数组。有了那个图像,我想做blob-Tracking。 问题是我无法从 depthMap 生成清晰的二进制图像。据我了解,深度图像会为靠近传感器的所有物体生成一个明亮的像素,而离传感器越远,它们就越暗。因此,我询问(一维)数组中的每个像素是否超过我的最小值并低于我的最大阈值,以构成我想要获取数据的范围。 这是我的代码:

 // 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);
}

【问题讨论】:

  • 目前我还没有找到答案的主要问题是如何将具有深度信息的 11 位 int-Array 处理为二进制图像。我现在将尝试灰度 depthImage 值

标签: processing openni


【解决方案1】:

我自己犯了一个非常愚蠢的错误,因为我误解了 11 位数组。 感谢“让事物看到”的例子,我解决了它。 https://github.com/atduskgreg/Making-Things-See-Examples/tree/master/ax02_depth_range_limit

【讨论】:

    猜你喜欢
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 2016-01-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多