【发布时间】:2018-11-22 13:10:50
【问题描述】:
我正在尝试使用以下库读取 QR 码:
- ARKit
- 志兴
然而,它似乎并不顺利。几个小时后,我仍然无法读出一个像样的二维码。 调试时我应用纹理来查看我的结果。由于纹理 Y,它看起来是红色的,但除此之外它还显示 QR 码。 解释纹理不会返回任何 ZXing 分析的数据。
这是我为此使用的以下代码:
#if UNITY_IOS && !UNITY_EDITOR
// Update is called once per frame
// BETTER: InvokeRepeating
void Update()
{
if (!done) {
ARTextureHandles handles = arSession.GetARVideoTextureHandles();
//ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles();
if (handles.IsNull())
{
return;
}
if (handles.TextureY != System.IntPtr.Zero) {
ReadQRCode (handles.TextureY);
}
}
}
#endif
private void ReadQRCode(System.IntPtr mtlTexPtr)
{
Debug.Log("---------------");
Debug.Log("Scanning...");
Resolution currentResolution = Screen.currentResolution;
tex = (UnityEngine.Texture2D)GameObject.Find("Camera").GetComponent<UnityARVideo>().m_ClearMaterial.GetTexture("_textureCbCr");
tex.UpdateExternalTexture(mtlTexPtr);
try
{
if(barCodeReader == null) {
Debug.Log("Could not find barcorereader");
}
if(tex == null) {
Debug.Log("Could not find texture");
}
var data = barCodeReader.Decode(tex.GetPixels32(), currentResolution.width, currentResolution.height);
if (data != null)
{
Debug.Log("QR: " + data.Text);
}
else
{
Debug.Log("NO QR: " + "No QR code detected !");
}
}
catch (Exception e)
{
Debug.LogError("Error reading QR");
Debug.LogError(e.Message);
}
}
【问题讨论】: