securesmartcam / app / src / main / java / org / witness / obscuracam / photo / detect / AndroidFaceDetection.java @ 41590feb
History | View | Annotate | Download (1.98 KB)
1 |
package org.witness.obscuracam.photo.detect; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import android.graphics.Bitmap; |
6 |
import android.graphics.PointF; |
7 |
import android.graphics.RectF; |
8 |
import android.media.FaceDetector; |
9 |
import android.media.FaceDetector.Face; |
10 |
|
11 |
public class AndroidFaceDetection implements FaceDetection { |
12 |
|
13 |
public static final String LOGTAG = "AndroidFaceDetection"; |
14 |
|
15 |
public static int MAX_FACES = 10; |
16 |
|
17 |
Face[] faces = new Face[MAX_FACES]; |
18 |
FaceDetector faceDetector; |
19 |
|
20 |
int numFaces = 0; |
21 |
|
22 |
public final static float CONFIDENCE_FILTER = .15f; |
23 |
|
24 |
public AndroidFaceDetection(int width, int height) { |
25 |
|
26 |
faceDetector = new FaceDetector(width, height, MAX_FACES);
|
27 |
|
28 |
} |
29 |
|
30 |
public void release () |
31 |
{ |
32 |
faceDetector = null;
|
33 |
} |
34 |
|
35 |
public int findFaces(Bitmap bmp) { |
36 |
|
37 |
numFaces = faceDetector.findFaces(bmp, faces); |
38 |
return numFaces;
|
39 |
} |
40 |
|
41 |
public ArrayList<DetectedFace> getFaces(int foundFaces) { |
42 |
|
43 |
ArrayList<DetectedFace> dFaces = new ArrayList<DetectedFace>(); |
44 |
|
45 |
for (int i = 0; i < foundFaces; i++) { |
46 |
|
47 |
if (faces[i].confidence() > CONFIDENCE_FILTER)
|
48 |
{ |
49 |
PointF midPoint = new PointF();
|
50 |
|
51 |
float eyeDistance = faces[i].eyesDistance();
|
52 |
faces[i].getMidPoint(midPoint); |
53 |
|
54 |
// Create Rectangle
|
55 |
/*
|
56 |
float poseX = faces[i].pose(Face.EULER_X);
|
57 |
float poseY = faces[i].pose(Face.EULER_Y);
|
58 |
float poseZ = faces[i].pose(Face.EULER_Z);
|
59 |
|
60 |
Log.i(LOGTAG,"euclid: " + poseX + "," + poseY + "," + poseZ);
|
61 |
*/
|
62 |
|
63 |
float widthBuffer = eyeDistance * 1.5f; |
64 |
float heightBuffer = eyeDistance * 2f; |
65 |
RectF faceRect = new RectF((midPoint.x-widthBuffer),
|
66 |
(midPoint.y-heightBuffer), |
67 |
(midPoint.x+widthBuffer), |
68 |
(midPoint.y+heightBuffer)); |
69 |
|
70 |
DetectedFace dFace = new DetectedFace();
|
71 |
dFace.bounds = faceRect; |
72 |
dFace.midpoint = midPoint; |
73 |
dFace.eyeDistance = eyeDistance; |
74 |
|
75 |
dFaces.add(dFace); |
76 |
} |
77 |
} |
78 |
|
79 |
return dFaces;
|
80 |
} |
81 |
|
82 |
} |