public void ExplicitlyDetectAndDecode()
        {
            using var obj = new QRCodeDetector();
            int x = 100;
            int y = 200;

            using var withQr    = ImageWithQrCode(x, y, out int w, out int h);
            using var pointsMat = new Mat();
            ShowImagesWhenDebugMode(withQr);

            bool detected = obj.Detect(withQr, out var points);

            Assert.True(detected);
            Assert.Equal(4, points.Length);
            Assert.Equal(102, points[0].X);
            Assert.Equal(201, points[0].Y);
            Assert.Equal(199, points[1].X);
            Assert.Equal(201, points[1].Y);
            Assert.Equal(199, points[2].X);
            Assert.Equal(299, points[2].Y);
            Assert.Equal(102, points[3].X);
            Assert.Equal(299, points[3].Y);

            using var straightQrCode = new Mat();
            obj.Decode(withQr, points);
            var decodedString = obj.Decode(withQr, points, straightQrCode);

            Assert.False(straightQrCode.Empty());
            Assert.Equal("https://github.com/opencv/opencv", decodedString);
        }
Esempio n. 2
0
    void OnNewSample(Frame frame)
    {
        if (isDetecting)
        {
            return;
        }

        using (var frameSet = frame.AsFrameSet())
        {
            using (var colorFrame = frameSet.ColorFrame)
            {
                if (colorFrame == null)
                {
                    return;
                }
                // set isDetecting true to avoid crashes
                isDetecting = true;
                int cfWidth  = colorFrame.Width;
                int cfHeight = colorFrame.Height;
                // transform realsense frame into cv mat format
                using (var image = new Mat(cfHeight, cfWidth, MatType.CV_8UC3, colorFrame.Data))
                {
                    using (qrCodeDetector = new QRCodeDetector())
                    {
                        // Show generated Image in separate window
                        // Window.ShowImages(image);
                        // check frame if qrcode is existing
                        bool detected = qrCodeDetector.Detect(image, out var points);

                        if (detected)
                        {
                            using (var straightQrCode = new Mat())
                            {
                                qrCodeDetector.Decode(image, points);
                                var decodedString = qrCodeDetector.Decode(image, points, straightQrCode);
                                if (!string.IsNullOrEmpty(decodedString))
                                {
                                    if (decodedString == "tiger")
                                    {
                                        actionEventQueue.Enqueue("spawnTiger");
                                    }
                                    if (decodedString == "house")
                                    {
                                        actionEventQueue.Enqueue("spawnHouse");
                                    }
                                }
                            }
                        }
                        isDetecting = false;
                    }
                }
            }
        }
    }
Esempio n. 3
0
        private string  RecongizeQRCode(Mat mat)
        {
            Mat            dstMat     = new Mat();
            QRCodeDetector QRdetecter = new QRCodeDetector();
            bool           res        = QRdetecter.Detect(mat, dstMat); //检测
            string         str        = QRdetecter.Decode(mat, dstMat); //解码

            return(str);
        }