这段代码使用了wechat_qrcode,无法解析二维码,如何修改
环境:vs2022创建的mfc项目
使用:opencv - 4.10.0 + opencv_contrib
解析二维码的代码:
// 线程
UINT ThreadProc(LPVOID pParam)
{
//加载图片解码
Ptr<wechat_qrcode::WeChatQRCode> detector;
string basepath = "D:/MyDatas/myapps/MFCApplication2/x64/Debug/";
string detect_prototxt = basepath + "model/detect.prototxt";
string detect_caffe_model = basepath + "model/detect.caffemodel";
string sr_prototxt = basepath + "model/sr.prototxt";
string sr_caffe_model = basepath + "model/sr.caffemodel";
try
{
detector = makePtr<wechat_qrcode::WeChatQRCode>(detect_prototxt, detect_caffe_model,
sr_prototxt, sr_caffe_model);
}
catch (const std::exception& e)
{
AfxMessageBox("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.");
}
CMFCApplication2Dlg* ti = (CMFCApplication2Dlg*)pParam;
//1.从摄像头读入视频
VideoCapture cap(0);
//2.循环显示每一帧
while (1)
{
bool isrun;
isrun = !(WaitForSingleObject(ti->event1, 5) == WAIT_OBJECT_0);
if (!isrun)
{
break;
}
Mat cam;
cap >> cam;//获取当前帧图像
//imshow("camera", cam);//显示当前帧图像
Mat img = cam;
vector<Mat> vPoints;
vector<String> strDecoded;
strDecoded = detector->detectAndDecode(img, vPoints);
for (int i = 0; i < strDecoded.size(); i++)
{
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(5);
}
destroyAllWindows();
cap.release();
return 0;
}
Ptr<wechat_qrcode::WeChatQRCode> detector 加载完毕,
detector->detectAndDecode无法解析二维码,如何修改