Search Unity

Getting camera image pixels with ARCore SDK

Discussion in 'AR' started by jariwake, Sep 10, 2018.

  1. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    I need to get an access to the pixels of the device camera when using ARCore SDK (1.4) in Unity (2018.2.5f1).

    I found examples that show how this should be possible by using TextureReader and its OnImageAvailableCallback event. But it never gets fired. I debugged it and it seems that the following line in TextureReader.cs causes pixelBuffer to always be zero and therefore the
    OnImageAvailableCallback never gets called:

    IntPtr pixelBuffer = m_TextureReaderApi.AcquireFrame(m_ImageBufferIndex, ref bufferSize);

    I have added the TextureReader to my scene (to the First Person Camera gameobject) and subscribed to the
    OnImageAvailableCallback event in my custom script.

    Is the TextureReader somehow broken? I would need the grayscale camera frame because I want to do some computer vision stuff on it.

    In ARFoundation I am able to do this (although it is really slow) with the Graphics.Blit() and RenderTexture, but I cannot use ARFoundation because it currently lacks the support for Image Targets (which I need in my project). And Vuforia is out of the question because it is currently lacking support for continuous autofocus.


    Edit: It seems that the TextureReader has been replaced with Frame.CameraImage.AcquireCameraImageBytes(). Guys at Google just havent removed TextureReader from the ARcore SDK yet, which causes confusion..
     
    Last edited: Sep 11, 2018
  2. smokegun

    smokegun

    Joined:
    Dec 13, 2012
    Posts:
    170
    Hey,

    I am trying to figure out the same thing. I need the pixels to combine QR reading.
    Did you get it to work? and can you please post your snippet?
     
  3. Hooligan-Labs

    Hooligan-Labs

    Joined:
    Dec 19, 2012
    Posts:
    4
    I'm also interested in this, also for QR code reading.