SlideShare a Scribd company logo
//---------------------------------------------------------
//
// author: thomas diewald
// date: 06.09.2011
//
// example how to use diewald_CV_kit.blobdetection.
//
// -------------------------------------------------------
// interaction:
//
// mouseX - defines the brightness treshhold
// dragged mouse - drag a rectangle to define the detection area
//
// key 'UP' - lower resolution
// key 'DOWN' - higher resolution
// key 'b' - draw boundingsboxes of blobs
// key 'f' - fill blobs
//---------------------------------------------------------
import diewald_CV_kit.libraryinfo.*;
import diewald_CV_kit.utility.*;
import diewald_CV_kit.blobdetection.*;
import java.util.ArrayList;
PFont font;
PImage sample_img;
int size_x, size_y;
BlobDetector blob_detector;
BoundingBox detection_area;
int detection_resolution = 1;
boolean draw_blobs_boundingsbox = true;
boolean draw_filled_blobs = true;
public void setup() {
size(640, 480);
// sample_img = loadImage(image_path + "imageprocessing_gradient_v7_600x600.jpg");
sample_img = loadImage("imageprocessing_gradient_v9_640x480.jpg");
size_x = sample_img.width;
size_y = sample_img.height;
//size(size_x, size_y);
size(640, 480);
sample_img.loadPixels();
blob_detector = new BlobDetector(size_x, size_y);
blob_detector.setResolution(detection_resolution);
blob_detector.computeContours(true);
blob_detector.computeBlobPixels(!true);
blob_detector.setMinMaxPixels(10*10, size_x*size_y);
blob_detector.setBLOBable(new BLOBable_GRADIENT(this, sample_img));
detection_area = new BoundingBox(0, 0, size_x, size_y);
blob_detector.setDetectingArea(detection_area);
font = createFont("Calibri", 14);
textFont(font);
frameRate(200);
}
public void draw() {
background(255);
image(sample_img, 0, 0);
// draw the detection-area
stroke(0, 0, 0);
strokeWeight(1);
noFill();
rect(detection_area.xMin(), detection_area.yMin(), detection_area.xSize()-1,
detection_area.ySize()-1);
// set resolution - improves speed a lot
blob_detector.setResolution(detection_resolution);
//update the blob-detector with the new pixelvalues
blob_detector.update();
// get a list of all the blobs
ArrayList<Blob> blob_list = blob_detector.getBlobs();
// iterate through the blob_list
for (int blob_idx = 0; blob_idx < blob_list.size(); blob_idx++ ) {
// get the current blob from the blob-list
Blob blob = blob_list.get(blob_idx);
// get the list of all the contours from the current blob
ArrayList<Contour> contour_list = blob.getContours();
// iterate through the contour_list
for (int contour_idx = 0; contour_idx < contour_list.size(); contour_idx++ ) {
// get the current contour from the contour-list
Contour contour = contour_list.get(contour_idx);
// get the current boundingbox from the current contour
BoundingBox bb = contour.getBoundingBox();
// handle the first contour (outer contour = contour_idx == 0) different to the inner contours
if ( contour_idx == 0) {
// draw the boundingbox and blob-id as text
if ( draw_blobs_boundingsbox ) {
drawBoundingBox(bb, color(0, 200, 200), 1);
fill(0, 200, 200);
text("blob["+blob_idx+"]", bb.xMin(), bb.yMin()- textDescent()*2);
}
// draw the contour
drawContour(contour.getPixels(), color(255, 0, 0), color(255, 0, 255, 100), draw_filled_blobs,
1);
}
else {
// draw the inner contours, if they have more than 20 vertices
if ( contour.getPixels().size() > 20) {
drawContour(contour.getPixels(), color(255, 150, 0), color(0, 100), false, 1);
}
}
}
}
// simple information about framerate, and number of detected blobs
fill(0, 200);
noStroke();
rect(0, 0, 150, 50);
printlnNumberOfBlobs(blob_detector);
printlnFPS();
}

More Related Content

KEY
「Frama-Cによるソースコード検証」 (mzp)
PDF
Зависимые типы в GHC 8. Максим Талдыкин
PDF
Simpson and lagranje dalambair math methods
PDF
44CON 2013 - The Forger's Art: Exploiting XML Digital Signature Implementatio...
DOCX
Plot3D Package and Example in R.-Data visualizat,on
PDF
C++ Programming - 14th Study
DOC
C# example (Polymorphesim)
PDF
Programming Language: Ruby
「Frama-Cによるソースコード検証」 (mzp)
Зависимые типы в GHC 8. Максим Талдыкин
Simpson and lagranje dalambair math methods
44CON 2013 - The Forger's Art: Exploiting XML Digital Signature Implementatio...
Plot3D Package and Example in R.-Data visualizat,on
C++ Programming - 14th Study
C# example (Polymorphesim)
Programming Language: Ruby

What's hot (17)

PDF
Short intro to the Rust language
PDF
DOC
Ececececuacion de primer grado y
PDF
Exploring fractals in CSS, @fronttrends, Warsaw, 2015
PDF
Prototype programming in JavaScript
PPTX
Beginning direct3d gameprogramming05_thebasics_20160421_jintaeks
PDF
PDF
Coding with Vim
PPTX
Share test
PPTX
Better performance through Superscalarity
PDF
Patterns and antipatterns
DOC
Algo for dfs
PDF
Programming Languages: comparison, history, future
DOCX
Programa en C++ ( escriba 3 números y diga cual es el mayor))
Short intro to the Rust language
Ececececuacion de primer grado y
Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Prototype programming in JavaScript
Beginning direct3d gameprogramming05_thebasics_20160421_jintaeks
Coding with Vim
Share test
Better performance through Superscalarity
Patterns and antipatterns
Algo for dfs
Programming Languages: comparison, history, future
Programa en C++ ( escriba 3 números y diga cual es el mayor))
Ad

Viewers also liked (13)

PDF
Género dos nomes
PPTX
Maintaining Your Brand's Voice
PPT
Vocabulary 5th grade Unit 4 lesson 1
PPTX
Programmed instruction
PPTX
Natural Disasters
PPT
Vocabulary 6th grade Unit 4 lesson 1
PPTX
Chitosan nanofiber
PPTX
PPT
Actualizacion de recomendación sobre vacuna frente a tetanos
PPTX
Act2 línea del tiempo
PPTX
Herramientas ofimaticas
PDF
This is Beauty & Health | True North
Género dos nomes
Maintaining Your Brand's Voice
Vocabulary 5th grade Unit 4 lesson 1
Programmed instruction
Natural Disasters
Vocabulary 6th grade Unit 4 lesson 1
Chitosan nanofiber
Actualizacion de recomendación sobre vacuna frente a tetanos
Act2 línea del tiempo
Herramientas ofimaticas
This is Beauty & Health | True North
Ad

More from Fran Orton (20)

DOCX
Pir code
DOCX
PPTX
Marilyn monroe inspo
DOCX
Essay
PPTX
Persil Posters
PPTX
Billboard Evaluation
PPTX
Software
PPTX
PPTX
Billboard evaluation
PPTX
Intro to cohesion
PPTX
Conventions magazine
PPTX
Evaluation textual analysis
PPTX
Questionnaire analysis
PPTX
Cohesion
PPTX
Radio advert evaluation legi
PPTX
Cohesion Through Media Products
PPTX
Eval text analysis
PPTX
Billboard evaluation
PPTX
Cohesion
PPTX
q2 - Intro to cohesion
Pir code
Marilyn monroe inspo
Essay
Persil Posters
Billboard Evaluation
Software
Billboard evaluation
Intro to cohesion
Conventions magazine
Evaluation textual analysis
Questionnaire analysis
Cohesion
Radio advert evaluation legi
Cohesion Through Media Products
Eval text analysis
Billboard evaluation
Cohesion
q2 - Intro to cohesion

Recently uploaded (20)

PPTX
joggers park landscape assignment bandra
PDF
Phone away, tabs closed: No multitasking
PPTX
Special finishes, classification and types, explanation
PDF
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
PPT
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PDF
Design Thinking - Module 1 - Introduction To Design Thinking - Dr. Rohan Dasg...
PPTX
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
PPTX
Tenders & Contracts Works _ Services Afzal.pptx
PPTX
YV PROFILE PROJECTS PROFILE PRES. DESIGN
PDF
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
PDF
YOW2022-BNE-MinimalViableArchitecture.pdf
PPTX
areprosthodontics and orthodonticsa text.pptx
PPT
UNIT I- Yarn, types, explanation, process
PPTX
Fundamental Principles of Visual Graphic Design.pptx
PPTX
6- Architecture design complete (1).pptx
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
PPTX
rapid fire quiz in your house is your india.pptx
PDF
The Advantages of Working With a Design-Build Studio
joggers park landscape assignment bandra
Phone away, tabs closed: No multitasking
Special finishes, classification and types, explanation
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
Design Thinking - Module 1 - Introduction To Design Thinking - Dr. Rohan Dasg...
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
Tenders & Contracts Works _ Services Afzal.pptx
YV PROFILE PROJECTS PROFILE PRES. DESIGN
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
YOW2022-BNE-MinimalViableArchitecture.pdf
areprosthodontics and orthodonticsa text.pptx
UNIT I- Yarn, types, explanation, process
Fundamental Principles of Visual Graphic Design.pptx
6- Architecture design complete (1).pptx
DOC-20250430-WA0014._20250714_235747_0000.pptx
rapid fire quiz in your house is your india.pptx
The Advantages of Working With a Design-Build Studio

Code

  • 1. //--------------------------------------------------------- // // author: thomas diewald // date: 06.09.2011 // // example how to use diewald_CV_kit.blobdetection. // // ------------------------------------------------------- // interaction: // // mouseX - defines the brightness treshhold // dragged mouse - drag a rectangle to define the detection area // // key 'UP' - lower resolution // key 'DOWN' - higher resolution // key 'b' - draw boundingsboxes of blobs // key 'f' - fill blobs //--------------------------------------------------------- import diewald_CV_kit.libraryinfo.*; import diewald_CV_kit.utility.*; import diewald_CV_kit.blobdetection.*; import java.util.ArrayList; PFont font; PImage sample_img; int size_x, size_y; BlobDetector blob_detector; BoundingBox detection_area; int detection_resolution = 1; boolean draw_blobs_boundingsbox = true; boolean draw_filled_blobs = true; public void setup() { size(640, 480); // sample_img = loadImage(image_path + "imageprocessing_gradient_v7_600x600.jpg"); sample_img = loadImage("imageprocessing_gradient_v9_640x480.jpg"); size_x = sample_img.width; size_y = sample_img.height; //size(size_x, size_y); size(640, 480); sample_img.loadPixels(); blob_detector = new BlobDetector(size_x, size_y); blob_detector.setResolution(detection_resolution); blob_detector.computeContours(true); blob_detector.computeBlobPixels(!true); blob_detector.setMinMaxPixels(10*10, size_x*size_y); blob_detector.setBLOBable(new BLOBable_GRADIENT(this, sample_img)); detection_area = new BoundingBox(0, 0, size_x, size_y);
  • 2. blob_detector.setDetectingArea(detection_area); font = createFont("Calibri", 14); textFont(font); frameRate(200); } public void draw() { background(255); image(sample_img, 0, 0); // draw the detection-area stroke(0, 0, 0); strokeWeight(1); noFill(); rect(detection_area.xMin(), detection_area.yMin(), detection_area.xSize()-1, detection_area.ySize()-1); // set resolution - improves speed a lot blob_detector.setResolution(detection_resolution); //update the blob-detector with the new pixelvalues blob_detector.update(); // get a list of all the blobs ArrayList<Blob> blob_list = blob_detector.getBlobs(); // iterate through the blob_list for (int blob_idx = 0; blob_idx < blob_list.size(); blob_idx++ ) { // get the current blob from the blob-list Blob blob = blob_list.get(blob_idx); // get the list of all the contours from the current blob ArrayList<Contour> contour_list = blob.getContours(); // iterate through the contour_list for (int contour_idx = 0; contour_idx < contour_list.size(); contour_idx++ ) { // get the current contour from the contour-list Contour contour = contour_list.get(contour_idx); // get the current boundingbox from the current contour BoundingBox bb = contour.getBoundingBox(); // handle the first contour (outer contour = contour_idx == 0) different to the inner contours if ( contour_idx == 0) { // draw the boundingbox and blob-id as text if ( draw_blobs_boundingsbox ) { drawBoundingBox(bb, color(0, 200, 200), 1);
  • 3. fill(0, 200, 200); text("blob["+blob_idx+"]", bb.xMin(), bb.yMin()- textDescent()*2); } // draw the contour drawContour(contour.getPixels(), color(255, 0, 0), color(255, 0, 255, 100), draw_filled_blobs, 1); } else { // draw the inner contours, if they have more than 20 vertices if ( contour.getPixels().size() > 20) { drawContour(contour.getPixels(), color(255, 150, 0), color(0, 100), false, 1); } } } } // simple information about framerate, and number of detected blobs fill(0, 200); noStroke(); rect(0, 0, 150, 50); printlnNumberOfBlobs(blob_detector); printlnFPS(); }