我正在尝试使用ZXing和AR Core库在Unity中扫描QR码。 目前,我尝试了以下操作:
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 !");
}
}
但是似乎无法检测到QR码。我可以做些什么来从AR核心相机中提取图像并从中提取QR码?