1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.cts; 18 19 import com.android.cts.media.R; 20 21 22 import android.content.Intent; 23 import android.graphics.PointF; 24 import android.media.FaceDetector; 25 import android.media.FaceDetector.Face; 26 import android.test.InstrumentationTestCase; 27 28 import java.util.List; 29 30 public class FaceDetector_FaceTest extends InstrumentationTestCase { 31 private FaceDetectorStub mActivity; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 Intent intent = new Intent(); 37 intent.setClass(getInstrumentation().getTargetContext(), FaceDetectorStub.class); 38 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 39 intent.putExtra(FaceDetectorStub.IMAGE_ID, R.drawable.single_face); 40 mActivity = (FaceDetectorStub) getInstrumentation().startActivitySync(intent); 41 } 42 43 @Override tearDown()44 protected void tearDown() throws Exception { 45 super.tearDown(); 46 mActivity.finish(); 47 } 48 testFaceProperties()49 public void testFaceProperties() throws Exception { 50 long waitMsec = 5000; 51 Thread.sleep(waitMsec); 52 List<Face> detectedFaces = mActivity.getDetectedFaces(); 53 assertEquals(1, detectedFaces.size()); 54 Face face = detectedFaces.get(0); 55 PointF eyesMP = new PointF(); 56 face.getMidPoint(eyesMP); 57 float tolerance = 5f; 58 float goodConfidence = 0.3f; 59 assertTrue(face.confidence() >= goodConfidence); 60 float eyesDistance = 20.0f; 61 assertEquals(eyesDistance, face.eyesDistance(), tolerance); 62 float eyesMidpointX = 60.0f; 63 float eyesMidpointY = 60.0f; 64 assertEquals(eyesMidpointX, eyesMP.x, tolerance); 65 assertEquals(eyesMidpointY, eyesMP.y, tolerance); 66 face.pose(FaceDetector.Face.EULER_X); 67 face.pose(FaceDetector.Face.EULER_Y); 68 face.pose(FaceDetector.Face.EULER_Z); 69 70 int ErrorEuler = 100; 71 try { 72 face.pose(ErrorEuler); 73 fail("Should throw IllegalArgumentException"); 74 } catch (IllegalArgumentException e) { 75 // expected 76 } 77 } 78 } 79 80