title: ARCore – How to convert YUV camera frame to RGB frame in C#?
body: <p>I want to get the current Camera Image from the ARCore session. I am using the <code>Frame.CameraImage.AcquireCameraImageBytes()</code> method to get this image. Then i am loading this image to a <code>Texture2D</code> in format of <code>TextureFormat.R8</code>. But the texture is red and upside down. I know that the format ARCore using is YUV but i could not find a way to convert this format to RGB. How can i do this?</p>
  
  <p>There are 2 or 3 questions about this issue but no solution is given.</p>
  
  <p>Code is given below:</p>
  
  <pre class="lang-cs prettyprint-override"><code>CameraImageBytes image = Frame.CameraImage.AcquireCameraImageBytes();
  int width = image.Width;
  int height = image.Height;
  int size = width*height;
  
  
  Texture2D texture = new Texture2D(width, height, TextureFormat.R8, false, false);
  byte[] m_EdgeImage = new byte[size];
  
  System.Runtime.InteropServices.Marshal.Copy(image.Y, m_EdgeImage, 0, size);
  
  texture.LoadRawTextureData(m_EdgeImage);
  texture.Apply();
  </code></pre>
  
  <p>Result image:</p>
  
  <p><a href="https://i.stack.imgur.com/E77Sp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E77Sp.jpg" alt="enter image description here"></a></p>