国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

Unity調用手機攝像機識別二維碼

2020-01-24 00:02:20
字體:
來源:轉載
供稿:網友

本文實現Unity調用手機攝像,拍攝,然后識別二維碼,顯示二維碼的內容。

需要導入一個zxing.unity.dll文件,現在這個腳本的識別數據是放在Updata里邊掃描的 數據量特別大會卡  要是用的話就自己做一下一秒執行一次。我這里沒有弄

下載地址:zxing.unity.dll

代碼:

using System.Threading;using UnityEngine;using ZXing; public class WebCameraScript : MonoBehaviour{ public string LastResult; public string Lastresult; public Color32[] data; private bool isQuit;  public GUITexture myCameraTexture; private WebCamTexture webCameraTexture;  private void Start() { // bool success = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); // Checks how many and which cameras are available on the device for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++) {  // We want the back camera  if (!WebCamTexture.devices[cameraIndex].isFrontFacing)  {  //webCameraTexture = new WebCamTexture(cameraIndex, Screen.width, Screen.height);  webCameraTexture = new WebCamTexture(cameraIndex, 200, 200);   // Here we flip the GuiTexture by applying a localScale transformation  // works only in Landscape mode  myCameraTexture.transform.localScale = new Vector3(1, 1, 1);  } }  // Here we tell that the texture of coming from the camera should be applied  // to our GUITexture. As we have flipped it before the camera preview will have the  // correct orientation myCameraTexture.texture = webCameraTexture; // Starts the camera webCameraTexture.Play(); //enabled=WebCamTexture.s }  public void ShowCamera() { myCameraTexture.guiTexture.enabled = true; webCameraTexture.Play(); }  public void HideCamera() { myCameraTexture.guiTexture.enabled = false; webCameraTexture.Stop(); }  private void OnGUI() { GUI.Label(new Rect(60, 30*1, Screen.width, 20), "LastResult:" + LastResult); if (GUI.Button(new Rect(0, 0, 100, 100), "ON/OFF")) {  if (webCameraTexture.isPlaying)  HideCamera();  else  ShowCamera(); } }  private void Update() { //data = new Color32[webCameraTexture.width * webCameraTexture.height]; data = webCameraTexture.GetPixels32();  DecodeQR(webCameraTexture.width, webCameraTexture.height); }   private void DecodeQR(int W, int H) { if (isQuit)  return; // create a reader with a custom luminance source var barcodeReader = new BarcodeReader {AutoRotate = true, TryHarder = true};  // while (true) {  try  {  // decode the current frame  Result result = barcodeReader.Decode(data, W, H);  if (result != null)  {   LastResult = result.Text;   // shouldEncodeNow = true;   print("i read out::" + result.Text);  }   // Sleep a little bit and set the signal to get the next frame  Thread.Sleep(200);  data = null;  }  catch  {  } } }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高淳县| 天祝| 嵊州市| 渑池县| 吉隆县| 章丘市| 东安县| 海林市| 北辰区| 资阳市| 吴堡县| 闽侯县| 成都市| 瑞昌市| 泾阳县| 台南县| 右玉县| 伊宁市| 察隅县| 资阳市| 历史| 柳江县| 宁海县| 神木县| 印江| 景德镇市| 新竹县| 洛阳市| 嵩明县| 山东| 普兰县| 正定县| 河北省| 吉木萨尔县| 开江县| 独山县| 平顺县| 盖州市| 大渡口区| 汪清县| 冷水江市|