KINECT + SimpleOpenNI + flob Tracking problems
in
Contributed Library Questions
•
8 months ago
Hello everybody,
I'm working on a little project to track people at a public space. they have to get a unique IDs to give them a color and control lights with those colors.
I'm stuck at this point:
If I use TRACK in processing, only half of my "people" (I simulate with objects in a nearer distance at the moment) are detected and they get an ID, some objects are rocksolid bound to their ID, others change sometimes.
If I use CALC or TRACKSIMPLE all of my "people" are tracked, but there is no permanent ID possible.
LINE 87: blobs = flob.tracksimple( flob.binarize(videoinput) );
Any idea why TRACK doesn't finde all of my objects? Is there a possible solution?
Any help would be very apprechiated!
Thank a lot in advance.
(I started with the flob tracking example to get to this point).
- /*
- flob tracking example with method track
- */
- import processing.opengl.*;
- import processing.video.*;
- import s373.flob.*;
- import SimpleOpenNI.*;
- SimpleOpenNI context;
- Capture video;
- Flob flob;
- PImage videoinput;
- /// video params
- int tresh = 100;
- int fade = 0;
- int om = 0;
- int videores=320;
- int videoheight=videores/4*3;
- int videotex=3;
- boolean drawimg=true;
- String info="";
- float fps = 30;
- PFont font = createFont("monaspace", 16);
- ArrayList blobs = new ArrayList();
- //distance to kinect of detected objects
- int threshold = 1370;
- int threshold_near = 700;
- void setup() {
- size(640, 480);
- context = new SimpleOpenNI(this);
- if (context.enableDepth() == false)
- {
- println("Can't open the depthMap, maybe the camera is not connected!");
- exit();
- return;
- }
- videoinput = createImage(videores, videoheight, RGB);
- flob = new Flob(this, videores, videoheight, width, height);
- flob.setOm(om).setThresh(tresh).setFade(0).setMirror(false, false);
- flob.setSrcImage(videotex);
- flob.setBlur(1);
- flob.settrackedBlobLifeTime(100);
- textFont(font);
- }
- void draw() {
- context.update();
- //limit depth out of kinect
- int allNearXPosAddedUp = 0;
- int allNearYPosAddedUp = 0;
- int allPos = 0;
- int[] depthArray = context.depthMap();
- for ( int row = 0; row < context.depthHeight(); row++) {
- for ( int col = 0; col < context.depthWidth(); col++) {
- int offsetInBigArray = row*context.depthWidth() + col;
- int thisDepth = depthArray[ offsetInBigArray ];
- if (thisDepth > threshold_near && thisDepth < threshold) { //the lights turn out to be 255
- allNearYPosAddedUp = allNearYPosAddedUp + row;
- allPos++;
- context.depthImage().pixels[offsetInBigArray] = color(255, 255, 255);
- }
- if (thisDepth < threshold_near || thisDepth > threshold) { //the shadows turn out to be 0
- allNearXPosAddedUp = allNearXPosAddedUp + col;
- allNearYPosAddedUp = allNearYPosAddedUp + row;
- allPos++;
- context.depthImage().pixels[offsetInBigArray] = color(0, 0, 0);
- }
- }
- }
- //BLOB TRACKING
- videoinput.copy(context.depthImage(), 0, 0, 640, 480, 0, 0, videores, videoheight);
- blobs = flob.track( flob.binarize(videoinput) );
- background(0);
- image(flob.getSrcImage(), 0, 0, width, height);
- fill(255, 100);
- stroke(255, 200);
- rectMode(CENTER);
- int numblobs = flob.getNumBlobs();
- for (int i = 0; i < blobs.size(); i++) {
- trackedBlob tb = flob.getTrackedBlob(i);
- String txt = "id: "+tb.id+" time: "+tb.presencetime+" ";
- float velmult = 100.0f;
- fill(220, 220, 255, 100);
- rect(tb.cx, tb.cy, tb.dimx, tb.dimy);
- fill(0, 255, 0, 200);
- rect(tb.cx, tb.cy, 5, 5);
- fill(0);
- line(tb.cx, tb.cy, tb.cx + tb.velx * velmult, tb.cy + tb.vely * velmult );
- fill(0, 102, 153);
- text(txt, tb.cx -tb.dimx*0.10f, tb.cy + 5f);
- }
- // stats
- fill(255, 152, 255);
- rectMode(CORNER);
- rect(5, 5, flob.getPresencef()*width, 10);
- String stats = ""+frameRate+"\nflob.numblobs: "+blobs.size()+"\nflob.thresh:"+tresh+
- " <t/T>"+"\nflob.fade:"+fade+" <f/F>"+"\nflob.om:"+flob.getOm()+
- "\nflob.image:"+videotex+"\nflob.presence:"+flob.getPresencef()
- +"\npress space to clear background";
- fill(0, 255, 0);
- text(stats, 5, 25);
- }
- void keyPressed() {
- if (key=='b')
- drawimg^=true;
- if (key=='s')
- saveFrame("flobtrack-######.png");
- if (key=='i') {
- videotex = (videotex+1)%4;
- flob.setImage(videotex);
- }
- if (key=='t') {
- tresh--;
- flob.setTresh(tresh);
- }
- if (key=='T') {
- tresh++;
- flob.setTresh(tresh);
- }
- if (key=='f') {
- fade--;
- flob.setFade(fade);
- }
- if (key=='F') {
- fade++;
- flob.setFade(fade);
- }
- if (key=='o') {
- om^=1;
- flob.setOm(om);
- }
- if (key==' ') //space clear flob.background
- flob.setBackground(videoinput);
- }
1