mobic
YaBB Newbies
Offline
Posts: 23
blobDetection library: Triangles ???
Aug 20th , 2007, 4:59pm
hello, i tried some things with the BlobDetection-library of v3ga.net and everything worked well but i couldn't use the triangles. where are they? i modified the example to see them but i always get the result that there are no triangles. in the documentation they write that every blob contains triangles. but i couldnt't get them. cann somebody help? thanks. code............................................................................ .......................... import processing.video.*; import blobDetection.*; Capture cam; BlobDetection theBlobDetection; PImage img; boolean newFrame=false; // ================================================== // setup() // ================================================== void setup() { // Size of applet size(640, 480); // Capture cam = new Capture(this, 40*4, 30*4, 15); // BlobDetection // img which will be sent to detection (a smaller copy of the cam frame); img = new PImage(80,60); theBlobDetection = new BlobDetection(img.width, img.height); theBlobDetection.setPosDiscrimination(true); theBlobDetection.setThreshold(0.2f); // will detect bright areas whose luminosity > 0.2f; PFont font; font = loadFont("Courier-48.vlw"); textFont(font); } // ================================================== // captureEvent() // ================================================== void captureEvent(Capture cam) { cam.read(); newFrame = true; } // ================================================== // draw() // ================================================== void draw() { if (newFrame) { newFrame=false; background(255); image(cam,0,0,width,height); fill(255,255,255,150); rect (0,0,width,height); img.copy(cam, 0, 0, cam.width, cam.height, 0, 0, img.width, img.height); //fastblur(img, 2); theBlobDetection.computeBlobs(img.pixels); drawBlobsAndEdges(true,true); } } // ================================================== // drawBlobsAndEdges() // ================================================== void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges) { noFill(); float groesse; Blob b; EdgeVertex eA,eB,eC; BlobTriangle tA,tB,tC; for (int n=0 ; n<theBlobDetection.getBlobNb() ; n++) { b=theBlobDetection.getBlob(n); if (b!=null) { groesse = b.w+b.h; if (groesse>0.4) { // Edges if (drawEdges) { strokeWeight(1); stroke(0,255,0); for (int m=0;m<b.getEdgeNb();m++) { eA = b.getEdgeVertexA(m); eB = b.getEdgeVertexB(m); if (eA !=null && eB !=null) { line( eA.x*width, eA.y*height, eB.x*width, eB.y*height ); text(b.getEdgeNb()+" "+n, (b.xMin+b.w/2)*width, (b.yMin+b.h/2)*height); //line((b.xMin+b.w/2)*width, (b.yMin+b.h/2)*height, // eA.x*width, eA.y*height); ellipse(eA.x*width, eA.y*height,10,10); } } } // Blobs if (drawBlobs) { strokeWeight(1); stroke(255,0,0); rect( b.xMin*width,b.yMin*height, b.w*width,b.h*height ); } // triangles if (drawEdges) { strokeWeight(1); stroke(255,0,0); println(b.getEdgeNb()); println(b.getTriangleNb()); for (int m=0;m<b.getTriangleNb();m++) { tA = b.getTriangle(m); eA = b.getTriangleVertexA(tA); eB = b.getTriangleVertexB(tA); eC = b.getTriangleVertexC(tA); line( eA.x*width,eA.y*height, eB.x*width,eB.y*height); line( eB.x*width,eB.y*height, eC.x*width,eC.y*height); line( eC.x*width,eC.y*height, eA.x*width,eA.y*height); } } } } } }