我使用 API 14 创建了一个成功使用人脸检测的 Activity(我对人脸检测有点陌生)。
但是我不想显示相机的预览;我只想知道用户的脸什么时候在镜头前。我添加了几个按钮来使 SurfaceView 可见/不可见,我发现当它不可见或消失时人脸检测停止工作。
有没有办法在布局中不需要 SurfaceView 的情况下启用人脸检测?
这是我的编码方式:
mCamera.setPreviewDisplay(mSurfaceHolder);
mCamera.startPreview();
if(mCamera.getParameters().getMaxNumDetectedFaces() >0) {
mCamera.setFaceDetectionListener(new Camera.FaceDetectionListener() {
@Override public void onFaceDetection(Face[] faces, Camera camera) {
if(faces.length > 0) {
System.out.println("Found someone");
}
}
});
mCamera.startFaceDetection();
}
为了隐藏表面 View ,我添加了一个黑色 View 。 :-)
<View android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000"/>
我仔细看了一圈,还没有找到太多使用 startFaceDetection() 的代码。
感谢任何想法/帮助。
最佳答案
您应该根据自己的目的使用虚拟的 SurfaceTexture。
只需传递任何整数来创建一个 SurfaceTexture 对象,例如
mSurfaceTexture = new SurfaceTexture(1);
现在,打开相机并执行以下操作:
mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT); try{ mCamera.setPreviewTexture(mSurfaceTexture); } catch (IOException t) { //Do Something here }
3) 你可以用同样的方式做其他所有事情,即使用人脸检测。
关于android - 人脸检测是否需要 SurfaceView 才能工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9781853/