QR码网络摄像头扫描仪c#

时间:2013-07-02 11:26:46

标签: c# webcam qr-code barcode-scanner

我尝试了各种 QR码库和网络摄像头捕获技术。在特定时间间隔内捕获照片然后将其发送到 QR码库似乎是一个好主意,但检测 QR码的成功率非常低。任何人都可以推荐一种更好的方法来通过网络摄像头检测 QR码吗?非常感谢:)

代码:

void FinalVideo_NewFrame(object sender,NewFrameEventArgs eventArgs)         {

        Bitmap video = (Bitmap)eventArgs.Frame.Clone();

        pictureBox1.Image = video;
        try
        {
            com.google.zxing.qrcode.decoder.Decoder objDecoder = new com.google.zxing.qrcode.decoder.Decoder();
            Bitmap bitmap = new Bitmap(pictureBox1.Image);
            com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width,bitmap.Height); 
            var binarizer = new HybridBinarizer(source);
            var binBitmap = new BinaryBitmap(binarizer);
            QRCodeReader qrCodeReader = new QRCodeReader();
            string str = new MultiFormatReader().decode(binBitmap).Text;
            MessageBox.Show(str);

        }
        catch
        {

        }

}

我还使用了messaging.toolkit.qrcode.dll。 代码如下:

private void mainWinForm_Load(object sender,EventArgs e)

    {

        webcam = new WebCam();
        webcam.InitializeWebCam(ref imgVideo);
        QRCodeDecoder decoder = new QRCodeDecoder();
        try
        {

            MessageBox.Show(decoder.decode(new QRCodeBitmapImage(imgCapture.Image as Bitmap)));
        }

        catch
        {
            //Do nothing
        }

    }

2 个答案:

答案 0 :(得分:1)

尝试使用AForge.NET库从网络摄像头捕获视频,然后使用ZXing.Net库读取QR码。

您可以按照这些Youtube教程进行操作,这些教程将展示如何使用AForge.Net从网络摄像头获取视频。 https://www.youtube.com/watch?v=osAOpsRYqVs&t=311s

对于QRs解码,我使用了以下每1秒执行一次的代码:

`

    private void decode_QRtag()
    {
        try
        {
            //pictureBox1 shows the web cam video
            Bitmap bitmap = new Bitmap(pictureBox1.Image);

            BarcodeReader reader = new BarcodeReader { AutoRotate = true, TryHarder = true };
            Result result = reader.Decode(bitmap);
            string decoded = result.ToString().Trim();        
            //capture a snapshot if there is a match
            PictureBox2.Image = bitmap;
            textBox1.Text = decoded;
        }
        catch 
        {
        }
    }`

答案 1 :(得分:0)

**For this you should install these packages
Install-Package AForge
Install-Package AForge.Video
Install-Package AForge.Video.DirectShow
Install-Package ZXing.Net

you can watch this video for more help
https://www.youtube.com/watch?v=wcoy0Gwxr50**




    using System.IO;
    using AForge;
    using AForge.Video;
    using AForge.Video.DirectShow;
    using ZXing;
    using ZXing.Aztec;


      private void Form1_Load(object sender, EventArgs e)
            {
                CaptureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                foreach (FilterInfo Device in CaptureDevice)
                {
                    comboBox1.Items.Add(Device.Name);
                }

                comboBox1.SelectedIndex = 0;
                FinalFrame = new VideoCaptureDevice();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                FinalFrame = new VideoCaptureDevice(CaptureDevice[comboBox1.SelectedIndex].MonikerString);
                FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);
                FinalFrame.Start();

            }

            private void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
            {
                pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
            }

            private void timer1_Tick(object sender, EventArgs e)
            {
                BarcodeReader Reader = new BarcodeReader();
                Result result = Reader.Decode((Bitmap)pictureBox1.Image);
                try
                {
                    string decoded = result.ToString().Trim();
                    if (decoded != "")
                    {
                        timer1.Stop();
                        MessageBox.Show(decoded);
                        Form2 form = new Form2();
                        form.Show();
                        this.Hide();

                    }
                }
                catch(Exception ex){

                }
            }

            private void button2_Click(object sender, EventArgs e)
            {
                timer1.Enabled = true;
                timer1.Start();
            }

            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                if (FinalFrame.IsRunning == true)
                {
                    FinalFrame.Stop();
                }
            }