Unity Zxing QR码扫描仪集成 [英] Unity Zxing QR code scanner integration

查看:240
本文介绍了Unity Zxing QR码扫描仪集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将Zxing与vuforia集成在一起,以便在Unity中创建QR码扫描应用程序? 我不知道如何将Zxing与Vuforia集成在一起,有人可以指导我如何做吗?我有Zxing .dll文件和Vuforia unity软件包.

I need to integrate Zxing with vuforia to make a QR code scanning app in Unity? I have no idea how to integrate Zxing with Vuforia in unity.Can someone guide me how to do this?I have Zxing .dll files and Vuforia unity package.Thanks in Advance.

推荐答案

我今天正在寻找将Zxing与vuforia集成到Unity中的方法.

I was looking for integrating Zxing with vuforia in Unity today.

要做的第一件事是从以下位置下载dll: https://zxingnet.codeplex.com/,然后将unity dll复制到您的Plugins文件夹(应该在Assets文件夹中)

The first thing to do is to download the dll from : https://zxingnet.codeplex.com/ and copy the unity dll into your Plugins folder (which should be in the Assets folder)

然后,我设法找到了一些示例(其中有些已经过时):

Then, I managed to found some examples (some of theses is outdated) :

https://github .com/Redth/ZXing.Net/blob/master/Clients/VuforiaDemo/Assets/VuforiaScanner.cs

合并这些示例并简化它们之后,我得到了类似的内容(放置在ARCamera预制件中):

After merging theses examples and simplify them, I got something like this (which is placed of the ARCamera prefab) :

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);
            }
        }
    }    
}

我设法使其能够在AVD(Android虚拟设备)中运行,因此它将在真实设备上运行.

I manage to make it works in an AVD (Android Virtual Device), so it will works on a real device.

这篇关于Unity Zxing QR码扫描仪集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆