利用 官方API实现人脸检测有几个步骤

Android 4.0 (API Level 14)框架提供了识别面部的和跟据其计算图像设置的API
注:当启用面部检测特性时,setWhiteBalance(String),setFocusAreas(List) 和setMeteringAreas(List)不再起作用.

使用面部检测特性通常需要以下几步:

1.   检查设备是否支持面部检测

2.   创建一个面部检测监听器

3.   添加面部检测监听器到你的相机对象.

4.   预览开始后开始面部检测(并且每次重启预览后同样)

 

第一步就很重要,如果设备不支持,就无从下手了!

而面部检测特性不是在所有的设备上都支持.这个可以调用getMaxNumDetectedFaces()来检测设备是否支持.

而关于getMaxNumDetectedFaces()的方法,官方是这样解释的:



public int getMaxNumDetectedFaces ()

Added in API level 14

Gets the maximum number of detected faces supported.This is the maximum length of the list returned from Camera.FaceDetectionListener. If the return value is 0,face detection of the specified type is not supported.

Returns

·        the maximum number of detected face supported by the camera.

See Also

·        startFaceDetection()


也就是说如果调用此方法返回可检测人脸最大的数量值为0,则证明使用此API方式不支持人脸识别。


有网友在Stack Overflow 上也提问到这个 人脸识别的问题:

Camera face detection getMaxNumDetectedFacesreturns 0 for Nexus 4, Nexus 7, Samsung Galaxy 2

 

v

I'm trying to get face detection working in live preview mode using the hardware-based Camera.faceDetectionListener new in ICS. I have tried with Nexus 4, Nexus 7, and a Samsung Galaxy 10.1 tablet and ALL of these devices return 0 for the front camera when I call getMaxNumDetectedFaces. All of the devices support face unlock, though, so I don't understand why none of them seem to support face detection. Has anyone got this working with one of these devices?

一些网友的回答:

 

Supported starting with API 14 (ICS), getMaxNumDetectedFaces returns the max length of the array that contains the results of camera face detection after it is started with startFaceDetection. If the value returned is 0, it indicates that the device does not support this method of face detection. In this case, face detection must be implemented by some other means (e.g., using FaceDetector available since API 1).

I checked the value returned by getMaxNumDetectedFaces for both front and back cameras in a few devices:

·         Nexus 4: returns 2 for both cameras.

·         Nexus 5: returns a very large number (5308421) for both cameras.

·         Nexus 7: returns 0 for both cameras.

·         Nexus 10: returns 16 for both cameras

·         Sony Xperia Z1: returns 5 for both cameras.

In summary, OEM support for camera face detection is hit and miss.

 

网友测试了谷歌系列的设备,有的设备也不支持使用官方API方式实现人脸识别功能,具体问题还是得追踪底层是否开放这个功能!


Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐