reading barcodes and qr codes using kudan with zxing
HI,
Im trying to add qr code reading to kudan by adding zxing to it also.
This is the code i have got so far to grab the vdeo texture from kuda, convert to color32 then get zxing to decode it.
If i put a texture in instead of trying to get it from the camera (comment out line first line inside the if in the update) the decoding works beautifully
so im not sure what i am missing
using System.Threading;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZXing;
using ZXing.QrCode;
namespace Kudan.AR {
public class xzing : MonoBehaviour
{
public KudanTracker _kudanTracker;
public Texture2D camTex;
private Thread qrThread;
private Color32[] camPix;
private int W, H;
public Text resultText;
private bool isQuit;
public string LastResult;
void OnDestroy()
{
qrThread.Abort();
}
void OnApplicationQuit()
{
isQuit = true;
}
void Start()
{
LastResult = "nothing";
OnEnable();
qrThread = new Thread(DecodeQR);
qrThread.Start();
}
void Update ()
{
if(camPix == null) {
camTex = _kudanTracker._trackerPlugin.GetTrackingTexture() as Texture2D;
W = camTex.width;
H = camTex.height;
camTex.SetPixels32(camPix);
camPix = camTex.GetPixels32();
}
}
void DecodeQR()
{
var barcodeReader = new BarcodeReader {AutoRotate = false, TryHarder = false};
while (true)
{
if (isQuit)
break;
try
{
var result = barcodeReader.Decode(camPix, W, H);
Debug.Log("camPix: " + camPix.Length);
if (result != null)
{
LastResult = result.Text;
Debug.Log("result: " + result.Text);
resultText.text = result.Text;
} else {
Debug.Log("result: No Code Detected");
resultText.text = "No Code Detected";
}
// Sleep a little bit and set the signal to get the next frame
camPix = null;
Debug.Log("camPix: " + camPix);
Thread.Sleep(1000);
}
catch
{
}
}
}
}
}
Answer by Slavrix · Oct 08, 2017 at 01:33 PM
I changed the camTex to a webcamtexture and i get it directly from the camera now and it does seem to work alot better though it looks like i need to tweak the settings a little bit somewhere, or add like a box on the ui as a guide for how much of the image the code needs to take up for it to be read correctly.
Your answer
Follow this Question
Related Questions
Augmented reality possible functions? 0 Answers
I want to track Bangla single letter, is it possible in unity3D with vuphoria augmented reality? 1 Answer
cannot combine shader of two objects 0 Answers
Why is my app screen black when I build to Android? What am I doing wrong? 1 Answer
how to run ARCore Instant Preview on Android emulator? 0 Answers