当前位置: 首页 > 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.hskmm.com/?act=detail&tid=15783

相关文章:

  • 数字孪生 + 碳痕追踪:MyEMS 给能源管理装了套 “全链路全景导航”
  • 空间复杂度和时间复杂度
  • 基于IOS26的iOS 内存分析与必要内存界定
  • 破局 “节能不省钱” 悖论:开源 EMS 生态如何让中小企业用 1/3 成本实现能效跃升?
  • iOS 26 性能测试实战,如何评估启动速度、CPUGPU 负载、帧率与系统资源适配(uni-app 与 iOS 原生应用性能方案)
  • P14062 【MX-X21-T7】[IAMOI R5] 若我不曾见过太阳 题解
  • unity确定性帧同步框架
  • 03-堆和栈
  • 视频汇聚平台EasyCVR如何构建智慧农业监控监管系统?
  • 一套自用的git提交规范,可清晰的识别到关联的任务/bug - 实践
  • 撕开厂商锁定黑箱:MyEMS 如何用开源代码夺回能源管理的 “自主控制权”?
  • 继续 Vibe Coding 撸工具:Markdown写作 + 一键发布
  • C造桥与砍树
  • Keil uVision5 MDK 5.42安装教程(支持ARM Cortex全系列开发)
  • 2024 ICPC ECfinal E
  • 从Void到Task<PublishAggregateResult>:一次服务方法返回类型重构的纠结与决策
  • LVGL移植到STM32F4出现无法运行的问题
  • 题目记录(Before NOIP2025 ver)
  • 专业修复sqlserver master 数据库损坏。
  • jenkins job的configure中配置git时 选择的credential为什么不能选择secret认证方式的数据
  • Day21继承
  • C# Avalonia 15- Animation- ImageWipe
  • 题解:P8067 [BalkanOI 2012] balls
  • 题解:P8300 [COCI 2012/2013 #2] INSPEKTOR
  • SuperHarness-3D低压柜机电协同设计方案!
  • 详细介绍:.NET驾驭Word之力:打造专业文档 - 页面设置与打印控制完全指南
  • 使用.NET标准库实现多任务并行处理的详细过程 - 实践
  • 模型训练中 平均损失值和平均准确率的深入理解
  • torch.max函数在分类问题中的使用 学习
  • godot3.6字典遍历