Qt使用wechat_qrcode,编译报错!

最近学习opencv,看见扩展库里有wechat_qrcode一项,忍不住想试一下。

参照网上的例子,编写如下代码,但是报错,不知道错在哪里,百思不得解。

#include "widget.h"
#include "ui_widget.h"

#include 

#include 
#include 
#include 
#include 

#include 

using namespace std;
using namespace cv;

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    Ptr detector;

    const std::string detect_prototxt = "c:/opencv/wechat_qrcode/detect.prototxt";
    const std::string detect_caffe_model = "c:/opencv/wechat_qrcode/detect.caffemodel";
    const std::string sr_prototxt = "c:/opencv/wechat_qrcode/sr.prototxt";
    const std::string sr_caffe_model = "c:/opencv/wechat_qrcode/sr.caffemodel";

    detector = makePtr(detect_prototxt, detect_caffe_model,sr_prototxt, sr_caffe_model);



}

Widget::~Widget()
{
    delete ui;
}

运行结果及详细报错内容:
C:\Qt\Qt5.12.10\Tools\mingw730_64\lib\gcc\x86_64-w64-mingw32\7.3.0\include\c++\ext\new_allocator.h:136: error: undefined reference to `cv::wechat_qrcode::WeChatQRCode::WeChatQRCode(std::__cxx11::basic_stringconst&, std::__cxx11::basic_stringconst&, std::__cxx11::basic_stringconst&, std::__cxx11::basic_stringconst&)'

首先,可以检查一下 c:/opencv/wechat_qrcode/ 目录下是否存在 detect.prototxt,detect.caffemodel,sr.prototxt,sr.caffemodel 这四个文件。如果没有这些文件,则可能导致出现这个错误。

另外,在 Windows 系统中,路径分隔符使用的是反斜杠 '',而不是斜杠 '/'。可以把代码中的斜杠全部改为反斜杠,然后重新编译。

例如,将:

const std::string detect_prototxt = "c:/opencv/wechat_qrcode/detect.prototxt";

改为:

const std::string detect_prototxt = "c:\opencv\wechat_qrcode\detect.prototxt";

如果问题仍然存在,还可以尝试检查一下项目中是否包含 opencv_wechat_qrcode 这个库,或者检查一下这个库是否在系统中正确安装。