Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Why i can not get texture by API "Frame.CameraImage.Texture"? #330

Closed
dvlee1024 opened this issue Jul 31, 2018 · 8 comments
Closed

Why i can not get texture by API "Frame.CameraImage.Texture"? #330

dvlee1024 opened this issue Jul 31, 2018 · 8 comments

Comments

@dvlee1024
Copy link

dvlee1024 commented Jul 31, 2018

I want to save texture from rear camera into sdcard. But when i get texture by the API "Frame.CameraImage.Texture" on my phone , i can only get a 0:0 size texture?

    Texture2D texture = (UnityEngine.Texture2D)Frame.CameraImage.Texture;
    if(texture == null) {
        SFLog.d("no texture");
        return;
    }
    SFLog.d("bg texture: "+texture.width + ":" + texture.height); // output 0:0
   
    string savePath = "/sdcard/DCIM/a.jpg";
    saveTextureToPath(texture,savePath);
@dvlee1024
Copy link
Author

I found these #306, #221

@pablisho
Copy link
Contributor

Hi, this is expected behaviour, that's an external texture and cannot be used for that. To do CPU image access you have to use Frame.CameraImage. AcquireCameraImageBytes or use the TextureReaderApi. I would suggest that you take a look a the ComputerVision example. Let me know if this solves your question.

@dvlee1024
Copy link
Author

dvlee1024 commented Aug 1, 2018

@pablisho

We can only get the separated data like just Y data or U data as the code below. It is not convenient for me.

        using (CameraImageBytes image = Frame.CameraImage.AcquireCameraImageBytes())
        {
            if (!image.IsAvailable)
            {
                return;
            }

            int size = image.Width * image.Height;
            byte[] yBuff = new byte[size];
            System.Runtime.InteropServices.Marshal.Copy(image.Y, yBuff, 0, size);

            if(texture == null) {
                texture = new Texture2D(image.Width, image.Height, TextureFormat.R8, false,false);
            }
            texture.LoadRawTextureData(yBuff);
            texture.Apply();

            rawImage.texture = texture;
        }

I use screenshot insteaded.

Texture2D screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24,false);  
 screenShot.ReadPixels(new Rect(0,0,Screen.width,Screen.height), 0, 0);  
screenShot.Apply();

@dvlee1024
Copy link
Author

@pablisho hi, why I cannot get CameraImageBytes on Mi8 device?
When I try to get CameraImageBytes on Mi8 device, console show the following log and failed to get the data.
But I can get it on other device. Something wrong with my code or my Mi8 device?

08-04 13:45:37.943  9876  9965 E native  : filter_update_base.cc:83 Mapped visual feature update failed when computing its residual and Jacobian.
08-04 13:45:37.979  9876  9895 E native  : status.cc:158 ArStatusErrorSpace::AR_ERROR_NOT_YET_AVAILABLE: 
08-04 13:45:37.979  9876  9895 W Unity   : Failed to acquire camera image with status ErrorNotYetAvailable
using (var image = Frame.CameraImage.AcquireCameraImageBytes())
                {
                    if (!image.IsAvailable)
                    {
                        print("IsAvailable");
                        return;
                    }
                    print("get it");
                }

@pablisho
Copy link
Contributor

pablisho commented Aug 6, 2018

Hi, @dvlee1024 CameraImageBytes comes in YUV format and we don't provide conversions because there are many libraries already doing that.
Thanks for reporting the Mi8 issue. We'll be looking further into it and I'll let you know if we were able to reproduce it.

@dvlee1024
Copy link
Author

@pablisho Any update of the Mi8 issue?

@chaosemer
Copy link
Contributor

Sorry for the delayed reply. Most Xiaomi devices have a known issue where the CPU image access does not reliably work. If you want to support these devices, you will need to copy the GPU image to CPU using the TextureReader code in the ComputerVision sample.

@fredsa
Copy link
Member

fredsa commented Dec 21, 2018

We've updated the ARCore support devices page to indicate which devices do not currently support CPU image access.

@fredsa fredsa closed this as completed Feb 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants