Java Android图像阅读器运动检测
我正在开发一个应用程序,它必须能够基于androids camera2 API进行运动检测。所以我正在使用一个图像阅读器和相应的OnImageAvailableListener。我有两个用于CameraCaptureSession帧的目标曲面,即显示相机预览的UI SurfaceTexture和ImageReaders曲面 我有点“被迫”使用ImageFormat.YUV_420_88,原因与本问题中提到的相同: 我对这种格式有点陌生,我需要实现一个运动检测 我的想法是以像素为单位遍历Image.getPlanes()[i].getBuffer(),并根据某个阈值比较两个图像 我有两个问题:Java Android图像阅读器运动检测,java,android,image-processing,image-formats,android-camera2,Java,Android,Image Processing,Image Formats,Android Camera2,我正在开发一个应用程序,它必须能够基于androids camera2 API进行运动检测。所以我正在使用一个图像阅读器和相应的OnImageAvailableListener。我有两个用于CameraCaptureSession帧的目标曲面,即显示相机预览的UI SurfaceTexture和ImageReaders曲面 我有点“被迫”使用ImageFormat.YUV_420_88,原因与本问题中提到的相同: 我对这种格式有点陌生,我需要实现一个运动检测 我的想法是以像素为单位遍历Imag
mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
Image image = null;
try {
image = imageReader.acquireLatestImage();
if (null == image) {
return;
}
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
detectMotion(bytes);
} finally {
if (image != null) {
image.close();
}
}
}
private void detectMotion(byte[] frame) {
if (null == frame) {
return;
}
int ret = NativeUtil.detectMotion(frame);
if (ret == 1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mIvMotion.setVisibility(View.VISIBLE);
}
});
Log.d(TAG, "Detected motion event");
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
mIvMotion.setVisibility(View.INVISIBLE);
}
});
}
}
};
NativeUtil.detectMotion在哪里?