humble_pianist
humble_pianist

Reputation: 3

How do I get a byte[] of the camera frame in unity?

I am relatively new to Unity. I was wondering how I could get the byte[] frame of the virtual main camera in Unity.

I couldn't find any tutorials online?

Upvotes: 0

Views: 625

Answers (2)

Wolfram
Wolfram

Reputation: 502

See the example here:

https://docs.unity3d.com/ScriptReference/Texture2D.ReadPixels.html

The idea here is to attach yourself to the render pipeline, using the callback OnPostRenderCallback(). Here you should have direct access to the frame buffer, and can directly read pixels from the active render target with destinationTexture.ReadPixels(...). Instead of the destinationTexture.Apply() (which uploads the texture to the GPU, which you do not require), you can just dump the content of the texture into a byte array: byte[] myRawPixelData=destinationTexture.GetRawTextureData().

Upvotes: 0

Morion
Morion

Reputation: 10860

You can use RenderTexture for this:

Upvotes: 0

Related Questions