简体   繁体   English

Android人脸检测MaxNumDetectedFaces

[英]Android face detection MaxNumDetectedFaces

So I just upgraded my tablet (original asus transformer) to android version 4.0.3 to build a app using face detection. 所以我只是将我的平板电脑(原始华硕变换器)升级到Android版本4.0.3,以使用面部检测构建应用程序。 But every time i launch it and try to start face detection i get this error in logcat: 但每次我启动它并尝试开始面部检测我在logcat中得到这个错误:

E/AndroidRuntime(1755): java.lang.IllegalArgumentException: invalid face detection type=0

I read in the documents it means 0 faces are able to be detected or supported but does this mean my device cant detect faces at all or is it something i can change? 我在文件中读到它意味着可以检测到或支持0个面,但这是否意味着我的设备根本无法检测到面部或者是否可以改变它? Also its using the back camera, would changing it to the other camera change anything? 它还使用后置摄像头,将它更改为其他摄像头改变什么? I've been trying to do that but i cant figure out how, the project im trying to run can be found here: 我一直试图这样做,但我无法弄清楚如何,我试图运行的项目可以在这里找到:

https://docs.google.com/open?id=0B2Nu5U2Cz81qZExGQ25sWVdRd21IOExUUTZsZzFoZw https://docs.google.com/open?id=0B2Nu5U2Cz81qZExGQ25sWVdRd21IOExUUTZsZzFoZw

from this SO question: Android face detector using android camera 从这个SO问题: Android脸部探测器使用Android相机

Remember you can detect faces using the older FaceDetector API . 请记住,您可以使用旧的FaceDetector API检测面部。 It's been around since API Level 1 and should work on all phones with a camera. 它已经从API级别1开始存在,并且应该适用于所有带摄像头的手机。 It also gives you back a bounding box when a face is detected. 当检测到面部时,它还会返回一个边界框。

public Rect findFace(Bitmap bmp) {
    // Ask for 1 face
    Face faces[] = new FaceDetector.Face[1];
    FaceDetector detector = new FaceDetector( bmp.getWidth(), bmp.getHeight(), 1 );
    int count = detector.findFaces( bmp, faces );

    Face face = null;

    if( count > 0 ) {
        face = faces[0];

        PointF midEyes = new PointF();
        face.getMidPoint( midEyes );
        Log.i( TAG,
                "Found face. Confidence: " + face.confidence() + ". Eye Distance: " + face.eyesDistance() + " Pose: ("
                        + face.pose( FaceDetector.Face.EULER_X ) + "," + face.pose( FaceDetector.Face.EULER_Y ) + ","
                        + face.pose( FaceDetector.Face.EULER_Z ) + "). Eye Midpoint: (" + midEyes.x + "," + midEyes.y + ")" );

        float eyedist = face.eyesDistance();
        PointF lt = new PointF( midEyes.x - eyedist * 2.0f, midEyes.y - eyedist * 2.5f );
        // Create rectangle around face.  Create a box based on the eyes and add some padding.
        // The ratio of head height to width is generally 9/5 but that makes the rect a bit to tall.
        return new Rect(
            Math.max( (int) ( lt.x ), 0 ),
            Math.max( (int) ( lt.y ), 0 ),
            Math.min( (int) ( lt.x + eyedist * 4.0f ), bmp.getWidth() ),
            Math.min( (int) ( lt.y + eyedist * 5.5f ), bmp.getHeight() )
        );
    }

    return null;
}

For others like me, 对于像我这样的人,

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/media/FaceDetector.java http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/media/FaceDetector.java

See the code at the link, and check possible exceptions (for example, illegal argument exception can be thrown by different input bitmap size with initial size of FaceDetection object, line 138~) 请参阅链接中的代码,并检查可能的异常(例如,非法的参数异常可以通过不同的输入位图大小抛出,其初始大小为FaceDetection对象,第138行〜)

You should first call getMaxNumDetectedFaces() to see if your device supports it. 您应首先调用getMaxNumDetectedFaces()以查看您的设备是否支持它。 The return value should be > 0 if its supported. 如果支持,返回值应> 0。 Like I mentioned in your previous question, the device camera module and drivers have to also support it. 就像我在上一个问题中提到的那样,设备相机模块和驱动程序也必须支持它。

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getMaxNumDetectedFaces () http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getMaxNumDetectedFaces ()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM