Ejemplo 1: Punto más claro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gab.opencv.*; | |
import processing.video.*; | |
Capture video; | |
OpenCV opencv; | |
void setup() { | |
size(640, 480); | |
video = new Capture(this, 640, 480); | |
opencv = new OpenCV(this, 640, 480); | |
video.start(); | |
} | |
void draw() { | |
opencv.loadImage(video); | |
image(video, 0, 0); | |
PVector loc = opencv.max(); | |
stroke(255, 0, 0); | |
strokeWeight(4); | |
noFill(); | |
ellipse(loc.x, loc.y, 15, 15); | |
} | |
void captureEvent(Capture c) { | |
c.read(); | |
} |
Ejemplo 2: Detección de contornos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gab.opencv.*; | |
import processing.video.*; | |
import java.awt.Rectangle; | |
Capture video; | |
OpenCV opencv; | |
ArrayList<Contour> contours; | |
ArrayList<Contour> polygons; | |
int threshold = 90; | |
void setup() { | |
size(640, 480); | |
video = new Capture(this, 640, 480); | |
opencv = new OpenCV(this, 640, 480); | |
video.start(); | |
} | |
void draw() { | |
image(video, 0, 0); | |
opencv.loadImage(video); | |
opencv.gray(); | |
opencv.threshold(threshold); | |
contours = opencv.findContours(); | |
// image(opencv.getOutput(), 0, 0); | |
noFill(); | |
strokeWeight(2); | |
for (Contour contour : contours) { | |
stroke(0, 255, 0); | |
contour.draw(); | |
/* | |
stroke(255, 0, 0); | |
beginShape(); | |
for (PVector point : contour.getPolygonApproximation ().getPoints()) { | |
vertex(point.x, point.y); | |
} | |
endShape();*/ | |
Rectangle r = contour.getBoundingBox(); | |
stroke(255,0,0); | |
rect(r.x, r.y, r.width, r.height); | |
float cx = (float) r.getCenterX(); | |
float cy = (float)r.getCenterY(); | |
line(cx-5, cy-5, cx+5, cy+5); | |
line(cx+5, cy-5, cx-5, cy+5); | |
} | |
println("threshold= "+threshold); | |
} | |
void captureEvent(Capture c) { | |
c.read(); | |
} | |
void keyPressed() { | |
println(key); | |
if (key == CODED) { | |
if (keyCode == UP) { | |
threshold ++; | |
} else if (keyCode == DOWN) { | |
if (threshold >0) { | |
threshold --; | |
} | |
} | |
} | |
} |
Ejemplo 3: Sustracción de fondo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gab.opencv.*; | |
import processing.video.*; | |
Capture video; | |
OpenCV opencv; | |
void setup() { | |
size(640, 480); | |
video = new Capture(this, 640, 480); | |
opencv = new OpenCV(this, 640, 480); | |
opencv.startBackgroundSubtraction(5, 3, 0.5); | |
video.start(); | |
} | |
void draw() { | |
image(video, 0, 0); | |
opencv.loadImage(video); | |
opencv.dilate(); | |
opencv.erode(); | |
opencv.updateBackground(); | |
noFill(); | |
stroke(255, 0, 0); | |
strokeWeight(3); | |
for (Contour contour : opencv.findContours()) { | |
contour.draw(); | |
} | |
} | |
void captureEvent(Capture c) { | |
c.read(); | |
} |
Ejemplo 3: Detección de rostros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gab.opencv.*; | |
import processing.video.*; | |
import java.awt.*; | |
Capture video; | |
OpenCV opencv; | |
void setup() { | |
size(640, 480); | |
video = new Capture(this, 640/2, 480/2); | |
opencv = new OpenCV(this, 640/2, 480/2); | |
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); | |
video.start(); | |
} | |
void draw() { | |
scale(2); | |
opencv.loadImage(video); | |
image(video, 0, 0 ); | |
noFill(); | |
stroke(0, 255, 0); | |
strokeWeight(3); | |
Rectangle[] faces = opencv.detect(); | |
println(faces.length); | |
for (int i = 0; i < faces.length; i++) { | |
println(faces[i].x + "," + faces[i].y); | |
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height); | |
} | |
} | |
void captureEvent(Capture c) { | |
c.read(); | |
} |
Recent Comments