当前位置: 首页 > news >正文

笔记_OpenCV4.5.1新增微信QRCode解码功能

原文地址:https://cloud.tencent.com/developer/article/1786320

 WeChatQRCode模块为OpenCV4.5.1新增功能,需要在github下载最新opencv源码master和contrib部分编译后使用。

下载和编译:

image

 

image

 

使用:

#include "pch.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/wechat_qrcode.hpp>using namespace std;
using namespace cv;int main()
{//加载图片解码Ptr<wechat_qrcode::WeChatQRCode> detector;string detect_prototxt = "./model/detect.prototxt";string detect_caffe_model = "./model/detect.caffemodel";string sr_prototxt = "./model/sr.prototxt";string sr_caffe_model = "./model/sr.caffemodel";Mat img = imread("./QR/T33/result.bmp");try {detector = makePtr<wechat_qrcode::WeChatQRCode>(detect_prototxt, detect_caffe_model,sr_prototxt, sr_caffe_model);}catch (const std::exception& e) {cout <<"\n---------------------------------------------------------------\n""Failed to initialize WeChatQRCode.\n""Please, download 'detector.*' and 'sr.*' from\n""https://github.com/WeChatCV/opencv_3rdparty/tree/wechat_qrcode\n""and put them into the current directory.\n""---------------------------------------------------------------\n";cout << e.what() << endl;return 0;}vector<Mat> vPoints;vector<String> strDecoded;strDecoded = detector->detectAndDecode(img, vPoints);for (int i = 0; i < strDecoded.size(); i++){cout << "decode-" << i+1 << ": " << strDecoded[i] << endl;Point pt1 = Point((int)vPoints[i].at<float>(0, 0), (int)vPoints[i].at<float>(0, 1));Point pt2 = Point((int)vPoints[i].at<float>(1, 0), (int)vPoints[i].at<float>(1, 1));Point pt3 = Point((int)vPoints[i].at<float>(2, 0), (int)vPoints[i].at<float>(2, 1));Point pt4 = Point((int)vPoints[i].at<float>(3, 0), (int)vPoints[i].at<float>(3, 1));line(img, pt1, pt2, Scalar(0, 255, 0), 2);line(img, pt2, pt3, Scalar(0, 255, 0), 2);line(img, pt3, pt4, Scalar(0, 255, 0), 2);line(img, pt4, pt1, Scalar(0, 255, 0), 2);putText(img, strDecoded[i], pt1, 0, 0.5, Scalar(255, 0, 0), 2);}imshow("wechat_qrcode", img);waitKey();imwrite("result.png", img);

结果示例:

image

 使用体验:非常适用APP开发者手机端扫码使用,如果是工业应用还需要自己做预处理和增强等步骤。

http://www.gsyq.cn/news/10864.html

相关文章:

  • 完整教程:模电基础:基本放大电路及其优化
  • 空间复杂度和时间复杂度
  • 实用指南:U盘歌单管理器 (专业车载音乐播放列表制作工具)
  • iOS 26 性能测试实战,如何评估启动速度、CPUGPU 负载、帧率与系统资源适配(uni-app 与 iOS 原生应用性能方案)
  • unity确定性帧同步框架
  • 03-堆和栈
  • 2024 ICPC ECfinal E
  • 专业修复sqlserver master 数据库损坏。
  • C# Avalonia 15- Animation- ImageWipe
  • 题解:P8067 [BalkanOI 2012] balls
  • godot3.6字典遍历
  • 安装 elasticsearch-9.1.4的 IK分词器
  • 完整教程:ArcGIS JSAPI 高级教程 - ArcGIS Maps SDK for JavaScript - 自定义(GLSL)修改高亮图层样式
  • css `isolation: isolate` - 详解
  • JVM 类加载器详解 - 实践
  • Unity小游戏接入抖音敏感词检测 - 指南
  • 域渗透靶场-vulntarget-a综合靶场
  • 在K8S中,网络通信模式有哪些?
  • 一文教你搞定PASS 2025:样本量计算神器安装到使用全流程
  • React 18.2中采用React Router 6.4
  • 题解:AT_abc257_h [ABC257Ex] Dice Sum 2
  • ClickHouse UPDATE 机制详解 - 若
  • ClickHouse index_granularity 详解 - 若
  • PADS笔记
  • clickhouse轻量级更新 - 若
  • 补充图
  • 域名+邮件推送+事件总线=实现每天定时邮件!
  • SOOMAL 降噪数据表
  • 案例分享|借助IronPDF IronOCR,打造医疗等行业的智能化解决方案
  • ClickHouse UPDATE 操作问题解决方案 - 若