예제 #1
0
        public void DetectAndDecode()
        {
            using var obj = new QRCodeDetector();
            int x = 100;
            int y = 200;

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

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

            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);

            Assert.False(straightQrCode.Empty());
            Assert.Equal("https://github.com/opencv/opencv", decodedString);
        }
예제 #2
0
        static void Main(string[] args)
        {
            using var straightQrCode = new Mat();
            var qr = new QRCodeDetector();


            var capture = new VideoCapture();

            capture.Open(0);

            using (var normalWindow = new Window("QRCode"))
            {
                var normalFrame = new Mat();
                var srFrame     = new Mat();
                while (true)
                {
                    capture.Read(normalFrame);
                    normalWindow.ShowImage(normalFrame);


                    var QRCodeContent = qr.DetectAndDecode(normalFrame, out var point);
                    if (QRCodeContent != "")
                    {
                        Console.WriteLine(QRCodeContent);
                    }


                    Cv2.WaitKey(500);
                }
            }
        }
예제 #3
0
        public static void QrCodeTest()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist1(matGray);

            QRCodeDetector detector = new QRCodeDetector();

            Point2f[] points;
            string    text = detector.DetectAndDecode(matGray, out points);

            Console.WriteLine("points : " + string.Join(",", points.Select(pt => pt.ToString())));
            Console.WriteLine(text);

            var matRet = matGray.CvtColor(ColorConversionCodes.GRAY2BGR);
            var pts    = points.Select(pt => new OpenCvSharp.Point(pt.X, pt.Y));
            var ptss   = Enumerable.Repeat(pts, 1);

            matRet.Polylines(ptss, true, Scalar.Lime);
            Glb.DrawMatAndHist2(matRet);

            matGray.Dispose();
            matRet.Dispose();
        }
예제 #4
0
        public void DecodeMultibyteString()
        {
            using var obj    = new QRCodeDetector();
            using var withQr = Image("qr_multibyte_letters.png");

            var decodedString = obj.DetectAndDecode(withQr, out var points);

            Assert.Equal(4, points.Length);
            Assert.Equal("Helloこんにちは你好안녕하세요", decodedString);
        }
예제 #5
0
        public void DecodeSinglebyteString()
        {
            using var obj    = new QRCodeDetector();
            using var withQr = Image("qr_singlebyte_letters.png");

            var decodedString = obj.DetectAndDecode(withQr, out var points);

            Assert.Equal(4, points.Length);
            Assert.Equal("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[]^_`{|}", decodedString);
        }
예제 #6
0
        public static string DecodeQR(string inputImagePath)
        {
            Mat            inputImage = new Mat(inputImagePath);
            QRCodeDetector qrDecoder  = new QRCodeDetector();

            Point2f[] point2Fs;
            string    data = qrDecoder.DetectAndDecode(inputImage, out point2Fs);

            if (data.Length > 0)

            {
                Display(inputImage, point2Fs, inputImagePath);
                inputImage.Dispose();
                qrDecoder.Dispose();
                return(data);
            }

            else
            {
                throw new Exception("QR Not Found");
                inputImage.Dispose();
                qrDecoder.Dispose();
            }
        }
예제 #7
0
        private void OpenCv_TimerTick(Object sender, EventArgs e)
        {
            //Vérifier l'adresse de la caméra
            //On a utilisé un routeur
            cameraNXT1.Open("http://192.168.0.101:8080/video");
            //cameraNXT2.Open(0);

            if (cameraNXT1.IsOpened())
            {
                Console.WriteLine("NXT1 open");
                int essais = 0;
                while (essais != 10)
                {
                    cameraNXT1.Read(frameNXT1);
                    string decodeDataNXT1 = qrdecoderNXT1.DetectAndDecode(frameNXT1, out Point2f[] bbox);
                    //Cv2.ImShow("NXT1", frameNXT1);
                    //Cv2.WaitKey(30);
                    if (decodeDataNXT1.Length > 0)
                    {
                        Console.WriteLine("detecte");
                        Regex           rg  = new Regex(@"\d+");
                        List <string>   arr = new List <string>();
                        MatchCollection mc  = rg.Matches(decodeDataNXT1);
                        foreach (Match i in mc)
                        {
                            arr.Add(i.ToString());
                        }
                        double lengthPixl = bbox[0].DistanceTo(bbox[1]);
                        int    lengthReel = Convert.ToInt32(arr[1]);
                        double distance   = (foucale * lengthReel) / lengthPixl;
                        Console.WriteLine(distance);
                        //Distance;
                        txtData.Rows[0].Cells[1].Value = distance;  //NXT1
                        //Beta
                        txtData.Rows[1].Cells[1].Value = arr[2];
                        //QrNum
                        txtData.Rows[2].Cells[1].Value = arr[0];
                        break;
                    }

                    essais++;
                }
                cameraNXT1.Release();
            }

            //S'inspirer du programme au-dessus pour le NXT2

            /*                if (cameraNXT2.IsOpened())
             *              {
             *                  cameraNXT2.Read(frameNXT2);
             *                  string decodeDataNXT2 = qrdecoderNXT1.DetectAndDecode(frameNXT1, out Point2f[] bboxNXT2);
             *                  //Cv2.ImShow("NXT2", frameNXT2);
             *                  //Cv2.WaitKey(30);
             *                  if (decodeDataNXT2.Length > 0)
             *                  {
             *                      Regex rg = new Regex(@"\d+");
             *                      List<string> arr = new List<string>();
             *                      MatchCollection mc = rg.Matches(decodeDataNXT2);
             *                      foreach (Match i in mc)
             *                          arr.Add(i.ToString());
             *                      //Distance;
             *                      txtData.Rows[0].Cells[2].Value = arr[1];  //NXT2
             *                      //Beta
             *                      txtData.Rows[1].Cells[2].Value = arr[0];
             *                      //QrNum
             *                      txtData.Rows[2].Cells[2].Value = arr[1];
             *                  }
             *              }*/
        }