我一直致力于一个为Unity3D和Vuforia提供增强现实的项目。现在我想整合XZing以从QR码获取数据并在我的一个Unity资产/对象中显示这些信息。
在包含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 :(得分:0)
你有谷歌
" Unity3D ZXing"
?有大量的讨论,例如:
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);