@blog.justoneplanet.info

日々勉強

androidで顔検出する

int maxFaces = 10;// 検出する顔の最大数
FaceDetector detector = new FaceDetector(bitmap.getWidth(), bitmap.getHeight(), maxFaces);
FaceDetector.Face[] faces = new FaceDetector.Face[maxFaces];
ArrayList<Bitmap> recognized = new ArrayList<Bitmap>();

// bitmapの中から顔を検出してfacesに格納する
int num = detector.findFaces(bitmap, faces);

// facesに格納されたデータから座標情報を取り出してbitmapを切り出す
for (int i = 0; i < num; i++) {
    FaceDetector.Face face = faces[i];
    PointF point = new PointF(0.0f, 0.0f);
    face.getMidPoint(point);

    int x = (int) (point.x - 1.5f * face.eyesDistance());
    int y = (int) (point.y - 2 * face.eyesDistance());
    int width  = (int) (face.eyesDistance() * 3);
    int height = (int) (face.eyesDistance() * 4);
    x = (x < 0)? 0 : x;
    y = (y < 0)? 0 : y;
    width = (width > bitmap.getWidth())? bitmap.getWidth() : width;
    height = (height > bitmap.getHeight())? bitmap.getHeight() : height;
    recognized.add(Bitmap.createBitmap(bitmap, x, y, width, height));
}
return recognized;

コメントはまだありません»

No comments yet.

RSS feed for comments on this post.TrackBack URL

Leave a comment