Quantcast
Channel: Kinect - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 530

OpenCV - How can I ad a different random image on every face?

$
0
0

I want to write a Code, where every face gets another random image out of 10 images I have. I struggle to separate the different faces. Every time I try, the same image appears on all faces. Would be great, if someone can give me a hint how to separate the faces for the Code.

You will see, I was a bit desperate. I see the mistake, its a big one I know. But I can't see the solution.

import gab.opencv.*;
import processing.video.*;
import java.awt.*;
 int num = 3;
 PImage[] myImageArray = new PImage[num];
 Capture video;
 OpenCV opencv;

 void setup() {

for (int i=0; i<myImageArray.length; i++){
   myImageArray[i] = loadImage( str(i) + ".png");
 }

  size(800, 600);
   video = new Capture(this, 800/2, 600/2);
   opencv = new OpenCV(this, 800/2, 600/2);
   opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);

   video.start();
 }

 void draw() {
   scale(2);
  opencv.loadImage(video);
   image(video, 0, 0 );

  Rectangle[] faces = opencv.detect();
   println(faces.length);                    //print number of faces
   for (int i = 0; i < faces.length; i++) {
     println(faces[i].x + "," + faces[i].y); //print position(x/y) of faces
  image(myImageArray[(int)random(num)], faces[i].x-70, faces[i].y-60, faces[i].width+80, faces[i].height+80);
 }
}

 void captureEvent(Capture c) {
   c.read();
 }

Viewing all articles
Browse latest Browse all 530

Trending Articles