Unity calls phone camera to recognize QR code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.