【问题标题】:Using ZXing in Unity to locate QRcode's Position Pattern在 Unity 中使用 ZXing 定位 QRcode 的 Position Pattern
【发布时间】:2018-04-28 06:44:17
【问题描述】:

作为标题,我想使用定位三个位置模式。

Example

我想知道当我从 webcamtexture 获得新的 QR 码时如何获取这些图案的 x y 位置。
我应该如何实现这是 Unity(C#)?

【问题讨论】:

  • 您可以参考this blog更好地理解。
  • 这篇博客只展示了ZXing如何解码和编码(之前已经做过这部分),但仍然不知道如何获取模式的位置。

标签: c# unity3d zxing


【解决方案1】:

使用以下代码解码ZXing dll。

private WebCamTexture camTexture;
private Rect screenRect;
void Start()
{
    screenRect = new Rect(0, 0, Screen.width, Screen.height);
    camTexture = new WebCamTexture();
    camTexture.requestedHeight = Screen.height;
    camTexture.requestedWidth = Screen.width;
    if (camTexture != null)
    {
        camTexture.Play();
    }
}

void OnGUI()
{
    // drawing the camera on screen
    GUI.DrawTexture(screenRect, camTexture, ScaleMode.ScaleToFit);
    // do the reading — you might want to attempt to read less often than you draw on the screen for performance sake
    try
    {
        IBarcodeReader barcodeReader = new BarcodeReader();
        // decode the current frame
        var result = barcodeReader.Decode(camTexture.GetPixels32(), camTexture.width, camTexture.height);
        if (result != null)
        {
            Debug.Log("DECODED TEXT FROM QR: " +result.Text);
        }
        ResultPoint[] point = result.ResultPoints;
        Debug.Log("X: " + point[0].X + " Y: " + point[1].Y);
    }
    catch (Exception ex) { Debug.LogWarning(ex.Message); }
}

我参考了ZXing dll link。它还在自述文件中有二维码生成器。通过自述文件。它几乎相同,只是添加了ResultPoint[] point = result.ResultPoints;。这给出了图像 3 个角的位置。显然,您需要在 Assets 的 plugins 文件夹中添加 ZXing.dll。 希望这有助于获得结果。

【讨论】:

  • 一年半前我曾尝试在 android 和 pc 上从 ZXing 解码 QR 标记,所以当时它确实对我有用。现在不知道,但应该也可以使用 ios。
猜你喜欢
  • 1970-01-01
  • 2013-09-22
  • 1970-01-01
  • 1970-01-01
  • 2014-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多