联合OpenCV4.5.2利用微信开源的库识别二维码

Posted Helloorld_1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了联合OpenCV4.5.2利用微信开源的库识别二维码相关的知识,希望对你有一定的参考价值。

首先参考链接如下:https://mp.weixin.qq.com/s/2GZAJAUPHTXFOKDRv-D21Q

有以下问题:

(1)只有opencv_contrib4.5.2及其以上版本的modeule中才有wechat_qrcode,注意按照上述链接中4.5.1的版本是没有的哟!

(2)利用cmake去编译contribu库时,需要注意,不要勾选python,不然后面生成项目时,会报错的。

我的使用版本是:opencv4.5.2,opencv_contrib4.5.2,VS2017;(debug+x64位)

这里是我编译好的文件,请自取:

https://download.csdn.net/download/Helloorld_1/87446941

核心模块文件下载地址:

https://github.com/WeChatCV/opencv_3rdparty

以下是用来测试的代码:

#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.jpg");
	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);

以上是关于联合OpenCV4.5.2利用微信开源的库识别二维码的主要内容,如果未能解决你的问题,请参考以下文章

opencv结合微信二维码识别功能实现图片二维码识别

如何利用Halcon进行二维码QR码的识别

用HTML5 可以实现二维码扫描识别的功能吗

Android扫描二维码(基于华为HMS Core)

利用CommaTool工具解决微信内链接或二维码可直接用外部浏览器打开

微信小程序问题,二维码如何识别?