OpenCV Face Detection from A Video File

edited October 2016 in Kinect

Hi All, I'm trying to do face detection with OpenCV for Processing from a video file. I've searched through examples on the web but all of them seem to be focusing on face detection from a live feed. Is there a way to do it from a video file? I know that you can create Movie objects using the Processing Video library but can I perhaps use that class in an Open CV object? I appreciate any tips and pointers.

Tagged:

Answers

  • Hi @kfrajer it looks like your example uses Capture class to analyze frames from a video captured via a camera. Let me know if I'm mistaken. What I'm looking for is a way to analyze frames and detect faces from a video file.

  • Try this with a video with faces:

    /**
     * Loop. 
     * 
     * Shows how to load and play a QuickTime movie file.  
     *
     */
    
    import gab.opencv.*;
    import processing.video.*;
    import java.awt.*;
    
    import processing.video.*;
    boolean mousePressedbyUsr=false;
    
    Movie movie;
    OpenCV opencv;
    
    
    void setup() {
      size(640, 360);
      background(0);
    
      opencv = new OpenCV(this, 640/2, 480/2);
      opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); 
    
      // Load and play the video in a loop
      movie = new Movie(this, "transit.mov");
      movie.loop();
      noStroke();
      noSmooth();
    }
    
    void movieEvent(Movie m) {
      m.read();
    }
    
    void draw() {
    
      if (movie.available() == true) {
        movie.read();
      }
    
      if (movie==null)
        return;
    
    
      opencv.loadImage(movie);
    
      image(movie, 0, 0, width, height);
      println( movie.time() + "\t" + frameCount  + "\t" + movie.duration());
    
      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);
      }
    }
    

    Kf

  • I'll try that. Thank you.

Sign In or Register to comment.