我的问题是,当检测到人脸时,如何拍摄照片并保存到设备中,而当我们拍摄第一张照片时,由于无法保存到设备中,所以在人脸检测到5秒后将拍摄下一张照片。
发布于 2017-03-09 17:41:18
您必须在camera API中添加FaceDetectionListener,然后调用startFaceDetection()方法。
CameraFaceDetectionListener fDListener = new CameraFaceDetectionListener();
mCamera.setFaceDetectionListener(fDetectionListener);
mCamera.startFaceDetection();实现覆盖方法,你会收到onFaceDetection覆盖方法中检测到的人脸,
private class MyFaceDetectionListener
implements Camera.FaceDetectionListener {
@Override
public void onFaceDetection(Face[] faces, Camera camera) {
if (faces.length == 0) {
Log.i(TAG, "No faces detected");
} else if (faces.length > 0) {
Log.i(TAG, "Faces Detected = " +
String.valueOf(faces.length));
public List<Rect> faceRects;
faceRects = new ArrayList<Rect>();
for (int i=0; i<faces.length; i++) {
int left = faces[i].rect.left;
int right = faces[i].rect.right;
int top = faces[i].rect.top;
int bottom = faces[i].rect.bottom;
Rect uRect = new Rect(left0, top0, right0, bottom0);
faceRects.add(uRect);
}
// add function to draw rects on view/surface/canvas
}
}根据您的情况,新的处理程序().postDelayed(新的Runnable,长秒)在5秒后在runnable内拍摄第二张图片。如果您有任何疑问,请告诉我。
https://stackoverflow.com/questions/42690402
复制相似问题