2013-11-27 3 views
0

Я пытаюсь создать двоичное изображение из функции depthMap() в OpenNI, которая предоставляет массив типа int. С этим изображением я хочу сделать blob-Tracking. Проблема в том, что я не могу создать четкое двоичное изображение из карты глубины. По моему пониманию, изображение глубины создает яркий пиксель для всего, что ближе к датчику, и чем дальше от сенсора, тем темнее они становятся. Поэтому я задаю каждый пиксель в (одномерном) массиве, если он находится за мой минимум и под моим максимальным порогом, чтобы составить диапазон, из которого я хочу получить данные. Вот мой код:OpenNi Blob Отслеживание бинарного изображения, полученного с помощью 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); 
} 
+0

Основная проблема в том, что я еще не смог ответить на вопрос, как обрабатывать 11-битный int-Array с информацией о глубине для двоичного изображения. Сейчас я попробую оценить значения глубины шкалы серого – mbnz

ответ