Unity3D 生成&识别二维码

本文介绍了如何在Unity3D中实现二维码的扫描识别和生成。使用WebCamTexture获取摄像头数据并显示在UI上,通过指定摄像头名称选择后置摄像头。利用zxing库间隔0.2秒进行一次二维码识别。同时,详细阐述了如何将字符转化为二维码的Color32数组,并将其显示在UI上的过程。想了解更多Unity2018教程,可以访问paws3d爪爪学院或加入学习讨论群。
摘要由CSDN通过智能技术生成

Unity扫描识别二维码

用WebCamTexture 获得摄像头数据,并把他付给UI层的RawImage.这个用来展示摄像头拍摄的内容画面。

private void CreateWebcamTex(string deviceName)
{
    mWebCamTexture = new WebCamTexture(deviceName,1280, 720);
    rawImage.texture = mWebCamTexture;
    mWebCamTexture.Play();
}

上面的函数需要传入 摄像头的名称,因为手机可能有前后置两个摄像头,需要选择后置摄像头的名称

WebCamDevice[] devices = WebCamTexture.devices; 
foreach (var item in devices){
     if(!item.isFrontFacing)
     {
           CreateWebcamTex(item.name);
           break;
    }   
}

zxing解析摄像头texture内容

    private BarcodeReader mReader;
    public string Decode(Color32[] colors, int width, int height)
    {
            var result = mReader.Decode(colors, width, height);
            if (result != null)
            {
                return result.Text;
            }
            return null;
    }

没必要每帧都去识别&

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值