Face recognition - to visualise hidden background

edited January 2018 in Kinect

Hi everyone,

Thank you for looking at my post and hope you can help me. I have a university project and I need to have a hidden background image, and then using face recognition to reveal this image (depending on the location of your face). Here is where I've got so far.

Can't seem to make the background disappear. Thank you in advance

import processing.video.*;
import gab.opencv.*;
import java.awt.*;

PImage photo;
int pixelcount;
color pixelcolor;

Capture firstcam;
OpenCV opencv;

void setup() {
  fullScreen();

  firstcam=new Capture(this, 1600, 900);
  opencv=new OpenCV(this, 1600, 900);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
  firstcam.start();
  frameRate(24);
  noFill();

  colorMode(HSB, 360, 100, 100);
  strokeWeight(1);
  smooth();
  photo = loadImage("photo.jpg");
}

void draw() {
  opencv.loadImage(firstcam);
  Rectangle[] faces = opencv.detect();
  image(photo, 0, 0, 1600, 900);
  pushMatrix();
  translate(width, 0);
  scale(-1, 1);

  for (int i = 0 ; i < faces.length ; i++) {
    ellipse(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    stroke(255,0,0);
    lights();
    smooth();
    strokeWeight(1.5);
  }

  popMatrix();
}

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

Answers

  • edit post, highlight code, press ctrl-o to format.

  • Thanks, just done :)

  • ctrl-t in the editor will indent your code nicely.

  • Thanks, doesn't seem to do anything.

    Anything on the actually coding?

    Cheers, R

  • ctrl-t in the editor will indent your code nicely.

    in the editor, not the forum.

    Anything on the actually coding?

    it's a mess because it isn't indented 8)

  • ok, at home now and i can run that.

    basically, Rectangle[] faces = opencv.detect(); is the thing doing all the work. it returns an array of faces that it found. so this will be of 0 length if there is no face, or non-zero if it has.

    so, something like

      Rectangle[] faces = opencv.detect();
    
      ...
    
      if (faces.length == 0) {
        // nothing found
      } else {
        for (int i=0; i<faces.length; i++) {
          // draw each face
        }
      }
    

    to reveal this image (depending on the location of your face)

    this is a bit vague... what do you mean by 'reveal'? revealed all at once? or only the bit where the face is?

  • (code tidied, btw)

  • btw, this is odd

    for (int i = 0; i < faces.length; i++) {
      ellipse(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
      stroke(255, 0, 0);
      lights();
      smooth();
      strokeWeight(1.5);
    }
    

    you'd generally set the attributes before calling the ellipse.

    in fact, you only need to do it once so you can move everything outside the loop

    stroke(255, 0, 0);
    lights();
    smooth();
    strokeWeight(1.5);
    for (int i = 0; i < faces.length; i++) {
      ellipse(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    }
    

    maybe even move them into setup given that you don't change them anywhere else

  • edited January 2018

    "to reveal this image" (depending on the location of your face)

    I mean, reveal only the little where the ellipse from your the face recognition is. so the image can never be revealed all at once, and only revealed where your face is.

    Thank you for the advice so far!! :)

  • You want to use mask(). Look it up in the reference for examples.

  • edited January 2018

    @ViciousR -- also try using Google to search this forum for: video mask, video masking, masking video --example.

    I believe there are a number of related projects with example code. Many are based on silhouette / screening / background subtraction, not face detection specifically, but some of the principles are the same.

Sign In or Register to comment.