Log in or register to post comments

ZXing with Vuforia

June 22, 2016 - 5:43am #1

We have implemented the QR detection functionality using ZXing.dll in Unity 5.3.4f1 with Vuforia Unity SDK 5.5.9. We have a QR detection script on GameObject which remains active throughout the app and using below mentioned (QRScanner.cs) code ( as mentioned on http://stackoverflow.com/questions/30546548/unity-zxing-qr-code-scanner-integration ).

We are also using Vuforia for image detection (50 image targets) in same scene where QR detection is expected. The Vuforia plugin is getting enabled / disabled multiple times as per our requirement. Both the image and QR detection is working perfectly for us on Android and iOS devices until app is in focus. Whenever VuforiaBehaviour gets disabled and enabled, QR detection stops working thereafter. QRScanner script always receives null data after app is resumed or AR camera is reloaded. We have tried keeping our QR detection script on AR camera prefab and also tried

VuforiaBehaviour.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated);
VuforiaBehaviour.RegisterQCARStartedCallback(OnTrackablesUpdated);

callbacks every time AR camera starts but with no success. The QR detection stops working completely after pausing Vuforia plugin for any reason.

Does anybody have any idea how to fix this issue ?

QRScanner.cs

    using UnityEngine;
    using System;
    using System.Collections;
    using Vuforia;
    using System.Threading;
    using ZXing;
    using ZXing.QrCode;
    using ZXing.Common;
  
    /*  ///////////////// QR detection does not work in editor //////////////// */
  
    [AddComponentMenu("System/QRScanner")]
    public class QRScanner : MonoBehaviour
    {  
     private bool cameraInitialized;
     private BarcodeReader barCodeReader;
     public AppManager camScript;
  
     void Start()
     {      
      barCodeReader = new BarcodeReader();
      StartCoroutine(InitializeCamera());
     }
  
     private IEnumerator InitializeCamera()
     {
      // Waiting a little seem to avoid the Vuforia's crashes.
      yield return new WaitForSeconds(3f);
  
      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);
         Application.OpenURL (data.Text);      // our function to call and pass url as text
         data = null;  // clear data
        }
        else
        {
         Debug.Log("No QR code detected !");
        }
       }
       catch (Exception e)
       {
        Debug.LogError(e.Message);
       }
      }
     }
    }

 

ZXing with Vuforia

May 9, 2017 - 3:11am #3

I try this way to decode QRcode ,and I get some problem.

 

QRcode Reading will be very slow. Because "barCodeReader.Decode" this method take too much time when app use vuforia. Can you fix it ?

ZXing with Vuforia

September 14, 2016 - 7:11am #2

How can I make this work with UPC-A barcodes??

Log in or register to post comments