ARCore for Unity save camera image

蹲街弑〆低调 提交于 2019-12-31 07:17:13

问题


Using ARCore for Unity, trying to save Frame.CameraImage.AcquireCameraImageBytes() as image and scanning the image for QR code. But the converted image is not in actual scale and it is repeating, so not able to deduct the QR code correctly.

Here is my code

void Update()
{
using (var image = Frame.CameraImage.AcquireCameraImageBytes())
    {
        if (image.IsAvailable)
        {               

            byte[] m_EdgeImage = null;
            Color32[] pixels = null;
            IParser Parser = new ZXingParser();
            if (_texture == null || m_EdgeImage == null || _texture.width != image.Width || _texture.height != image.Height)
            {
                _texture = new Texture2D(image.Width, image.Height, TextureFormat.RGBA32, false, false);                    
                m_EdgeImage = new byte[image.Width * image.Height*4];           

            }
            System.Runtime.InteropServices.Marshal.Copy(image.Y, m_EdgeImage, 0, image.Width * image.Height);               
            _texture.LoadRawTextureData(m_EdgeImage);
            _texture.Apply();       

            ParserResult Result = Parser.Decode(pixels, _texture.width, _texture.height);
            if (Result != null)
            {
                Debug.Log("QRCODE");

            }
            else
            {               
                var encodedJpg = _texture.EncodeToJPG();
                var path = Application.persistentDataPath;
                File.WriteAllBytes(path + "/test.jpg", encodedJpg);             
                Debug.Log("NOQRCODE");
                Application.Quit();
            }
        }
    }
}

Here is the converted image

What is wrong here


回答1:


An ARCore camera image with its data accessible from the CPU in YUV-420-888 formatCheck this. The buffer size is width*height*1.5 for YUV. You may need to convert YUV to RGB format.



来源:https://stackoverflow.com/questions/49798067/arcore-for-unity-save-camera-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!