This is an Android Library that allows Unity to get the camera preview frames in real time. It is based on the Camera2 API. The basic idea is to use ImageReader to get the camera preview frames in YUV format, and then pass them to Unity as a YUV texture.
Unity will then convert the YUV texture to an RGB texture and display it on the screen.
./gradlew YUV420_888:assemble- Use it as an AndroidJavaObject in Unity
- You need two Texture2D objects in Unity to display the camera preview frames. One is for Y plane (TextureFormat.R8), the other is for UV plane (TextureFormat.RG16).
- You need a shader to convert YUV texture to RGB texture. Check YCbCr to RGB Conversion matrix.
- You need to set the shader to the material of the RawImages that you want to display the camera preview frames.
- Done
This is a small part of my research project prototype. It is not ready for production. And it only tested on Samsung S23 and S21.
Use it at your own risk.
The full project may be released in the future if requested by the academic peer reviewers.