Last active
February 13, 2024 01:44
-
-
Save 3p3r/d52d0ee173c5c28d1f324729b35cb96a to your computer and use it in GitHub Desktop.
Revisions
-
Sepehr Laal revised this gist
Jul 4, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,9 @@ /// http://zxingnet.codeplex.com/ /// This is tested with Unity3D 5.3.5f1 /// /// A Multi threaded version of this class is available at: /// https://gist.github.com/sepehr-laal/0b636942406a385097cbd5bcd1130b52 /// /// Attach this script to an object in your scene and /// hit play. If you hold a QR code in front of your /// WebCam, its decoded string appears in "decodedResult" -
Sepehr Laal created this gist
Jul 4, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ using ZXing; using ZXing.Common; using UnityEngine; using System.Collections.Generic; /// <summary> /// Extremely basic usage of BarcodeDecoder in ZXing /// library to actively decode QR codes from WebCam. /// You may download ZXing C# binaries from: /// http://zxingnet.codeplex.com/ /// This is tested with Unity3D 5.3.5f1 /// /// Attach this script to an object in your scene and /// hit play. If you hold a QR code in front of your /// WebCam, its decoded string appears in "decodedResult" /// </summary> public class ZXingScanner : MonoBehaviour { public string decodedResult; WebCamTexture webCamTexture; BarcodeReader barcodeReader; void Start() { var formats = new List<BarcodeFormat>(); formats.Add(BarcodeFormat.QR_CODE); barcodeReader = new BarcodeReader { AutoRotate = false, Options = new DecodingOptions { PossibleFormats = formats, TryHarder = true, } }; webCamTexture = new WebCamTexture(); webCamTexture.Play(); } void Update() { if (webCamTexture != null && webCamTexture.isPlaying) DecodeQR(); } void DecodeQR() { if (webCamTexture == null) return; Result result = barcodeReader.Decode( webCamTexture.GetPixels32(), webCamTexture.width, webCamTexture.height); if (result != null) decodedResult = result.Text; } void OnDestroy() { if (webCamTexture != null) webCamTexture.Stop(); } }