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

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

问题描述

使用ARCore for Unity,尝试将Frame.CameraImage.AcquireCameraImageBytes()另存为图像并扫描图像以获取QR码.但是转换后的图像不是实际比例,而是重复的,因此无法正确推导QR码.

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

这是转换后的图像

这是怎么了

推荐答案

可从CPU以YUV-420-888格式访问其数据的ARCore摄像机图像

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天全站免登陆