camera2api 自动捕捉当前预览帧
camera2api auto capture current preview frame
在 Android
上使用相机 2 API
对于实时图像处理,我设置了一个侦听器来执行一些图像处理,以提供关于是否捕获图像的布尔输出。目前,我正在使用 camera2Raw
示例,当单击按钮时该示例具有 takePicture()
。我怎样才能确保捕获我处理过的同一帧,而不捕获其他帧。请帮帮我。谢谢
当您在 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);
}
};
在上面的示例中,我进行了一次捕获,当它完成时,捕获回调被调用。我只是从图像结果中打印曝光值和 ISO。但是,当您拍照时,您当前 ImageReader 的 onImageAvailable 监听器也会被调用,您将在其中保存当前帧和图像。
看看你在 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 的保存图像过程有了更深入的了解,如果我能在其他方面为您提供帮助,请告诉我!
在 Android
上使用相机 2 API对于实时图像处理,我设置了一个侦听器来执行一些图像处理,以提供关于是否捕获图像的布尔输出。目前,我正在使用 camera2Raw
示例,当单击按钮时该示例具有 takePicture()
。我怎样才能确保捕获我处理过的同一帧,而不捕获其他帧。请帮帮我。谢谢
当您在 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);
}
};
在上面的示例中,我进行了一次捕获,当它完成时,捕获回调被调用。我只是从图像结果中打印曝光值和 ISO。但是,当您拍照时,您当前 ImageReader 的 onImageAvailable 监听器也会被调用,您将在其中保存当前帧和图像。
看看你在 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 的保存图像过程有了更深入的了解,如果我能在其他方面为您提供帮助,请告诉我!