Created
February 22, 2021 17:06
-
-
Save abhamra/c911a9f1b23eee60e4b49ce0b6bc2676 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
PImage drake; | |
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); | |
//opencv.loadCascade(OpenCV.CASCADE_NOSE); | |
video.start(); | |
//img = loadImage("/Users/bhama22/Downloads/drake.png"); | |
//img2 = loadImage("/Users/bhama22/Downloads/sun.png"); | |
drake = loadImage("/Users/bhama22/Downloads/drake.png"); | |
} | |
void draw() { | |
scale(2); | |
opencv.loadImage(video); | |
image(video, 0, 0 ); | |
//image(drake, 0, 0, width/8, height/4); | |
//drake = get(0, 0, width/8, height/4); | |
//image(drake, 0, 0, width/8, height/4); | |
noFill(); | |
stroke(0, 255, 0); | |
strokeWeight(3); | |
Rectangle[] faces = opencv.detect(); | |
println(faces.length); | |
//for (int i = 0; i < faces.length-1; i++) { | |
// //println(faces[i].x + "," + faces[i].y); | |
// //rect 1 | |
if(faces.length>1){ | |
PImage one = get(faces[0].x*2+faces[0].width/2, faces[0].y*2+faces[0].height/2, faces[0].width, faces[0].height); | |
PImage two = get(faces[1].x*2+faces[1].width/2, faces[1].y*2+faces[1].height/2, faces[1].width, faces[1].height); | |
//rect(faces[0].x,faces[0].y, faces[0].width, faces[0].height); | |
//rect 2 | |
//rect(faces[1].x, faces[1].y, faces[1].width, faces[1].height); | |
image(one, faces[1].x, faces[1].y, faces[1].width, faces[1].height); | |
image(two, faces[0].x, faces[0].y, faces[0].width, faces[0].height); | |
} | |
//} | |
} | |
void captureEvent(Capture c) { | |
c.read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment