Frame Difference with blob detection
in
Contributed Library Questions
•
5 months ago
Hi Everyone,
I have problem of unifying the two code into one. As I have frame-difference code and blob detection code. I am trying to make finger detection more robust using these two techniques.
I have thought that if I could apply the blob detection on the frame that is left after the frame-subtraction but it is not working. Can anyone of you give me some insight on my code ...Sometime I do lot of stupid things and got blind not to see them.
please help !
Here is the code.
- import processing.video.*;
- import Blobscanner.*;
- Detector bd;
- int numPixels;
- int[] backgroundPixels;
- Capture video;
- int flag=0;
- int width=320, height=240;
- void setup() {
- size(width, height, P2D);
- video = new Capture(this, width, height);
- video.start();
- backgroundPixels = new int[width*height];
- loadPixels();
- }
- void draw() {
- if (video.available()) {
- video.read();
- }
- video.loadPixels();
- for (int y = 0; y < height; y++) {
- for (int x =0; x < width; x++) {
- numPixels = x + y*width;
- color currColor = video.pixels[numPixels];
- color bkgdColor = backgroundPixels[numPixels];
- /*----------------------------------*/
- int currR = (currColor >> 16) & 0xFF;
- int currG = (currColor >> 8) & 0xFF;
- int currB = currColor & 0xFF;
- /*----------------------------------*/
- int bkgdR = (bkgdColor >> 16) & 0xFF;
- int bkgdG = (bkgdColor >> 8) & 0xFF;
- int bkgdB = bkgdColor & 0xFF;
- int diffR = abs(currR - bkgdR);
- int diffG = abs(currG - bkgdG);
- int diffB = abs(currB - bkgdB);
- pixels[numPixels] = 0xFF000000 | (diffR << 16) | (diffG << 8) | diffB;
- }
- }
- updatePixels();
- if (flag==1) {
- video.loadPixels();
- bd.imageFindBlobs(video);
- bd.loadBlobsFeatures();
- bd.weightBlobs(false);
- bd.findCentroids(false, false);
- stroke(255, 100, 0);
- for (int i = 0; i < bd.getBlobsNumber(); i++) {
- fill(255, 0, 0);
- noStroke();
- ellipse(bd.getCentroidX(i), bd.getCentroidY(i), 5, 5);
- }
- updatePixels();
- }
- }
- void keyPressed() {
- video.loadPixels();
- arraycopy(video.pixels, backgroundPixels);
- flag=1;
- video.filter(THRESHOLD);
- bd = new Detector( this, 0, 0, video.width, video.height, 255 );
- }
1