简单的Vuforia到HoloLens

时间:2017-02-17 04:22:10

标签: c# unity3d zxing vuforia hololens

我试图从HoloLens获得一个简单的Vuforia图像到一个将QRCodes转换为文本的功能(通过ZXing)。我已经导入了ZXing库,在阅读了类似的实现后发现下面的实现是最简单的形式。

实际上很简单,步骤是

  1. 首先设置条形码对象
  2. 初始化相机
  3. 将QRcode的文本值发送到控制台

    Guid
  4. 因此问题只发生在对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()

    有人可以通过VisualStudio的模拟器复制问题吗? (注意,在将FrameFormats替换为灰度时,这在Unity中有效。

2 个答案:

答案 0 :(得分:1)

我能够根据这篇博文建立一个使用ZXing在HoloLens上扫描二维码的工作解决方案:

https://mtaulty.com/2016/12/28/windows-10-uwp-qr-code-scanning-with-zxing-and-hololens/

答案 1 :(得分:1)

那是因为你使用了错误的dll文件(hololens不支持)。试试ZXing.net中的winmd文件