stereolabs / zed-unity

ZED SDK Unity plugin
https://www.stereolabs.com/documentation/guides/using-zed-with-unity/introduction.html
MIT License
250 stars 57 forks source link

ZED Mini Texture2D retrieval issue #241

Closed Huang0504 closed 1 year ago

Huang0504 commented 1 year ago

Preliminary Checks

Proposal

Hi,I has a serval question for ZED unity SDK,I want to retrieve the Texture2D of camera,so I check ZEDRenderingPlane.cs and use the TextureEye attribute ,but when I use the getpixel() to read camtexture to other texture2d , it doesnt work,the new texture can not see anything, here is part of code I wrote,when I press space and tmp is correct camera texture but the texture is whole gray texture.

public Texture2D texture;
public Texture2D tmp;
public GameObject frame;//gameobject of ZED Rendering Plane
private void LateUpdate()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                tmp = frame.GetComponent<ZEDRenderingPlane>().TextureEye;
                texture=ChangeFormat(tmp, TextureFormat.RGBA32);
            }

        }
public Texture2D ChangeFormat(Texture2D oldTexture, TextureFormat newFormat)
        {
            //Create new empty Texture
            Texture2D newTex = new Texture2D(oldTexture.width,oldTexture.height, newFormat, false);
            //Copy old texture pixels into new one

            newTex.SetPixels(oldTexture.GetPixels());
            //Apply
            newTex.Apply();
            return newTex;
        }

Use-Case

No response

Anything else?

No response

Bvallon-sl commented 1 year ago

Hi,

I think the issue is coming from the way you are copying the texture to the new one, as you said the "tmp" texture is correct.

You should try using functions like Graphics.CopyTexture() or Graphics.ConvertTexture() instead.

Best,

Benjamin Vallon

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days