"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Camera very laggy

First of all i have combined vuforia with ZXing QR library. What i want to achieve:

Before showing the object I want to get the DATA from the QR code.

 

Problem:

Camera is laggy even after QR scan

 

This is my script: (Added it as attachment aswell)


using ZXing;
using UnityEngine;
using Vuforia;
using System;
using UnityEngine.UI;

public class Personizer : MonoBehaviour, ITrackableEventHandler
{

#if UNITY_EDITOR
    private Vuforia.Image.PIXEL_FORMAT mPixelFormat = Vuforia.Image.PIXEL_FORMAT.GRAYSCALE;
#elif UNITY_ANDROID
   private Vuforia.Image.PIXEL_FORMAT mPixelFormat =  Vuforia.Image.PIXEL_FORMAT.RGB888;
#elif UNITY_IOS
    private Vuforia.Image.PIXEL_FORMAT mPixelFormat =  Vuforia.Image.PIXEL_FORMAT.RGB888;
#endif

    private bool mFormatRegistered = false;

    private bool scannedQR;
    private bool canSeeTarget;
    private string qrData;

    public Text debugText;
    public TrackableBehaviour mTrackableBehaviour;

    void Start () {
        Application.targetFrameRate = 60;

        scannedQR = false;
        canSeeTarget = false;

        VuforiaARController.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated);
        VuforiaARController.Instance.RegisterOnPauseCallback(OnPause);
        VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);

        var isAutoFocus = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
        if (!isAutoFocus)
        {
            CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL);
        }
    }

    void OnVuforiaStarted()
    {
        StartSearchingQR();

        mTrackableBehaviour.RegisterTrackableEventHandler(this);
    }

    void StartSearchingQR()
    {
        RegisterFormat();
    }

    private void OnTrackablesUpdated()
    {
        if (!scannedQR)
        {
            if (mFormatRegistered)
            {
                Vuforia.Image image = CameraDevice.Instance.GetCameraImage(mPixelFormat);

                if (image != null)
                {
                    try
                    {
                        IBarcodeReader barcodeReader = new BarcodeReader();
                        // decode the current frame
                        var result = barcodeReader.Decode(image.Pixels, image.BufferWidth, image.BufferHeight, RGBLuminanceSource.BitmapFormat.RGB24);

                        if (result != null)
                        {
                            scannedQR = true;
                            UnregisterFormat();
                            qrData = result.Text;
                            debugText.text = result.Text;

                            if (canSeeTarget)
                                mTrackableBehaviour.gameObject.SetActive(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogWarning(ex.Message);
                    }
                }
            }
        }
    }

    public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
        newStatus == TrackableBehaviour.Status.TRACKED ||
        newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            OnTrackingFound();
        }
        else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
                 newStatus == TrackableBehaviour.Status.NOT_FOUND)
        {
            OnTrackingLost();
        }
        else
        {
            OnTrackingLost();
        }
    }

    private void OnTrackingFound()
    {
        //PlayAnimations();
        canSeeTarget = true;
        if (!scannedQR)
        {
            mTrackableBehaviour.gameObject.SetActive(false);
        }
    }

    private void OnTrackingLost()
    {
        canSeeTarget = false;
        //StopAnimations();
    }

    #region Vuforia
    void OnPause(bool paused)
    {
        if (!scannedQR)
        {
            if (paused)
            {
                UnregisterFormat();
            }
            else
            {
                RegisterFormat();
            }
        }
    }

    void RegisterFormat()
    {
        if (CameraDevice.Instance.SetFrameFormat(mPixelFormat, true))
        {
            mFormatRegistered = true;
        }
        else
        {
            mFormatRegistered = false;
        }
    }

    void UnregisterFormat()
    {
        CameraDevice.Instance.SetFrameFormat(mPixelFormat, false);
        mFormatRegistered = false;
    }
    #endregion
}

 

But my camera is a bit laggy now?

You're passing around of a ton of image data per second.  You gotta be smart with the way you handle that data.  Some things to try:

Attachment