Android 检测到人脸时拍照
我有以下代码,当检测到人脸时,我只想自动拍摄一张照片。 我已经实现了自动拍照,但它拍摄了很多照片,没有时间处理它们,因为它不断检测人脸。我怎样才能让它每x分钟搜索一张脸或每x分钟拍照一次?先谢谢你Android 检测到人脸时拍照,android,camera,android-camera,face-detection,Android,Camera,Android Camera,Face Detection,我有以下代码,当检测到人脸时,我只想自动拍摄一张照片。 我已经实现了自动拍照,但它拍摄了很多照片,没有时间处理它们,因为它不断检测人脸。我怎样才能让它每x分钟搜索一张脸或每x分钟拍照一次?先谢谢你 FaceDetectionListener faceDetectionListener = new FaceDetectionListener(){ @Override public void onFaceDetection(Face[] faces, Camera camera)
FaceDetectionListener faceDetectionListener
= new FaceDetectionListener(){
@Override
public void onFaceDetection(Face[] faces, Camera camera) {
if (faces.length == 0){
prompt.setText(" No Face Detected! ");
}else{
//prompt.setText(String.valueOf(faces.length) + " Face Detected :) ");
try{
camera.takePicture(myShutterCallback,myPictureCallback_RAW, myPictureCallback_JPG);
}
catch(Exception e){
}
}
}};
然后,您可以在
myShutterCallback
中执行任何处理,并调用faceDetectionListener.setProcessing(false)
拍摄另一张照片。这将保证一次只拍摄一张照片。如果我在您给我写信时运行它,它根本不会拍摄照片。我做错了什么?
FaceDetectionListener faceDetectionListener
= new FaceDetectionListener(){
private boolean processing = false;
public void setProcessing(boolean processing) {
this.processing = processing;
}
@Override
public void onFaceDetection(Face[] faces, Camera camera) {
if (processing) return;
if (faces.length == 0){
prompt.setText(" No Face Detected! ");
}else{
//prompt.setText(String.valueOf(faces.length) + " Face Detected :) ");
try{
camera.takePicture(myShutterCallback,myPictureCallback_RAW, myPictureCallback_JPG);
processing = true;
}
catch(Exception e){
}
}
}};