3

我正在尝试使用库 ZXing 和 AR Core 扫描 Unity 中的二维码。目前我尝试了以下方法:

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 !");
    }

}

但似乎无法检测到二维码。有什么办法可以从 AR Core 相机中提取图像并从中提取 QR 码吗?

4

0 回答 0