【发布时间】:2017-02-17 04:22:09
【问题描述】:
我正在尝试从 HoloLens 获取一个简单的 Vuforia 图像,并将其转换为将 QRCodes 转换为文本的函数(通过 ZXing)。我已经导入了 ZXing 库,在阅读了类似的实现后发现下面的实现是最简单的形式。
其实很简单,步骤是
- 首先设置条形码对象
- 初始化相机
-
将二维码的文本值发送到控制台
using UnityEngine; using System; using System.Collections; using UnityEngine.UI; using Vuforia; using ZXing; public class HelloWorldV2 : MonoBehaviour { private bool cameraInitialized; private BarcodeReader barReader; void Start() { GameObject sometext = GameObject.Find("Text"); Text txt = sometext.GetComponent<Text>(); txt.text = "Right before BarReader"; barReader = new BarcodeReader(); txt.text = "Right after BarReader"; //NEVER GETS HERE! StartCoroutine(InitializeCamera()); } private IEnumerator InitializeCamera() { // Waiting a little seem to avoid the Vuforia's crashes. yield return new WaitForSeconds(1.25f); var isFrameFormatSet = CameraDevice.Instance.SetFrameFormat(Vuforia.Image.PIXEL_FORMAT.RGB888, true); Debug.Log(String.Format("FormatSet : {0}", isFrameFormatSet)); // Force autofocus. var isAutoFocus = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); if (!isAutoFocus) { CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL); } Debug.Log(String.Format("AutoFocus : {0}", isAutoFocus)); cameraInitialized = true; } private void Update() { if (cameraInitialized) { try { var cameraFeed = CameraDevice.Instance.GetCameraImage(Vuforia.Image.PIXEL_FORMAT.RGB888); if (cameraFeed == null) { return; } var data = barReader.Decode(cameraFeed.Pixels, cameraFeed.BufferWidth, cameraFeed.BufferHeight, RGBLuminanceSource.BitmapFormat.RGB24); if (data != null) { // QRCode detected. Debug.Log(data.Text); } else { Debug.Log("No QR code detected !"); } } catch (Exception e) { Debug.LogError(e.Message); } } } }
所以问题只是在构造函数调用BarcodeReader() 时发生。我不确定这将如何发生。为什么简单的构造函数调用会失败?
我从调试会话中得到的唯一其他提示如下:
FileLoadException: Could not load file or assembly 'System.Core,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of
its dependencies. The located assembly's manifest definition does not match
the assembly reference. (Exception from HRESULT: 0x80131040)
at ZXing.BarcodeReader..ctor()
at HelloWorldV2.Start()
有人可以通过 VisualStudio 的模拟器复制这个问题吗? (注意,在将 FrameFormats 替换为灰度时,这在 Unity 中有效。
【问题讨论】:
标签: c# unity3d zxing vuforia hololens