Hus*_*123 9 qr-code barcode-scanner unity-game-engine zxing vuforia
我需要将Zxing和vuforia集成在Unity中制作QR码扫描应用程序吗?我不知道如何将Zxing与Vuforia整合在一起.有人可以指导我如何做到这一点吗?我有Zxing .dll文件和Vuforia统一包.谢谢你.
我今天正在寻找将Zxing与vuforia整合在Unity中.
首先要从https://zxingnet.codeplex.com/下载dll 并将unity dll复制到Plugins文件夹(应该在Assets文件夹中)
然后,我设法找到了一些例子(有些论文已经过时):
http://ydaira.blogspot.fr/2012/09/how-to-decode-qr-codes-using-unity3d.html
https://github.com/Redth/ZXing.Net/blob/master/Clients/VuforiaDemo/Assets/VuforiaScanner.cs
在合并这些示例并简化它们之后,我得到了类似的东西(放置在ARCamera预制件中):
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
{
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);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我设法让它在AVD(Android虚拟设备)中运行,因此它可以在真实设备上运行.
| 归档时间: |
|
| 查看次数: |
22493 次 |
| 最近记录: |