Unity調(diào)用手機(jī)攝像機(jī)識別二維碼
本文實現(xiàn)Unity調(diào)用手機(jī)攝像,拍攝,然后識別二維碼,顯示二維碼的內(nèi)容。
需要導(dǎo)入一個zxing.unity.dll文件,現(xiàn)在這個腳本的識別數(shù)據(jù)是放在Updata里邊掃描的 數(shù)據(jù)量特別大會卡 要是用的話就自己做一下一秒執(zhí)行一次。我這里沒有弄
下載地址: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
{
}
}
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
欄 目:C#教程
下一篇:C#位運算以及實例計算詳解
本文標(biāo)題:Unity調(diào)用手機(jī)攝像機(jī)識別二維碼
本文地址:http://www.jygsgssxh.com/a1/C_jiaocheng/4726.html
您可能感興趣的文章
- 01-10C#調(diào)用dos窗口獲取相關(guān)信息的方法
- 01-10同步調(diào)用和異步調(diào)用WebService
- 01-10C#調(diào)用WebService實例開發(fā)
- 01-10C++調(diào)用C#的DLL程序?qū)崿F(xiàn)方法
- 01-10Unity3d獲取系統(tǒng)時間
- 01-10Unity3D獲取當(dāng)前鍵盤按鍵及Unity3D鼠標(biāo)、鍵盤的基本操作
- 01-10C#怎么實現(xiàn)手機(jī)短信發(fā)送功能
- 01-10C# 調(diào)用 JavaWebservice服務(wù)遇到的問題匯總
- 01-10C#開發(fā)Android百度地圖手機(jī)應(yīng)用程序(多地圖展示)
- 01-10基于C#實現(xiàn)手機(jī)號碼歸屬地接口調(diào)用


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實現(xiàn)txt定位指定行完整實例
- 01-10WinForm實現(xiàn)仿視頻播放器左下角滾動新
- 01-10C#停止線程的方法
- 01-10C#實現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-11ajax實現(xiàn)頁面的局部加載
- 01-10delphi制作wav文件的方法
- 04-02jquery與jsp,用jquery
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-10C#中split用法實例總結(jié)
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢data目錄下的sessions文件夾有什


