ARCore for Unity 保存相机图像 [英] ARCore for Unity save camera image

查看:41
本文介绍了ARCore for Unity 保存相机图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ARCore for Unity,尝试将 Frame.CameraImage.AcquireCameraImageBytes() 保存为图像并扫描图像以获取二维码.但是转换后的图片没有实际比例,而且是重复的,所以无法正确扣除二维码.

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.

这是我的代码

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();
            }
        }
    }
}

这是转换后的图像

这里有什么问题

推荐答案

一张 ARCore 相机图像,其数据可从 CPU 以 YUV-420-888 格式访问检查这个.YUV 的缓冲区大小为宽*高*1.5.您可能需要将 YUV 转换为 RGB 格式.

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.

这篇关于ARCore for Unity 保存相机图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆