#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
cv::Mat img = imread("3.png");//读取本地的一张图片便显示出来
Mat gray;
cvtColor(img, gray, COLOR_RGB2GRAY);
Mat SE = getStructuringElement(MORPH_RECT, Size(1, 7));
dilate(gray, gray, SE);
cv::QRCodeDetector QRdetecter;
std::vector<cv::Point> list;
cv::Mat res;
/*bool b = QRdetecter.detect(gray, list);
if (b)
{
string str = QRdetecter.decode(gray, list);
printf("%s\n", str);
printf("1111\n");
}*/
string str = QRdetecter.detectAndDecode(gray, list, res);
printf("%s\n", str);
printf("1111\n");
for (int j = 0; j < list.size(); j++)
{
if (j == 3)
line(img, list[j], list[0], Scalar(0, 255, 0), 2);
else
line(img, list[j], list[j + 1], Scalar(0, 255, 0), 2);
}
namedWindow("1", 0);
imshow("1", img);
if (res.data)
{
namedWindow("2", 0);
imshow("2", res);
}
waitKey(-1);
return 0;
}