2016-01-06 58 views
1

我一直在爲Unity3D和Vuforia提供增強現實的項目。現在我想整合XZing從QR碼獲取數據並將這些信息顯示在我的一個Unity資產/對象中。將Unity3D與XZing集成

在包含XZing資產並將VuforiaScanner.cs腳本放在ARCamera上後,無法從相機設備對象加載圖像。

你知道如何解決這個問題或者知道一些將XZing實現到Vuforia/Unity3D的教程嗎?

這裏是VuforiaScanner.cs

using UnityEngine; 
using System; 
using System.Collections; 

using Vuforia; 

using System.Threading; 

using ZXing; 
using ZXing.QrCode; 
using ZXing.Common; 


[AddComponentMenu("System/VuforiaScanner")] 
public class VuforiaScanner : MonoBehaviour 
{  
    private bool cameraInitialized; 

    private BarcodeReader barCodeReader; 

    void Start() 
    {   
     barCodeReader = new BarcodeReader(); 
     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(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 
      { 
       /** 
       * AT THIS POINT CAMERAFEED IS NULL 
       **/ 
       var cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGB888); 
       if (cameraFeed == null) 
       { 
        return; 
       } 
       var data = barCodeReader.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); 
      } 
     } 
    }  
} 

感謝代碼段提前。

+0

VuforiaScanner.cs具有線VAR數據= barCodeReader.Decode(cameraFeed.Pixels,cameraFeed.BufferWidth,cameraFeed.BufferHeight,RGBLuminanceSource.BitmapFormat.RGB24)誤差; [https://i.stack.imgur.com/oMe7W.jpg] [enter image description here] – alimaha

回答

0

你谷歌

「Unity3D斑馬線」

?內有一個巨大的討論量,例如:

http://forum.unity3d.com/threads/zxing-library-with-unity.335017/

注意,因爲它說,

的iOS的WebCamTexture不會返回其應有的寬度和高度...

這是Unity3D的一個相當大的問題,已經有多年了,

http://answers.unity3d.com/answers/687987/view.html

private IEnumerator _workAroundRisibleUnityBug() 
    { 
    while (frontCam.width < 100) 
     { 
     Debug.Log("the width/height values are not yet ready."); 
     Debug.Log(frontCam.width +" " +frontCam.height); 
     yield return null; 
     } 

    Debug.Log("the width/height values are now meaningful."); 
    Debug.Log(frontCam.width +" " +frontCam.height);