二维码扫描仪扫描二维码内的小盒子

时间:2020-02-07 02:31:56

标签: qr-code opencvsharp

qrcode sample

大家好!我正在为QRCode扫描仪使用OpenCVSharp C#,除此QR码外,我还能检测到一些QR码,它会扫描QR码内部的小盒子(请参见上图),有什么办法可以避免这种情况?任何帮助将不胜感激!

private void btn_DetectObject_Click(object sender, EventArgs e)
    {
        if (srcImage == "") return;
        var haarCascade = new CascadeClassifier(cascadeXML);
        Mat src = new Mat(srcImage);

        Mat gray = new Mat();

        Mat result = src.Clone();
        Cv2.CvtColor(src, gray, ColorConversionCodes.BGR2GRAY);

        // 顔検出
        Rect[] faces = haarCascade.DetectMultiScale(
            gray, 1.08, 2, HaarDetectionType.FindBiggestObject, new OpenCvSharp.Size(30, 30)); //1.08 = scale 2 = number of neighbors

        if (faces.Length == 0)
        {
            System.Media.SystemSounds.Beep.Play();
        }
        else
        {
            // 検出した顔の位置に円を描画
            int n;
            for (n = 0; n < faces.Length; n++)
            {
                int x = faces[n].X;
                int y = faces[n].Y;
                int w = faces[n].Width;
                int h = faces[n].Height;
                int k = PicImageIpl.Image.Width;
                Cv2.Rectangle(result, new Rect(x, y, w, h), 0xff0000, 2);
                PicImageIpl.ImageIpl = result;

                float qrResult = (float)w / (float)k;
                MessageBox.Show(qrResult.ToString());
            }
        }
        src.Dispose();
        gray.Dispose();
        result.Dispose();
    }

这是我的检测代码,我使用了haarCascade。

0 个答案:

没有答案