Convert Android camera2 api YUV_420_888 to RGB

后端 未结 7 883
暗喜
暗喜 2020-12-14 02:56

I am writing an app that takes the camera feed, converts it to rgb, in order to do some processing.

It works fine on the old camera implementation which uses NV21 Y

7条回答
  •  抹茶落季
    2020-12-14 03:27

    Approximately 10 times faster than the mentioned "imageToMat"-Function above is this code:

    Image image = reader.acquireLatestImage();
    ...
    Mat yuv = new Mat(image.getHeight() + image.getHeight() / 2, image.getWidth(), CvType.CV_8UC1);
    ByteBuffer buffer = image.getPlanes()[0].getBuffer();
    final byte[] data = new byte[buffer.limit()];
    buffer.get(data);
    yuv.put(0, 0, data);
    ...
    image.close();
    

提交回复
热议问题