代码之家  ›  专栏  ›  技术社区  ›  Maxim

使用ZXing和AR Core统一扫描二维码

  •  1
  • Maxim  · 技术社区  · 6 年前

    我正在尝试使用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相机中提取图像并从中提取二维码?

    0 回复  |  直到 6 年前