如何避免重复拍摄图像
how to avoid image captured repeatedly
我是 android 的新人 development.I 目前正在开发一个应用程序,将身份证中的图像与 face.From UploadActivity
的图像进行比较,用户将捕获身份证点击"OK"后用户会被提示从LivenessActivity
直播前置摄像头抓拍用户的脸。据说做完眨眼动作后,人脸会被成功抓拍并自动提示UploadActivity
.在UploadActivity
,用户点击按钮"VIEWFACE"然后人脸图像会appear.But不幸的是,在捕获人脸图像的过程中,LivenessActivity
一直出现要求用户捕获再次。但是如果用户点击后退按钮,那么它会提示UploadActivity
。如何避免LivenessActivity
在捕获面部后继续出现?
这是我的Upload Activity
和LivenessActivity
供大家参考:
上传活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
txtPercentage = (TextView) findViewById(R.id.txtPercentage);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
imgPreview = (ImageView) findViewById(R.id.imgPreview);
imgFace = (ImageView) findViewById(R.id.imgFace);
btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);
btnCapturePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
captureImage();
}
});
Intent i = getIntent();
// boolean flag to identify the media type, image or video
final boolean isImage = i.getBooleanExtra("isImage",true);
previewMedia(isImage);
if (fileUri != null)
//call LivenessActivity
startActivity(new Intent(UploadActivity.this,
LivenessActivity.class));
btnviewface = (Button) findViewById(R.id.btnviewface);
btnviewface.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle extras = getIntent().getExtras();
byte[] face = extras.getByteArray("image_best");
//save byte[] in the sd card, make a folder
try {
Config.IMAGE_FACE = "/storage/emulated/0/Pictures/Android
File Upload/IMG_face.jpg";
FileOutputStream stream = new FileOutputStream(
Config.IMAGE_FACE);
stream.write(face);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bmp = BitmapFactory.decodeByteArray(face, 0,
face.length);
imgFace.setImageBitmap(bmp);
previewMedia(isImage);
new UploadFileToServer(Config.IMAGE_DOC,
Config.IMAGE_FACE).execute();
}
} );
LivenessActivity:
@Override
public Detector.DetectionType onDetectionSuccess(DetectionFrame validFrame) {
FaceIDDataStruct dataStruct = mDetector.getFaceIDDataStruct();
if (dataStruct != null) {
face = dataStruct.images.get("image_best");
Intent intent = new Intent(LivenessActivity.this, UploadActivity.class);
//facefileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
//intent.putExtra("filePath", facefileUri.getPath());
intent.putExtra("image_best",face);
setResult(PAGE_INTO_LIVENESS, intent);
startActivity(intent);
}
if (face == null) {
face = validFrame.getCroppedFaceImageData();
}//do something with liveness face
return DetectionType.DONE;
}
删除 LivenessActivity
中的 startActivity 而不是此调用 finish()
或 LivenessActivity.this.finish()
@Override
public Detector.DetectionType onDetectionSuccess(DetectionFrame validFrame) {
FaceIDDataStruct dataStruct = mDetector.getFaceIDDataStruct();
if (dataStruct != null) {
face = dataStruct.images.get("image_best");
Intent intent = new Intent(LivenessActivity.this, UploadActivity.class);
//facefileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
//intent.putExtra("filePath", facefileUri.getPath());
intent.putExtra("image_best",face);
setResult(PAGE_INTO_LIVENESS, intent);
startActivity(intent); // Remove this
finish(); // LivenessActivity.this.finish()
}
if (face == null) {
face = validFrame.getCroppedFaceImageData();
}//do something with liveness face
return DetectionType.DONE;
}
我是 android 的新人 development.I 目前正在开发一个应用程序,将身份证中的图像与 face.From UploadActivity
的图像进行比较,用户将捕获身份证点击"OK"后用户会被提示从LivenessActivity
直播前置摄像头抓拍用户的脸。据说做完眨眼动作后,人脸会被成功抓拍并自动提示UploadActivity
.在UploadActivity
,用户点击按钮"VIEWFACE"然后人脸图像会appear.But不幸的是,在捕获人脸图像的过程中,LivenessActivity
一直出现要求用户捕获再次。但是如果用户点击后退按钮,那么它会提示UploadActivity
。如何避免LivenessActivity
在捕获面部后继续出现?
这是我的Upload Activity
和LivenessActivity
供大家参考:
上传活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
txtPercentage = (TextView) findViewById(R.id.txtPercentage);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
imgPreview = (ImageView) findViewById(R.id.imgPreview);
imgFace = (ImageView) findViewById(R.id.imgFace);
btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);
btnCapturePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
captureImage();
}
});
Intent i = getIntent();
// boolean flag to identify the media type, image or video
final boolean isImage = i.getBooleanExtra("isImage",true);
previewMedia(isImage);
if (fileUri != null)
//call LivenessActivity
startActivity(new Intent(UploadActivity.this,
LivenessActivity.class));
btnviewface = (Button) findViewById(R.id.btnviewface);
btnviewface.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle extras = getIntent().getExtras();
byte[] face = extras.getByteArray("image_best");
//save byte[] in the sd card, make a folder
try {
Config.IMAGE_FACE = "/storage/emulated/0/Pictures/Android
File Upload/IMG_face.jpg";
FileOutputStream stream = new FileOutputStream(
Config.IMAGE_FACE);
stream.write(face);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bmp = BitmapFactory.decodeByteArray(face, 0,
face.length);
imgFace.setImageBitmap(bmp);
previewMedia(isImage);
new UploadFileToServer(Config.IMAGE_DOC,
Config.IMAGE_FACE).execute();
}
} );
LivenessActivity:
@Override
public Detector.DetectionType onDetectionSuccess(DetectionFrame validFrame) {
FaceIDDataStruct dataStruct = mDetector.getFaceIDDataStruct();
if (dataStruct != null) {
face = dataStruct.images.get("image_best");
Intent intent = new Intent(LivenessActivity.this, UploadActivity.class);
//facefileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
//intent.putExtra("filePath", facefileUri.getPath());
intent.putExtra("image_best",face);
setResult(PAGE_INTO_LIVENESS, intent);
startActivity(intent);
}
if (face == null) {
face = validFrame.getCroppedFaceImageData();
}//do something with liveness face
return DetectionType.DONE;
}
删除 LivenessActivity
中的 startActivity 而不是此调用 finish()
或 LivenessActivity.this.finish()
@Override
public Detector.DetectionType onDetectionSuccess(DetectionFrame validFrame) {
FaceIDDataStruct dataStruct = mDetector.getFaceIDDataStruct();
if (dataStruct != null) {
face = dataStruct.images.get("image_best");
Intent intent = new Intent(LivenessActivity.this, UploadActivity.class);
//facefileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
//intent.putExtra("filePath", facefileUri.getPath());
intent.putExtra("image_best",face);
setResult(PAGE_INTO_LIVENESS, intent);
startActivity(intent); // Remove this
finish(); // LivenessActivity.this.finish()
}
if (face == null) {
face = validFrame.getCroppedFaceImageData();
}//do something with liveness face
return DetectionType.DONE;
}