Blob detection - SimpleOpenNI plus Flob
in
Contributed Library Questions
•
10 months ago
Related to this
post
I'm attempting to create blobs detection in two rectangular detection areas using Kinect depth information and passing it to a flob detection routine.
For some reason I see the framerate drop dramatically alot of times. And I'm getting only one blob at the same time. I would appreciate any thoughts to improve blob detection..
I'm attempting to create blobs detection in two rectangular detection areas using Kinect depth information and passing it to a flob detection routine.
For some reason I see the framerate drop dramatically alot of times. And I'm getting only one blob at the same time. I would appreciate any thoughts to improve blob detection..
- import SimpleOpenNI.*;
- import s373.flob.*;
- SimpleOpenNI context;
- Flob flob1;
- float minThreshold = 1000; // minimum distance from the sensor
- float maxThreshold = 1500; // maximum distance from the sensor
- color blobNo = color(0); // color if it's outside the range
- color blobYes = color(0, 255, 0); // color if it's within the range
- int tresh = 250;
- int om = 0;
- ArrayList blobs1;
- void setup() {
- size(640, 480);
- context = new SimpleOpenNI(this);
- if (!context.enableDepth()) {
- exit();
- return;
- }
- context.setMirror(true);
- context.enableScene();
- flob1 = new Flob(context.sceneImage(), context.sceneWidth(), context.sceneHeight());
- flob1.setOm(om);
- //flob1.setThresh(250);
- }
- void draw() {
- context.update();
- PImage blobImage = getBlobImage(50, 165, 440, 165, 150, 150);
- blobs1 = flob1.track(flob1.binarize(blobImage));
- image(blobImage, 0, 0);
- stroke(255, 0, 0);
- noFill();
- rect(50, 165, 150, 150);
- rect(440, 165, 150, 150);
- for (int i = 0; i < blobs1.size(); i++) {
- trackedBlob tb = flob1.getTrackedBlob(i);
- String txt = "time: " + tb.presencetime;
- text(txt, 10, 30);
- stroke(0, 255, 0);
- rect(tb.boxminx, tb.boxminy, tb.dimx, tb.dimy);
- }
- println(frameRate);
- }
- PImage getBlobImage(int sx1, int sy1, int sx2, int sy2, int w, int h) {
- PVector[] realWorldMap = context.depthMapRealWorld();
- PImage blobImage = createImage(context.depthWidth(), context.depthHeight(), RGB);
- //int maxY = min(context.depthHeight()-sy, sy+h);
- //int maxX = min(context.depthWidth()-sx, sx+w);
- for (int y=sy1; y<sy1+h; y++) {
- for (int x=sx1; x<sx1+w; x++) {
- int index = x + y * context.depthWidth();
- PVector realWorldPoint = realWorldMap[index];
- color blobColor = blobNo;
- if (realWorldPoint.z > minThreshold && realWorldPoint.z < maxThreshold) {
- blobColor = blobYes;
- }
- blobImage.pixels[index] = blobColor;
- }
- }
- for (int y=sy2; y<sy2+h; y++) {
- for (int x=sx2; x<sx2+w; x++) {
- int index = x + y * context.depthWidth();
- PVector realWorldPoint = realWorldMap[index];
- color blobColor = blobNo;
- if (realWorldPoint.z > minThreshold && realWorldPoint.z < maxThreshold) {
- blobColor = blobYes;
- }
- blobImage.pixels[index] = blobColor;
- }
- }
- return blobImage;
- }
1