Is there a way to access the current camera frame in Unity?

0 votes
asked Apr 23, 2018 by ngc6543 (1,670 points)
Hi, I'm trying to access the camera frame when an image target is recognized. I thought the CameraDeviceBehaviour would expose a Texture2D or IntPtr for the native Texture, but could not find any. I'm not trying to record the screen content into a video, just trying to capture the camera's image frame at a certain moment. Is this not possible?

1 Answer

0 votes
answered Apr 23, 2018 by albert52 (31,850 points)
selected Apr 24, 2018 by ngc6543
commented Apr 23, 2018 by ngc6543 (1,670 points)
Hey, thanks for the quick reply.
I tried to get the current frame by adding an event listener to `ARCameraBehaviour.FrameUpdate`.

void EasyARCam_FrameUpdate(ARCameraBaseBehaviour arg1, Frame arg2)

{

Debug.Log("Frame Format : " + arg2.Images[0].Format);

Debug.Log("Frame update : " + arg2.Images[0].Width + "x" + arg2.Images[0].Height);

   
crntFrameImage = arg2.Images[0];
if (capturedTex.width != crntFrameImage.Width)
   
{

  capturedTex = new Texture2D(crntFrameImage.Width, crntFrameImage.Height);
           
  Resources.UnloadUnusedAssets();

}
       
  capturedTex.LoadImage(crntFrameImage.Pixels);
       
  capturedTex.Apply();
       
  //capturedTex.LoadRawTextureData(arg2.Images[0].Pixels);
       
  //capturedTex.Apply();
        
   
}


The Frame format was BGR888, and the Image.Width, Height were as expected. But the above code doesn’t get images. `capturedTex` is expected to have 1280x720 image, but instead it has 8x8 red ‘question mark` instead. Is Capturing from FrameUpdate is for PRO-only feature??
commented Apr 24, 2018 by ngc6543 (1,670 points)
Never mind. I got it working. Thanks anyway!
commented Apr 24, 2018 by albert52 (31,850 points)
You're welcome
commented Jul 3, 2019 by emanuel (390 points)
How did you make it work?
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...