在我的方法中,我使用OpenCV Mat和脚本
https://gist.github.com/camdenfullmer/dfd83dfb0973663a7974
首先,使用上面链接中的代码将YUV_420_888图像转换为Mat.
* mImage是我在ImageReader.OnImageAvailableListener中获得的Image对象
Mat mYuvMat = imageToMat(mImage);
public static Mat imageToMat(Image image) {
ByteBuffer buffer;
int rowStride;
int pixelStride;
int width = image.getWidth();
int height = image.getHeight();
int offset = 0;
Image.Plane[] planes = image.getPlanes();
byte[] data = new byte[image.getWidth() * image.getHeight() * ImageFormat.getBitsPerPixel(ImageFormat.YUV_420_888) / 8];
byte[] rowData = new byte[planes[0].getRowStride()];
for (int i = 0; i < planes.length; i++) {
buffer = planes[i].getBuffer();
rowStride = planes[i].getRowStride();
pixelStride = planes