unity Zxing 二维码扫描器集成 [英] Unity Zxing QR code scanner integration

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

问题描述

我需要将 Zxing 与 vuforia 集成以在 Unity 中制作二维码扫描应用程序吗?我不知道如何将 Zxing 与 Vuforia 统一集成.有人可以指导我如何做到这一点吗?我有 Zxing .dll 文件和 Vuforia 统一包.提前致谢.

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.

推荐答案

我今天想在 Unity 中将 Zxing 与 vuforia 集成.

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 二维码扫描器集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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