How to trigger an action with face detection?

edited December 2017 in Kinect

Hello, Is it possible to use face detection to trigger a video to play? if webcam detects a face, video plays im having trouble with achieving this


  • What have you tried? What are you using to detect the face? a webcam? do you know how to collect the video from the camera? Do you have some code that you have tested?

  • I use a webcam. I can get a video playback from the camera. I found a code that draws rectangles around the faces. I removed webcam footage from draw section. I got it working, but maybe you could suggest best settings for the video itself and should i improve something for it to run more smoothly?

    import gab.opencv.*; import*; import java.awt.Rectangle;

    Capture cam; 
    OpenCV opencv; 
    Rectangle[] faces;
    Movie video1;
    void setup() { 
      size(displayWidth, displayHeight);
      background (0, 0, 0); 
      video1 = new Movie (this, "1.mp4");
      cam = new Capture( this, 640, 480, 30); 
      opencv = new OpenCV(this, cam.width, cam.height); 
     void movieEvent(Movie m) {;
    void draw() { 
      faces = opencv.detect(); 
      if (faces!=null) { 
        for (int i=0; i< faces.length; i++) { 
        image(video1, 0, 0 );
      if (faces.length<=0) {
        fill(255, 0, 0); 
        println("no faces");
        text("stop", 100, 100);
    void captureEvent(Capture cam) {;
  • I want it to run fullscreen and the video to fit the screen and run smoothly

  • Answer ✓

    Please don't post duplicates.

    Choose one, close the other or you'll get answers to both and that'll confuse everyone.

  • how to close a discussion?

This discussion has been closed.