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

Aak*_*ubu 2 c# webcam qr-code barcode-scanner

我尝试过各种二维码库和网络摄像头捕获技术。在特定时间间隔内捕获照片然后将其发送到二维码库似乎是一个好主意,但检测二维码的成功率极低。谁能推荐一种通过网络摄像头检测二维码的更好方法?多谢 :)

代码:

void FinalVideo_NewFrame(对象发送者, 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
        {

        }
Run Code Online (Sandbox Code Playgroud)

}

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

私有无效mainWinForm_Load(对象发送者,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
        }

    }
Run Code Online (Sandbox Code Playgroud)

rug*_*312 5

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

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

至于 QR 解码,我使用了以下代码,每 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 
        {
        }
    }`
Run Code Online (Sandbox Code Playgroud)