I'm trying to scan a QR code in Unity using the libraries ZXing and AR Core. Currenty I tried the following:
private void _OnImageAvailable(TextureReaderApi.ImageFormatType format, int width, int height, IntPtr pixelBuffer, int bufferSize)
{
// pixelBuffer is input image
byte[] s_ImageBuffer = new byte[bufferSize]; // output image
System.Runtime.InteropServices.Marshal.Copy(pixelBuffer, s_ImageBuffer, 0, bufferSize);
//m_EdgeDetectionBackgroundTexture = new Texture2D(width, height, TextureFormat.R8, false, false);
m_EdgeDetectionBackgroundTexture = new Texture2D(width, height, TextureFormat.RGBA32, false, false);
m_EdgeDetectionBackgroundTexture.LoadRawTextureData(s_ImageBuffer);
m_EdgeDetectionBackgroundTexture.Apply();
var cameraFeed = m_EdgeDetectionBackgroundTexture.GetPixels32();
BarcodeReader barCodeReader = new BarcodeReader();
var data = barCodeReader.Decode(cameraFeed, width, height);
if (data != null)
{
// QRCode detected.
Debug.Log(data.Text);
//ResultPoints[0].X=bottom right
//ResultPoints[2].X=top right
//ResultPoints[2].Y=top left
//ResultPoints[0].X=bottom left
Debug.LogError(data.ResultPoints[0].X);
Debug.LogError(data.ResultPoints[2].X);
Debug.LogError(data.ResultPoints[2].Y);
Debug.LogError(data.ResultPoints[0].Y);
Debug.LogError(data.Text);
}
else
{
Debug.Log("No QR code detected !");
}
}
But it seems like no QR code can be detected. Is there anything I could do to extract an image from a AR Core Camera and extract the QR code from it?