Exemplo n.º 1
0
        public static string DecodeFromImage(Texture2D image)
        {
            Debuger.Log(LOG_TAG, "DecodeFromImage() ");

            try
            {
                Color32LuminanceSource src = new Color32LuminanceSource(image.GetPixels32(), image.width, image.height);

                Binarizer    bin = new GlobalHistogramBinarizer(src);
                BinaryBitmap bmp = new BinaryBitmap(bin);

                MultiFormatReader mfr    = new MultiFormatReader();
                Result            result = mfr.decode(bmp);

                if (result != null)
                {
                    return(result.Text);
                }
                else
                {
                    Debuger.LogError(LOG_TAG, "DecodeFromImage() Decode 失败!");
                }
            }
            catch (Exception e)
            {
                Debuger.LogError(LOG_TAG, "DecodeFromImage() " + e.Message);
            }

            return("");
        }
Exemplo n.º 2
0
 public static string DecodeQRcodeImage(Texture2D texture2D)
 {
     try
     {
         Color32LuminanceSource color32LuminanceSource = new Color32LuminanceSource(texture2D.GetPixels32(), texture2D.width, texture2D.height);
         Binarizer         binarizer         = new GlobalHistogramBinarizer(color32LuminanceSource);
         BinaryBitmap      binaryBitmap      = new BinaryBitmap(binarizer);
         MultiFormatReader multiFormatReader = new MultiFormatReader();
         Result            result            = multiFormatReader.decode(binaryBitmap);
         if (result != null)
         {
             return(result.Text);
         }
         else
         {
             Debuger.LogError("Decode QRcode Image Error");
             return(String.Empty);
         }
     }
     catch (Exception e)
     {
         Debuger.LogError("Decode QRcode Image Error " + e.Message);
         return(String.Empty);
     }
 }
Exemplo n.º 3
0
        static LuminanceSource CreateLuminanceSource(Color32[] colors, int width, int height)
        {
            LuminanceSource luminanceSource = new Color32LuminanceSource(colors, width, height);

            if (luminanceSource.CropSupported)
            {
                var smallerSize     = Mathf.Min(width, height);
                var smallerSizeHalf = smallerSize / 2;
                luminanceSource = luminanceSource.crop(width / 2 - smallerSizeHalf, height / 2 - smallerSizeHalf, smallerSize, smallerSize);
            }

            return(luminanceSource);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Function for just fetching the QR-Codes in the WebCamTexture-Image.
        /// It stores the Data in a QrCodeData-Object.
        /// It uses the "pixels" field as the image-source, since we can not
        /// access the Unity-API from another thread than the main-thread.
        /// </summary>
        private void DecodeQr()
        {
            while (_runThread)
            {
                // waiting.
                if (_pixels != null)
                {
                    // Create a BitMatrix from the Color32[] of the camear image, so that XZing can detect QR-codes.
                    LuminanceSource lum    = new Color32LuminanceSource(_pixels, GlobalState.Instance.CamWidth, GlobalState.Instance.CamHeight);
                    HybridBinarizer bin    = new HybridBinarizer(lum);
                    BinaryBitmap    binBip = new BinaryBitmap(bin);
                    BitMatrix       matrix = binBip.BlackMatrix;

                    Detector       detector = new Detector(matrix);
                    DetectorResult result   = detector.detect();
                    _qrCodeCollection.UpdateData(result);
                }
            }
        }