예제 #1
0
        private void button6_Click(object sender, EventArgs e)
        {
            using (var openDlg = new OpenFileDialog())
            {
                openDlg.Multiselect = false;
                if (openDlg.ShowDialog(this) == DialogResult.OK)
                {
                    string fileName = openDlg.FileName;
                    if (!File.Exists(fileName))
                    {
                        return;
                    }

                    var image = (Bitmap)Bitmap.FromFile(fileName);
                    pictureBox1.Image = image;

                    var result = barcodeReader.Decode(image);
                    if (result == null)
                    {
                        result = barcodeReader.Decode(image);
                    }

                    if (result == null)
                    {
                        MessageBox.Show("Không nhận diện được mã QR Code",
                                        "QR Code Generator");
                    }
                    else
                    {
                        textBox5.Text = result.Text;
                    }
                }
            }
        }
예제 #2
0
 private void DecodeBarcode()
 {
     while (true)
     {
         if (pictureBox1.Image != null)
         {
             var barcodeBitmap = (Bitmap)pictureBox1.Image;
             Thread.Sleep(5);
             var result = reader.Decode(barcodeBitmap);
             if (result != null)
             {
                 Invoke(new Action(
                            delegate()
                 {
                     if (textBox1.Text != "")
                     {
                         if (textBox1.Lines[textBox1.Lines.Length - 1] != "바코드구격: " + result.BarcodeFormat + " 내용: " + result.Text)
                         {
                             textBox1.AppendText("\r\n바코드구격: " + result.BarcodeFormat + " 내용: " + result.Text);
                         }
                     }
                     else
                     {
                         textBox1.AppendText("\r\n바코드구격: " + result.BarcodeFormat + " 내용: " + result.Text);
                     }
                 }));
             }
         }
     }
 }
예제 #3
0
파일: Program.cs 프로젝트: liole/ImageCode
        static Tuple <float, float> Test(int index, int iterations = 1, QRLevel level = QRLevel.Medium)
        {
            var black = 0;
            var white = 0;

            for (var it = 0; it < iterations; ++it)
            {
                var text    = RandomString(70);
                var pattern = new bool[3, 3];
                for (var j = 0; j < 9; ++j)
                {
                    pattern[j / 3, j % 3] = (index >> j) % 2 == 1;
                }
                var blackBitmap = Generate(text, level, pattern, true);
                var whiteBitmap = Generate(text, level, pattern, false);
                var blackResult = reader.Decode(blackBitmap);
                var whiteResult = reader.Decode(whiteBitmap);
                if (blackResult != null && blackResult.Text == text)
                {
                    black++;
                }
                if (whiteResult != null && whiteResult.Text == text)
                {
                    white++;
                }
            }
            return(new Tuple <float, float>(
                       (float)black / iterations,
                       (float)white / iterations
                       ));
        }
예제 #4
0
        public string DecodedBarcode(string imageLocation)
        {
            var barcodeBitmap = (Bitmap)Image.FromFile(imageLocation);
            var result        = _reader.Decode(barcodeBitmap);

            return(result.Text);
            //return _reader.Decode(barcodeBitmap);
        }
        private Result Quantize(IMagickImage image)
        {
            var settings = new QuantizeSettings
            {
                ColorSpace   = ColorSpace.Gray,
                Colors       = 2,
                DitherMethod = DitherMethod.No
            };

            image.Quantize(settings);

            return(_reader.Decode(image));
        }
예제 #6
0
        Result CheckRegion(ref Bitmap barcodeBitmap, ref int debugNum)
        {
            //Сюда попадает уже вырезанный кусок картинки
            Result result = null;

            if (debugNum != 0)
            {
                if (debugNum != 0)
                {
                    barcodeBitmap.Save("debug_" + debugNum + ".jpg", ImageFormat.Jpeg);
                }
                debugNum++;
            }

            try
            {
                result = reader.Decode(barcodeBitmap);
            }
            catch
            {
                //Do nothing...
            }

            float angle = 0.5f;

            //немного поворачиваем, вдруг криво стоит
            while ((result == null) && (angle < 3.0f))
            {
                try
                {
                    result = reader.Decode(RotateBitmap(barcodeBitmap, angle));
                }
                catch
                {
                    //Do nothing...
                }
                if (result == null)
                {
                    try
                    {
                        result = reader.Decode(RotateBitmap(barcodeBitmap, -angle));
                    }
                    catch
                    {
                        //Do nothing...
                    }
                }
                angle += 0.5f;
            }
            return(result);
        }
예제 #7
0
        private string DecodeQrCode(WriteableBitmap wb)
        {
            IBarcodeReader reader = QrTools.GetQrReader();
            var            result = reader.Decode(wb);

            return(result?.Text);
        }
예제 #8
0
    IEnumerator loop()
    {
        while (0 == 0)
        {
            //how many seconds to att the camera reader --- default 0.333(3 times per second)
            yield return(new WaitForSeconds(0.333f));


            try
            {
                //Convert camera vulforia
                CameraDevice.Instance.SetFrameFormat(PIXEL_FORMAT.GRAYSCALE, true);
                print("pixels :" + CameraDevice.Instance.GetCameraImage(PIXEL_FORMAT.GRAYSCALE).Pixels.Length);

                var result = barcodeReader.Decode(CameraDevice.Instance.GetCameraImage(PIXEL_FORMAT.GRAYSCALE).Pixels, CameraDevice.Instance.GetCameraImage(PIXEL_FORMAT.GRAYSCALE).Width, CameraDevice.Instance.GetCameraImage(PIXEL_FORMAT.GRAYSCALE).Height, RGBLuminanceSource.BitmapFormat.Gray8);

                //Qr's code result

                print(result);
            }
            catch (Exception ex)
            {
                Debug.LogWarning(ex.Message);
            }
        }
    }
예제 #9
0
    void FixedUpdate()
    {
        if (frameReady)
        {
            try
            {
                var result = barcodeReader.Decode(texture.GetPixels32(), texture.width, texture.height);
                if (result != null)
                {
                    displayText.text = result.Text;
                    if (result.Text != previousVideoURL)
                    {
                        //Update
                        Debug.Log("Update");
                        player.Stop();
                        player.enabled   = false;
                        previousVideoURL = result.Text;
                        playerTex        = new Texture2D(playerTex.width, playerTex.height);
                        player.url       = result.Text;
                        player.enabled   = true;
                        player.frame     = 0;
                        player.Play();
                    }
                }
                else
                {
                    displayText.text = "No Measurement";
                }
            }
            catch (Exception ex) { Debug.LogWarning(ex.Message); }

            frameReady = false;
        }
    }
예제 #10
0
    IEnumerator Decoder()
    {
        // yield return endFrame;
        WaitForSeconds wait   = new WaitForSeconds(0.5f);
        Result         result = null;//barcodeReader.Decode(camTexture.GetPixels32(), camTexture.width, camTexture.height);

        while (result == null)
        {
            // Debug.Log("Decoder");
            yield return(wait);

            result = barcodeReader.Decode(camTexture.GetPixels32(), camTexture.width, camTexture.height);
        }
        WebCamStop();
        gameObject.SetActive(false);
        backBtn.gameObject.SetActive(false);
        GameManager.Instance.SetGameStation(result.Text);
        // if (result != null) {
        //  WebCamStop();
        //  gameObject.SetActive(false);
        //  backBtn.gameObject.SetActive(false);
        //  GameManager.Instance.SetGameStation(result.Text);
        //     // print(result.Text);
        // }
        // else
        //  StartCoroutine(Decoder());
    }
예제 #11
0
 private void OnGUI()
 {
     // do the reading — you might want to attempt to read less often than you draw on the screen for performance sake
     if (!isReadingQr)
     {
         return;
     }
     // drawing the camera on screen
     Graphics.DrawTexture(screenRect, camTexture);
     if (delay < 15)
     {
         delay++;
         return;
     }
     delay = 0;
     try
     {
         // decode the current frame
         var result = barcodeReader.Decode(camTexture.GetPixels32(),
                                           camTexture.width, camTexture.height);
         if (result != null)
         {
             client.Connect(result.Text, ControllerData.APPLICATION_PORT);
         }
     }
     catch (Exception ex) {
         Debug.LogWarning(ex.Message);
     }
 }
예제 #12
0
    private void Update()
    {
        frames++;
        if (frames % 40 == 0)
        {
            try
            {
                if (!wCamTexture.isPlaying)
                {
                    wCamTexture.Play();
                }

                var result = barcodeReader.Decode(wCamTexture.GetPixels32(),
                                                  wCamTexture.width, wCamTexture.height);
                if (result != null)
                {
                    Debug.Log("DECODED TEXT FROM QR: " + result.Text);
                    if (addingNew)
                    {
                    }
                    else if (manager.CheckID(result.Text, sDatatype, transform.parent.gameObject, nextUI, ErrorUI))
                    {
                        wCamTexture.Stop();
                        if (sDatatype == CheckIdType.package)
                        {
                            tourlist.UpdateList();
                            groundNavigation.updateGroundNavigation();
                        }
                    }
                }
            }
            catch (Exception ex) { Debug.LogWarning(ex.Message); }
            delay = 0.0f;
        }
    }
예제 #13
0
    private void decode()
    {
        if (cameraInitialized && !isDecoding)
        {
            try
            {
                isDecoding = true;

                // Decode the current frame
                var result = barcodeReader.Decode(camTexture.GetPixels32(), camTexture.width, camTexture.height);
                if (result != null)
                {
                    cameraDeactivate();

                    GameObject item = Instantiate(foodItemPrefab, scrollContent.transform);
                    item.GetComponent <FoodItem>().gameInstance = this;
                    item.GetComponent <FoodItem>().barcode      = result.Text;
                }
                else
                {
                    //Debug.Log("Nothing detected.");
                }
                isDecoding = false;
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }
        }
    }
예제 #14
0
    void Update()
    {
        decodedText = "";
        if (!mFormatRegistered)
        {
            return;
        }

        Image image = CameraDevice.Instance.GetCameraImage(mPixelFormat);

        try {
            // decode the current frame
            camSize = new Vector2(image.Width, image.Height);
            var result = barcodeReader.Decode(image.Pixels, image.Width, image.Height, mPixelFormat == Image.PIXEL_FORMAT.RGBA8888 ? RGBLuminanceSource.BitmapFormat.RGBA32 : RGBLuminanceSource.BitmapFormat.RGB24);
            decodedText = result.Text;
            if (result != null)
            {
                points = result.ResultPoints;
                Rect r = GetPercentageRect(points);
                currentArea = r.width * r.height;
                if (!loadedQRs.Contains(result.Text) && currentArea >= minAreaForUserTargetCreation)
                {
                    targetBuilder.BuildNewTarget("" + loadedQRs.Count, 1);
                    loadedQRs.Add(result.Text);
                }
            }
        }
        catch (Exception ex) { Debug.LogWarning(ex.Message); }
    }
예제 #15
0
    /// <summary>
    /// Decode any single QR code present in a camera frame.
    /// </summary>
    /// <param name="image">The camera feed frame.</param>
    private void ReadQRCode(Vuforia.Image image)
    {
        if (image == null || image.Pixels == null)
        {
            return;
        }

        try
        {
            // decode the current frame
            var result = barcodeReader.Decode(image.Pixels, image.BufferWidth, image.BufferHeight, VuforiaToZXingBitmapFormat(pixelFormat));
            if (result != null)
            {
                scannedText.text = result.Text;
                Debug.Log($"Decoded {result.Text}");
            }
            else
            {
                Debug.Log("Nothing decoded yet.");
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
예제 #16
0
    // Update is called once per frame
    void Update()
    {
        if (hasCamera)
        {
            Result res = qrReader.Decode(cameraFeedTexture.GetPixels32(), cameraFeedTexture.width, cameraFeedTexture.height);
            if (res != null)
            {
                Debug.Log(res.Text);
                //reminder to check that the qr code being decoded IS in fact one of the cards
                DataController cards = FindObjectOfType <DataController> ();
                //int cardNum = -1;

                CardData cardData = cards.GetCardData();
                int      cardNum  = cardData.GetCardSNFromURL(res.Text);
                cards.cardNumber = cardNum;

                if (cardNum >= 0)
                {
                    SceneManager.LoadScene("ShowCardScene", LoadSceneMode.Single);
                }
                else
                {
                    SceneManager.LoadScene("MenuScene", LoadSceneMode.Single);
                }

                //SceneManager.LoadScene ("MenuScene", LoadSceneMode.Single);
            }
        }
    }
예제 #17
0
        private void ScanForBarcode()
        {
            _phoneCamera.GetPreviewBufferArgb32(_previewBuffer.Pixels);
            _previewBuffer.Invalidate();

            _barcodeReader.Decode(_previewBuffer);
        }
예제 #18
0
        private void ScanForBarcode()
        {
            //grab a camera snapshot
            _phoneCamera.GetPreviewBufferArgb32(_previewBuffer.Pixels);
            _previewBuffer.Invalidate();

            //scan the captured snapshot for barcodes
            //if a barcode is found, the ResultFound event will fire
            _barcodeReader.Decode(_previewBuffer);
        }
    public IEnumerator ReadQRCode()
    {
        while (true)
        {
            if (cameraInitialized)
            {
                image = CameraDevice.Instance.GetCameraImage(mPixelFormat);

                if (image == null)
                {
                    Debug.Log("No camera image found");
                }
                else
                {
                    result = barCodeReader.Decode(image.Pixels, image.BufferWidth, image.BufferHeight, RGBLuminanceSource.BitmapFormat.RGB24);

                    image = null;

                    if (result != null)
                    {
                        // QRCode detected.
                        QRVisible = true;

                        Debug.Log(i + " QR code: " + result.Text);
                        //Do something with the QR code.

                        GameObject instantiatedSucces = Instantiate(succes, GameObject.Find("Canvas Start").transform);

                        Manager.Instance.controllerUrl = result.Text;
                        Debug.Log("Manager's controllerUrl set: " + Manager.Instance.controllerUrl);

                        int    firstIndex  = 0;
                        int    secondIndex = result.Text.IndexOf("can");
                        int    thirdIndex  = result.Text.IndexOf("=") + 1;
                        string canvasUrl   = result.Text.Substring(firstIndex, secondIndex) + result.Text.Substring(thirdIndex);

                        Manager.Instance.canvasUrl = canvasUrl + "?raw";
                        Debug.Log("Manager's variable set: " + Manager.Instance.canvasUrl);
                        result = null;  // clear data
                        yield return(new WaitForSeconds(1));

                        Destroy(instantiatedSucces);

                        uiMethods.Show(GameObject.Find("Canvas full"));
                        uiMethods.Hide(GameObject.Find("Canvas Start"));

                        yield break;
                    }
                }
            }

            yield return(new WaitForSeconds(0.5f));
        }
    }
예제 #20
0
 /// <summary>
 /// Decode the specified webCamTexture and portrait.
 /// </summary>
 /// <returns>The decode.</returns>
 /// <param name="webCamTexture">Web cam texture.</param>
 /// <param name="portrait">If set to <c>true</c> portrait.</param>
 public static Result Decode(WebCamTexture webCamTexture, bool portrait = true)
 {
     try
     {
         // decode the current frame
         if (portrait)
         {
             return(barcodeReader.Decode(Scanner.WebCamGetColor32Rotate(webCamTexture), webCamTexture.height, webCamTexture.width));
         }
         else
         {
             return(barcodeReader.Decode(webCamTexture.GetPixels32(), webCamTexture.width, webCamTexture.height));
         }
     }
     catch (Exception ex)
     {
         Debug.LogWarning(ex.Message);
         return(null);
     }
 }
        public string decodeB(ref Bitmap bm)
        {
            try
            {
                this.Sres = reader.Decode(bm);
            }catch (Exception ex)
            {
                genericDefinitions.error(ex.ToString(), "Error");
            }

            return(this.Sres.ToString());
        }
예제 #22
0
        private void ReadCode(Bitmap bitmap)
        {
            txtCodeType.Clear();
            txtContent.Clear();

            var result = barcodeReader.Decode(bitmap);

            if (result != null)
            {
                txtCodeType.Text = result.BarcodeFormat.ToString();
                txtContent.Text  = result.Text;
            }
        }
예제 #23
0
        private void ScanPreviewBuffer()
        {
            if (_luminance == null)
            {
                return;
            }

            _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
            // use a dummy writeable bitmap because the luminance values are written directly to the luminance buffer
            var result = _reader.Decode(dummyBitmap);

            Dispatcher.BeginInvoke(() => DisplayResult(result));
        }
예제 #24
0
        private bool Is파일QR코드(string imagePath)
        {
            try
            {
                var s = string.Empty;

                var barcodeBitmap = (Bitmap)Image.FromFile(imagePath);

                var result = _barcodeReader.Decode(barcodeBitmap);

                if (result != null)
                {
                    s = result.Text;
                }

                return(!string.IsNullOrWhiteSpace(s));
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #25
0
    private void DecodeQR(byte[] imgBuffer, int width, int height)
    {
        var textResult = BarcodeReader.Decode(imgBuffer, width, height, RGBLuminanceSource.BitmapFormat.Gray8);

        if (textResult != null)
        {
            if (SnackbarText != null)
            {
                SnackbarText.text = textResult.Text;
            }
            OnTextAvailable?.Invoke(textResult.Text);
        }
    }
예제 #26
0
    private void Update()
    {
        if (cameraInitialized)
        {
            try
            {
                //Image cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.GRAYSCALE);
                if (CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.GRAYSCALE, true))
                {
                    Debug.Log("Successfully registered pixel format ");
                }
                else
                {
                    Debug.LogError("Failed to register pixel format:");
                    return;
                }

                Image cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.GRAYSCALE);
                if (cameraFeed == null)
                {
                    return;
                }
                Result data = barCodeReader.Decode(cameraFeed.Pixels, cameraFeed.BufferWidth, cameraFeed.BufferHeight, RGBLuminanceSource.BitmapFormat.Gray8);
                if (data != null)
                {
                    // TODO: Handle when preview doesn't exists or an invalid text from QR Code was detected
                    FirebaseDatabase.DefaultInstance
                    .GetReference("previews/" + data.Text)
                    .GetValueAsync().ContinueWith(task =>
                    {
                        if (task.IsFaulted)
                        {
                            // TODO: Handle the error...
                        }
                        else if (task.IsCompleted)
                        {
                            DataSnapshot snapshot = task.Result;
                            Project.id            = (string)snapshot.Child("projectId").Value;
                            Project.previewId     = data.Text;
                            SceneManager.LoadScene("ManagerScene");
                        }
                    });
                }
            }
            catch (Exception e)
            {
                Debug.Log("Error: " + e.Message);
            }
        }
    }
예제 #27
0
    IEnumerator SaveBarcodeCoroutine(Type type, Action <bool> foundBarcode)
    {
        var texture = toTexture2D(tex);

        byte[] bytes = texture.EncodeToPNG();

        try
        {
            // decode the current frame
            var result = barcodeReader.Decode(texture.GetPixels32(), texture.width, texture.height);
            Debug.Log("Result: " + result);
            if (result != null)
            {
                Debug.Log("DECODED TEXT FROM QR: " + result.Text);
                foundBarcode(true);

                float scanTime = Time.realtimeSinceStartup - startTime;
                TimeProfiler.Instance.AddLog(System.DateTime.Now, TimeModel.Action.QRScan, scanTime);

                Debug.Log("Type: " + type.ToString());
                if (type == Type.SubscribeSensor)
                {
                    networkManager.ParseAndSubscribe(result.Text);
                }
                else if (type == Type.InfoSensor)
                {
                    Debug.Log("Barcode: " + result.Text);
                    networkManager.ParseAndSubscribeForInfo(result.Text);
                }
            }
            else
            {
                foundBarcode(false);
            }
        }
        catch (Exception ex)
        {
            Debug.LogWarning(ex.Message);
            foundBarcode(false);
        }

        //var folder = Directory.CreateDirectory(Application.persistentDataPath + "/Images");
        Debug.Log(Application.persistentDataPath);

        File.WriteAllBytes(Application.persistentDataPath + "/Images/barcode.png", bytes);

        yield return(null);
    }
예제 #28
0
        private void ScanPreviewBuffer()
        {
            if (luminance == null)
            {
                return;
            }

            photoCamera.GetPreviewBufferY(luminance.PreviewBufferY);
            // use a dummy writeable bitmap because the luminance values are written directly to the luminance buffer
            var result = reader.Decode(dummyBitmap);

            if (result != null)
            {
                viewModel.Scanned(result.Text);
            }
        }
예제 #29
0
        private Result AnalyseFrame()
        {
            if (_currentCamera == null)
            {
                return(null);
            }

            var width         = Convert.ToInt32(_currentCamera.PreviewResolution.Width);
            var height        = Convert.ToInt32(_currentCamera.PreviewResolution.Height);
            var previewBuffer = new byte[width * height];

            _currentCamera.GetPreviewBufferY(previewBuffer);

            Result result = _barcodeReader.Decode(previewBuffer, width, height, RGBLuminanceSource.BitmapFormat.Gray8);

            return(result);
        }
예제 #30
0
        private void Decode(Bitmap image)
        {
            var timerStart = DateTime.Now;

            var result = barcodeReader.Decode(image);

            var timerStop = DateTime.Now;

            labDuration.Text = (timerStop - timerStart).TotalMilliseconds.ToString();/// ("0 ms");

            if (result == null)
            {
                txtContent.Text = "No barcode recognized";
            }
            else
            {
                txtType.Text    = result.BarcodeFormat.ToString();
                txtContent.Text = result.Text;
            }
        }