这是我的 Activity 类的代码:
@Override protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
_cpf = ProcessCameraProvider.getInstance(this);
_cpf.addListener(new Runnable() {
@Override
public void run() {
try {
ProcessCameraProvider cameraProvider = _cpf.get();
bindImageAnalysis(cameraProvider);
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}
}, ContextCompat.getMainExecutor(this));
}
private void bindImageAnalysis(@NonNull ProcessCameraProvider cameraProvider) {
ImageAnalysis imageAnalysis =
new ImageAnalysis.Builder().setTargetResolution(new Size(640, 360))
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST).build();
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(this), new ImageAnalysis.Analyzer() {
@Override
public void analyze(@NonNull ImageProxy ip) {
processImage(ip.getImage(), ip.getImageInfo().getRotationDegrees());
ip.close();
}
});
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();
cameraProvider.bindToLifecycle((LifecycleOwner)this, cameraSelector, imageAnalysis);
}
在每个analyze
回调中,MLKit 都指示它
InputImage.fromMediaImage(ip.getImage(),ip.getImageInfo().getRotationDegrees()).getByteBuffer()
为空。我该如何解释这个?这是否总是意味着图像为空?