在Android上使用Camera 2 API
对于实时图像处理,我设置了一个监听器来进行一些图像处理,给出一个关于是否捕获图像的布尔输出。目前,我在点击按钮时使用的camera2Raw
示例中包含takePicture()
。如何确保捕获我处理的相同帧并且不捕获其他帧。请帮帮我。感谢
答案 0 :(得分:0)
当你在captureSession中进行捕获时,当前帧将被捕获并通过onCapturePictureComplete()方法从当前回调关联到你的捕获:
mCaptureSession.capture(mPhotoRequestBuilder.build(), YourCallback, null);
private CameraCaptureSession.CaptureCallback YourCallback = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
//get the iso and time exposure from the picture
Integer iso = result.get(CaptureResult.SENSOR_SENSITIVITY);
long timeExposure = result.get(CaptureResult.SENSOR_EXPOSURE_TIME);
Log.i(TAG, "[mHdrCaptureCallback][HDR] Photo: " + mHdrIndex + " Exposure: " + timeExposure);
Log.i(TAG, "[mHdrCaptureCallback][HDR] Photo: " + mHdrIndex + " ISO " + iso);
}
};
在上面的示例中,我进行了捕获,当它完成时,Capture回调就是调用。我只是从图像结果打印曝光和ISO的值。但是,当您拍摄照片时,也会调用当前ImageReader中的onImageAvailable Listener,并且您将拥有当前帧和图像以保存它。
在Google中查看您的示例:
/**
* This a callback object for the {@link ImageReader}. "onImageAvailable" will be called when a
* JPEG image is ready to be saved.
*/
private final ImageReader.OnImageAvailableListener mOnJpegImageAvailableListener
= new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
dequeueAndSaveImage(mJpegResultQueue, mJpegImageReader);
}
};
/**
* This a callback object for the {@link ImageReader}. "onImageAvailable" will be called when a
* RAW image is ready to be saved.
*/
private final ImageReader.OnImageAvailableListener mOnRawImageAvailableListener
= new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
dequeueAndSaveImage(mRawResultQueue, mRawImageReader);
}
};
希望它能帮到你,现在你知道保存图像处理如何更好地使用camera2,请告诉我是否可以帮助你做其他事情!