Android MaxNumDetectedFaces Face Detection

So, I just upgraded my tablet (original asus transformer) to version 4.0.3 for Android to create an application that uses face recognition. But every time I run it and try to start face recognition, I get this error in logcat:

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

I read in the docs, which means that 0 faces can be detected or maintained, but does this mean that my device cannot detect faces at all or is it something I can change? Also would his use of the rear camera change him to another camera to change anything? I tried to do this, but I cannot figure out how a project that is trying to start can be found here:

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

from this question SO: Android face detector using Android camera

+4
source share
3 answers

You must first call getMaxNumDetectedFaces () to find out if your device supports it. The return value must be> 0, if supported. As I mentioned in the previous question, the deviceโ€™s camera module and drivers must also support it.

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

0
source

Remember that you can detect faces using the older FaceDetector API . It works from API level 1 and should work on all phones with a camera. It also returns you a frame 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; } 
+4
source

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

See the code for the link and check for possible exceptions (for example, the exclusion of an illegal argument may be selected due to the different size of the bitmap with the initial size of the FaceDetection object, line 138 ~)

0
source

Source: https://habr.com/ru/post/1399819/


All Articles