Считыватель QR-кодов с использованием Vuforia, Unity & Zxing - PullRequest
1 голос
/ 15 марта 2019

Я разрабатываю декодер QR-кода для своего проекта.

Я взял ссылку от Интеграция сканера QR-кода Unity Zxing

Я использую Unity 2018+ и Vuforia 7+. Может ли кто-нибудь помочь мне, где я допустил ошибку?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
using ZXing;

using System;


[AddComponentMenu("System/QRScanner")]
public class QRScanner : 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.GRAYSCALE, 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.GRAYSCALE);
                    if (cameraFeed == null)
                    {
                        return;
                    }
                    var data = barCodeReader.Decode(cameraFeed.Pixels, cameraFeed.BufferWidth, cameraFeed.BufferHeight, RGBLuminanceSource.BitmapFormat.RGB24);
                    if (data != null)
                    {
                    // QRCode detected.
                    Debug.Log("Detected");
                        Debug.Log(data.Text);
                    }
                    else
                    {
                        Debug.Log("No QR code detected !");
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message);
                }
            }
        }
    }

Результат прямо сейчас: "QR-код не обнаружен". Цель, которую я использую, работая над другим приложением для чтения кода qr

...