时间:2021-05-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 { } } }}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
1、启动Alook浏览器,点击界面右上角的二维码按钮。 2、浏览器会进入拍摄模式,并调用手机的后置摄像头。 3、把镜头对准要扫描的二维码,它就会自动识别转跳
OPPO手机怎么识别二维码?当我们在日常生活中遇到需要扫描二维码时,该怎么使用我们的OPPO手机识别二维码呢,下面就由小编为大家带来OPPO手机怎么识别二维码。
现在二维码很常见,手机扫描二维码很简单,只需用扫描二维码的APP对准二维码即可。一般下载的手机浏览器就自带了二维码识别。但是有时候我们需要电脑识别二维码,比如一
OPPO手机怎么识别图中二维码?当我们在收到带有二维码的图片消息时,该怎么识别图中的二维码内容呢,怎么识别图中二维码,下面就和小编一起来看看吧!手机中的微信,在
本文实例讲述了PHP生成二维码与识别二维码的方法。分享给大家供大家参考,具体如下:二维码的分类线性堆叠式二维码矩阵式二维码二维码的优缺点优点信息容量大编码范围广