Simple call phone camera capture and then identify the QR code to display the contents of the QR code
Need to import a Zxing.unity.dll file, now this script recognition data is placed in the updata inside the volume of data scanned Special conference card if you use it, do it yourself one second. I didn't get it.
http://download.csdn.net/detail/chh19941125/8734149
Code:
Using system.threading;using unityengine;using Zxing;public class webcamerascript:monobehaviour{public string LastRe Sult; 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_C Ontinuousauto); Checks how many and which cameras is available on the device for (int cameraindex = 0; Cameraindex < Webcamt Exture.devices.Length; cameraindex++) {//We want the back camera if (! webcamtexture.devices[cameraindex].isfrontfacing) {//webcameratexture = new Webcamtexture (camer Aindex, 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); }}//The texture of coming from the camera should is applied//to our Guitextur E. As we have flipped it before the camera preview would have the//correct orientation Mycameratexture.tex ture = 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 (30*1, Screen.width,), "LastResult:" + LastResult); if (GUI. button (new Rect (0, 0, +), "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, Tryhard ER = true}; while (true) {try {//decode the current frame ResU Lt 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 {}}}}
Unity calls phone camera to recognize QR code