LoginSignup
2
6

More than 5 years have passed since last update.

Processingで顔認識openCVを使う。

Last updated at Posted at 2017-10-10

processingでopenCVを使う。

processingで顔認識を行うにはopenCVのライブラリを使うのが簡単でした。openframeWorksで顔認識を行う場合はxml形式の学習データが必要だったのですが、Processingでは必要ないのかな?

openCVをProcessingで利用するためには、こちらのページを参考にさせてもらいました。
[リンク]http://r-dimension.xsrv.jp/classes_j/opencv-for-processing/

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

Capture video;
OpenCV opencv;
Rectangle[] faces;

void setup() {
  size(1280, 680);
  background(0);
  video =new Capture(this, width/2, height/2);
  opencv=new OpenCV(this, width/2, height/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
  video.start();
}

void draw() {
  scale(2);
  opencv.loadImage(video);
  pushMatrix();
  scale(-1, 1);
  image(video, -width/2, 0);
  popMatrix();

  Rectangle[] faces =opencv.detect();
  opencv.loadImage(video);
  strokeWeight(3);
  stroke(255, 255);
  fill(255,0,0, 127);
  strokeWeight(3);

  for ( int i = 0; i <faces.length; i ++) {
    pushMatrix();
    scale(-1, 1);
    translate(-width/2, 0);
    noFill();
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    popMatrix();
  }
}



void captureEvent(Capture c) {
  c.read();
}
2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6