Hi Forum...
I need some advice on how to tackle a problem...
I have blob detection routine (using the
blobDetection library by V3GA) which returns x amount of blobs, running in a constant for loop. Within the function, in order to reduce noise, I also test to see if the center point of the blobs are within some cropping boundaries I've set, and also whether the size of the blob is between two thresholds, both of which are working great.
My problem is that I only want to 'listen' to the position of one blob at a time - to set focus, as it were, on the first one that passes the size/position tests.
I'm at a loss about how to do that effectively right now (it's been a long day programming
). I can access the index of the blob(s) in question should they pass the conditionals, and I'm thinking that I should use a boolean to set some type of focus, then reset it if the number of blobs drops off to 0, for example...
Note that the blobs are not actually Objects, sorry for the misleading subject, just couldn't figure out what else to write...
Here's my code for this portion of the program:
The
for loop starts on Line 8
My tests are on Lines 30 - 33
- void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges) {
- Blob b;
- EdgeVertex eA,eB;
- for (int n = 0 ; n < bd.getBlobNb() ; n++) {
- b = bd.getBlob(n);
- if (b!=null) {
- // Edges (Not Used)
- if (drawEdges) {
- noFill();
- strokeWeight(2);
- stroke(0, 255, 255);
- beginShape();
- for (int m = 0; m < b.getEdgeNb(); m++) {
- eA = b.getEdgeVertexA(m);
- eB = b.getEdgeVertexB(m);
- if (eA != null && eB != null) {
- vertex(eA.x * width, eA.y * height);
- }
- }
- endShape(CLOSE);
- }
- // Blobs
- if (drawBlobs) {
- strokeWeight(1);
- noFill();
- stroke(255,0,0);
- rectMode(CORNER);
- // If Blobs Are Within Crop Area
- if(b.xMin * width > cropL && b.xMin * width < cropR &&
- b.yMin * height > cropT && b.yMin * height < cropB) {
- // If The Blob Is Over A Certain Size
- if(b.w > 0.1 && b.w < 0.2) {
- rect(b.xMin * width, b.yMin * height, b.w * width, b.h * height);
- blobX = (b.xMin * width) + ((b.w * width)/2) ; // This is the place where I am passing
- blobY = (b.yMin * height) + ((b.h * height)/2); // the variables I need to use later...
- }
- }
- else {
- }
- }
- }
- }
- }
Line 35 & 36 is the crux of it - I need to use these positions to control an interface that will trigger messages, but if I have more than one blob, obviously these get messed up and unusable...
I know there's probably a simple, elegant solution to this, I just can't grasp it right now.
Any thoughts xor advice much appreciated...
Regards,
~ Jesse
1