在Unity中使用ZXing定位QRcode的Position Pattern
Using ZXing in Unity to locate QRcode's Position Pattern
如题,我想使用locate three Position Pattern
Example
我想知道当我从网络摄像头纹理中获取新二维码时如何获取这些图案的 x y 位置。
我应该如何实现这是 Unity(C#)?
使用下面的代码解码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 个角的位置。显然,您需要在资产的插件文件夹中添加 ZXing.dll。
希望这有助于获得结果。
如题,我想使用locate three Position Pattern
Example
我想知道当我从网络摄像头纹理中获取新二维码时如何获取这些图案的 x y 位置。
我应该如何实现这是 Unity(C#)?
使用下面的代码解码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 个角的位置。显然,您需要在资产的插件文件夹中添加 ZXing.dll。
希望这有助于获得结果。