Hi,
I’ve been trying to get xzing to read barcodes from the android camera via [KudanAR][1], as far as I can tell everything I’ve done so far should work however it never manages to find a QR code within the image.
Any ideas on what I’m doing wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZXing;
using ZXing.QrCode;
public class QR : MonoBehaviour
{
public Text QROutputText;
Texture2D camTex;
Color32 camPix;
void Update ()
{
try
{
IBarcodeReader barcodeReader = new BarcodeReader ();
camTex = SystemManager.instance._kudanTracker._trackerPlugin.GetTrackingTexture() as Texture2D;
camPix = RotateMatrix(camTex.GetPixels32(), camTex.height);
camTex.SetPixels32(camPix);
var result = barcodeReader.Decode(camTex.GetPixels32(), camTex.width, camTex.height);
if (result != null)
{
QROutputText.text = "Scanned Text : " + result.Text;
Debug.Log ("DECODED TEXT FROM QR:" + result.Text);
}
else
{
QROutputText.text = "No QR code detected";
//Debug.Log ("NO BARDCODE DETECTED");
}
}
catch (Exception ex)
{
Debug.LogWarning (ex.Message);
}
}
static Color32[] RotateMatrix(Color32[] matrix, int n) {
Color32[] ret = new Color32[n * n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
ret[i*n + j] = matrix[(n - j - 1) * n + i];
}
}
return ret;
}
}
Thanks
[1]: https://www.kudan.eu/