Integration with Unity Zxing QR Code Integration

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

+6
source share
2 answers

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

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

Then I managed to find some examples (some of these points are outdated):

After combining the examples of examples and simplifying them, I got something like this (which is placed in the prefab 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 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); } } } } 

I managed to get it to work in AVD (Android Virtual Device), so it will work on a real device.

+7
source

If you are using Unity 5.x and 64-bit Windows, you may receive an error message

Failed to load Assets / Plugins / QCARWrapper.dll

The solution is simple, as indicated in the Unity3d question - Failed to load "Assets / Plugins / QCARWrapper.dll"

  • To use Vuforia with Unity 64 bits, simply move the QCARWrapper libraries from /Plugins to /Plugins/x86. These are the DLLs:

  • Select QCARWrapper.bundle in the Unity project view (located under Assets> Plugins) so that its parameters are displayed in the Unity inspector. Change the QCARWrapper.bundle settings in the Unity inspector from any platform to a standalone + Editor.

How it works, like a charm.

+1
source

Source: https://habr.com/ru/post/988219/


All Articles