ARカメラ(Vuforia)に、以下のスクリプト(【QR読み取り】)を貼り付けて、
1つのカメラオブジェクト(ARCamera)で、
QRコードの読み込みと、
ARマーカの読み取りを実施しようとしています。
以下のスクリプト(【QR読み取り】)を除いた状態だと、
ARカメラとして正常にマーカを読み取って、3D表示できています。
マーカはQRコードではなく、固定の画像です。
以下のスクリプト(【QR読み取り】)を組み込むと、
QRの読み取り自体はできるのですが、
そもそも画面が真っ白になってしまいます。
ARマーカの読み取りもできません。
どのようにすれば、ARカメラに、QR読込み機能を追加できるでしょうか。
■Unityバージョン
2018.3.9f1 (64-bit)
【QR読み取り】
unity
1using System.Collections; 2using UnityEngine; 3using UnityEngine.UI; 4using ZXing; 5 6public class SampleQRReader : MonoBehaviour 7{ 8 string _result = null; 9 public WebCamTexture _webCam; 10 11 IEnumerator Start() 12 { 13 yield return Application.RequestUserAuthorization(UserAuthorization.WebCam); 14 if (Application.HasUserAuthorization(UserAuthorization.WebCam) == false) 15 { 16 GameObject.Find("QrResult").GetComponent<Text>().text = "no camera."; 17 Debug.LogFormat("no camera."); 18 yield break; 19 } 20 Debug.LogFormat("camera ok."); 21 GameObject.Find("QrResult").GetComponent<Text>().text = "camera ok."; 22 23 WebCamDevice[] devices = WebCamTexture.devices; 24 if (devices == null || devices.Length == 0) 25 yield break; 26 _webCam = new WebCamTexture(devices[0].name, Screen.width, Screen.height, 12); 27 _webCam.Play(); 28 } 29 30 void Update() 31 { 32 if (_webCam != null) 33 { 34 _result = Read(_webCam); 35 36 GameObject.Find("QrResult").GetComponent<Text>().text = _result; 37 38 Debug.LogFormat("result : " + _result); 39 } 40 } 41 42 43 public static string Read(WebCamTexture tex) 44 { 45 BarcodeReader reader = new BarcodeReader(); 46 int w = tex.width; 47 int h = tex.height; 48 var pixel32s = tex.GetPixels32(); 49 var r = reader.Decode(pixel32s, w, h); 50 if (r != null) 51 return r.Text; 52 else 53 return "error"; 54 } 55 56}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/24 13:52