LoginSignup
0
0

More than 3 years have passed since last update.

PcessingでopenCVを使い、顔以外を検出

Posted at

processingにopenCVを入れて顔を検出する説明がネットにも本にも色々書かれているけど、口や、目だけを検出する方法が少ないので調べてみた。

例として顔検出にexampleとして入っているのは

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

OpenCV opencv;
Rectangle[] faces;

void setup() {
  opencv = new OpenCV(this, "test.jpg");
  size(1080, 720);

  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  
  faces = opencv.detect();
}

void draw() {
  image(opencv.getInput(), 0, 0);

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  for (int i = 0; i < faces.length; i++) {
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  }
}

この中の
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);

ってところで検出する対象を決めている。

opencvのことが書かれているファイルは
Documents/Processing/libraries/opencv_processing/src/gab/opencv/OpenCV.java

この中に

    public final static String VERSION = "0.5.4";
    public final static String CASCADE_FRONTALFACE = "haarcascade_frontalface_alt.xml";
    public final static String CASCADE_PEDESTRIANS = "hogcascade_pedestrians.xml";
    public final static String CASCADE_EYE = "haarcascade_eye.xml";
    public final static String CASCADE_CLOCK = "haarcascade_clock.xml";
    public final static String CASCADE_NOSE = "haarcascade_mcs_nose.xml";
    public final static String CASCADE_MOUTH = "haarcascade_mcs_mouth.xml";
    public final static String CASCADE_UPPERBODY = "haarcascade_upperbody.xml";
    public final static String CASCADE_LOWERBODY = "haarcascade_lowerbody.xml";
    public final static String CASCADE_FULLBODY = "haarcascade_fullbody.xml";
    public final static String CASCADE_PEDESTRIAN = "hogcascade_pedestrians.xml";

    public final static String CASCADE_RIGHT_EAR = "haarcascade_mcs_rightear.xml";
    public final static String CASCADE_PROFILEFACE = "haarcascade_profileface.xml";

とあるので、CASCADE_FRONTALFACEの部分をCASCADE_○○に書き換えれば使えそう

Bad Request

0
0
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
0
0