首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >[C#]OpenCvSharp利用微信二维码引擎实现二维码识别

[C#]OpenCvSharp利用微信二维码引擎实现二维码识别

作者头像
云未归来
发布2025-07-20 13:46:50
发布2025-07-20 13:46:50
4050
举报

介绍 微信开源了其二维码的解码功能,并贡献给 OpenCV 社区。其开源的 wechat_qrcode 项目被收录到 OpenCV contrib 项目中。从 OpenCV 4.5.2 版本开始,就可以直接使用。 该项目 github 地址:

https://github.com/opencv/opencv_contrib/tree/master/modules/wechat_qrcode

模型文件的地址:

https://github.com/WeChatCV/opencv_3rdparty

微信的扫码引擎,很早就支持了远距离二维码检测、自动调焦定位、多码检测识别等功能,它是基于 CNN 的二维码检测。

OpenCvSharp在 4.6.0.20220608 版本也加入了支持

效果:

测试环境:

vs2019

net framework4.7.2

opencvsharp4.8.0

代码:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FIRC;
using OpenCvSharp;

namespace FIRC
{
    public partial class Form1 : Form
    {
        Mat src = new Mat();
        QRManager qm = new QRManager();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图文件(*.*)|*.jpg;*.png;*.jpeg;*.bmp";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect = false;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
              
                src = Cv2.ImRead(openFileDialog.FileName);
                pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src);


            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(pictureBox1.Image==null)
            {
                return;
            }
            Mat[] rects;
            string[] texts;
            qm.Inference(src,out rects,out texts);
            Console.WriteLine(string.Format("检测到了{0}个二维码",rects.Length));
            var resultMat = qm.DrawImage(rects,texts,src);
            pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat); //Mat转Bitmap
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            qm.LoadWeights();
        }
    }
}

代码优点:

封装成类直接几句即可调用,方便二次开发,同时为了照顾新手源码直接下载即可正常运行,注意要选x64 debug即可

视频演示:

OpenCvSharp利用微信二维码引擎实现二维码识别_哔哩哔哩_bilibili测试环境:vs2019net framework4.7.2opencvsharp4.8.0, 视频播放量 2、弹幕量 0、点赞数 0、投硬币枚数 0、收藏人数 0、转发人数 0, 视频作者 未来自主研究中心, 作者简介 未来自主研究中心,相关视频:微信最恶心的两个设置,记得关闭,否则再多的内存都不够用!,微信聊天打字太慢?用这三种方法,一分钟能打出上百字!,paddleocr快速训练助手文本识别版使用教程,pdf文件区域ocr识别自动重命名文件工具使用教程,C#实现图文描述生成imagecaption图像生成文字描述,怎么翻墻网站登录chatgpt,电脑如何翻墻使用chatgpt,chatgpt手机版,最新ChatGPT4.0免费使用教程,[数据集介绍][目标检测]城市道路交通事故数据集VOC格式1182张,labelme简单使用教程,python3.12安装dlib模块,真·跳到你面前!裸眼3D到底是什么?不会看?UP手把手教你!

https://www.bilibili.com/video/BV11e411q7RE/?vd_source=989ae2b903ea1b5acebbe2c4c4a635ee

源码下载地址:

https://download.csdn.net/download/FL1623863129/88681827

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-12-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档