unity Vuforia + 二维码解析 使用同一个摄像机
来源:互联网 发布:包天下网络怎么赚钱 编辑:程序博客网 时间:2024/05/16 12:32
在unity中,使用Vuforia并且实现同一相机扫描二维码。网上有几个教程,但是会遇到当应用被暂停以后二维码扫描不正确,主要原因来自于Vuforia的一个问题。查了很久才解决,在此记录,希望能帮到遇到同样问题的你们。
using UnityEngine;using System.Collections;using Vuforia;using ZXing;using ZXing.Client.Result;public class ScanCodeBehaviour : MonoBehaviour { VuforiaBehaviour vuforia; bool decoding; bool init; BarcodeReader barcodeReader = new BarcodeReader(); bool posting; void Awake() { vuforia = this.GetComponent<VuforiaBehaviour>(); vuforia.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated); } // Use this for initialization void Start () { } void Update() { if (vuforia == null) return; if (vuforia.enabled && !init) { //Wait 1/4 seconds for the device to initialize (otherwise it seems to crash sometimes) init = true; Loom.QueueOnMainThread(() => {//这里必须先设置false,再设置true!!! CameraDevice.Instance.SetFrameFormat(Vuforia.Image.PIXEL_FORMAT.RGB888, false); init = CameraDevice.Instance.SetFrameFormat(Vuforia.Image.PIXEL_FORMAT.RGB888, true); posting = false; }, 0.25f); } } void OnApplicationFocus(bool value) { if (value == false) { } else {//失去焦点后需要重新init init = false; } } public void Reinit() { init = false; } // Update is called once per frame void OnTrackablesUpdated() { if (vuforia.enabled && CameraDevice.Instance != null && !decoding && !posting) { Vuforia.Image image = CameraDevice.Instance.GetCameraImage(Vuforia.Image.PIXEL_FORMAT.RGB888); if (image != null) { decoding = true; Loom.RunAsync(() => { try { Result data = barcodeReader.Decode(image.Pixels, image.BufferWidth, image.BufferHeight, RGBLuminanceSource.BitmapFormat.RGB24); if (data != null) { Loom.QueueOnMainThread(() => { Debug.LogError(data.Text); }); } } finally { decoding = false; } }); } } } }
重点就两点,一点是应用失去焦点返回后需要重新init,第二是,重新init的时候需要把原有的format设置成false,不然不可用。。
阅读全文
0 0
- unity Vuforia + 二维码解析 使用同一个摄像机
- Unity+Vuforia+ZXing解析二维码
- vuforia + zxing 解析二维码
- Unity+Vuforia ar 摄像机自动对焦
- unity ~ vuforia的入门使用
- Unity如何深入使用Vuforia
- unity 调用手机摄像机 识别二维码
- Vuforia打开关闭摄像机
- unity功能记录--使用摄像机
- unity使用vuforia实现模型AR效果
- 使用unity插件vuforia进行AR开发
- unity perspective透视摄像机和orthographic正交摄像机解析
- Unity摄像机的使用二:摄像机的切换
- Unity摄像机
- Unity 摄像机
- unity 摄像机
- Vuforia SDK---- AR开发vuforia 二维码扫描
- 使用unity + Vuforia实现脱卡识别,多目标情况
- Linux——利用Shell脚本编写进度条
- lintcode[156]:合并区间
- 学习笔记---绘制文字
- Git修改分支名称
- 安卓低功耗蓝牙(BLE)开发教程
- unity Vuforia + 二维码解析 使用同一个摄像机
- PAT乙级1027. 打印沙漏(20)
- adb shell dumpsys SurfaceFlinge 分析
- 初见蓝桥——历年试题 小朋友排队
- linux之浅谈crond和crontab
- GreenDao3.0框架使用详解
- Git 入门
- MediaCodec类中queueInputBuffer
- PHP 取出本月,本季度,本年,上月,上季度,上一年的开始和结束日期