Skip to content

Commit 3a2ed1c

Browse files
authored
Merge pull request #3483 from SinM9:wechat_qrcode_perf_tests
Wechat qrcode perfomance tests
2 parents c07438c + be0850b commit 3a2ed1c

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
#include "perf_precomp.hpp"
5+
6+
static
7+
void initQRTests()
8+
{
9+
#ifdef HAVE_OPENCV_DNN
10+
const char* extraTestDataPath =
11+
#ifdef WINRT
12+
NULL;
13+
#else
14+
getenv("OPENCV_DNN_TEST_DATA_PATH");
15+
#endif
16+
if (extraTestDataPath)
17+
cvtest::addDataSearchPath(extraTestDataPath);
18+
#endif // HAVE_OPENCV_DNN
19+
}
20+
21+
CV_PERF_TEST_MAIN(wechat_qrcode, initQRTests())
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef __OPENCV_PERF_PRECOMP_HPP__
6+
#define __OPENCV_PERF_PRECOMP_HPP__
7+
8+
#include "opencv2/ts.hpp"
9+
#include "opencv2/wechat_qrcode.hpp"
10+
11+
namespace opencv_test {
12+
using namespace cv::wechat_qrcode;
13+
}
14+
15+
#endif
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#include "perf_precomp.hpp"
6+
namespace opencv_test
7+
{
8+
namespace
9+
{
10+
std::string qrcode_model_path[] = {"", "dnn/wechat_2021-01"};
11+
12+
std::string qrcode_images_name[] = {
13+
"version_1_top.jpg",
14+
"version_2_left.jpg", "version_2_up.jpg", "version_2_top.jpg",
15+
"version_3_down.jpg", "version_3_top.jpg",
16+
"version_4_top.jpg",
17+
"version_5_down.jpg", "version_5_left.jpg", "version_5_up.jpg", "version_5_top.jpg",
18+
"russian.jpg", "kanji.jpg", "link_wiki_cv.jpg"};
19+
20+
std::string qrcode_images_multiple[] = {"2_qrcodes.png", "3_qrcodes.png", "3_close_qrcodes.png",
21+
"4_qrcodes.png", "5_qrcodes.png", "7_qrcodes.png"};
22+
23+
WeChatQRCode createQRDetectorWithDNN(std::string& model_path)
24+
{
25+
string path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel;
26+
if (!model_path.empty())
27+
{
28+
path_detect_prototxt = findDataFile(model_path + "/detect.prototxt", false);
29+
path_detect_caffemodel = findDataFile(model_path + "/detect.caffemodel", false);
30+
path_sr_prototxt = findDataFile(model_path + "/sr.prototxt", false);
31+
path_sr_caffemodel = findDataFile(model_path + "/sr.caffemodel", false);
32+
}
33+
return WeChatQRCode(path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel);
34+
}
35+
36+
typedef ::perf::TestBaseWithParam< tuple< std::string,std::string > > Perf_Objdetect_QRCode;
37+
38+
PERF_TEST_P_(Perf_Objdetect_QRCode, detect_and_decode)
39+
{
40+
std::string model_path = get<0>(GetParam());
41+
std::string name_current_image = get<1>(GetParam());
42+
const std::string root = "cv/qrcode/";
43+
44+
std::string image_path = findDataFile(root + name_current_image);
45+
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
46+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
47+
48+
std::vector< Mat > corners;
49+
std::vector< String > decoded_info;
50+
auto detector = createQRDetectorWithDNN(model_path);
51+
// warmup
52+
if (!model_path.empty())
53+
{
54+
decoded_info = detector.detectAndDecode(src, corners);
55+
}
56+
TEST_CYCLE()
57+
{
58+
decoded_info = detector.detectAndDecode(src, corners);
59+
ASSERT_FALSE(decoded_info[0].empty());
60+
}
61+
SANITY_CHECK_NOTHING();
62+
}
63+
64+
typedef ::perf::TestBaseWithParam< tuple< std::string,std::string > > Perf_Objdetect_QRCode_Multi;
65+
66+
PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, detect_and_decode)
67+
{
68+
std::string model_path = get<0>(GetParam());
69+
std::string name_current_image = get<1>(GetParam());
70+
const std::string root = "cv/qrcode/multiple/";
71+
72+
std::string image_path = findDataFile(root + name_current_image);
73+
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
74+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
75+
76+
std::vector< Mat > corners;
77+
std::vector< String > decoded_info;
78+
auto detector = createQRDetectorWithDNN(model_path);
79+
// warmup
80+
if (!model_path.empty())
81+
{
82+
decoded_info = detector.detectAndDecode(src, corners);
83+
}
84+
TEST_CYCLE()
85+
{
86+
decoded_info = detector.detectAndDecode(src, corners);
87+
ASSERT_TRUE(decoded_info.size());
88+
}
89+
for(size_t i = 0; i < decoded_info.size(); i++)
90+
{
91+
ASSERT_FALSE(decoded_info[i].empty());
92+
}
93+
SANITY_CHECK_NOTHING();
94+
}
95+
96+
typedef ::perf::TestBaseWithParam< tuple<std::string, std::string, Size> >Perf_Objdetect_Not_QRCode;
97+
98+
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect_and_decode)
99+
{
100+
std::string model_path = get<0>(GetParam());
101+
std::string type_gen = get<1>(GetParam());
102+
Size resolution = get<2>(GetParam());
103+
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
104+
if (type_gen == "random")
105+
{
106+
RNG rng;
107+
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
108+
}
109+
else if (type_gen == "chessboard")
110+
{
111+
uint8_t next_pixel = 255;
112+
for (int j = 0; j < not_qr_code.cols; j++)
113+
{
114+
not_qr_code.ptr<uchar>(0)[j] = next_pixel;
115+
next_pixel = 255 - next_pixel;
116+
}
117+
for (int r = not_qr_code.cols; r < not_qr_code.rows * not_qr_code.cols; r++)
118+
{
119+
int i = r / not_qr_code.cols;
120+
int j = r % not_qr_code.cols;
121+
not_qr_code.ptr<uchar>(i)[j] = 255 - not_qr_code.ptr<uchar>(i-1)[j];
122+
}
123+
}
124+
std::vector< Mat > corners;
125+
std::vector< String > decoded_info;
126+
auto detector = createQRDetectorWithDNN(model_path);
127+
// warmup
128+
if (!model_path.empty())
129+
{
130+
decoded_info = detector.detectAndDecode(not_qr_code, corners);
131+
}
132+
TEST_CYCLE()
133+
{
134+
decoded_info = detector.detectAndDecode(not_qr_code, corners);
135+
ASSERT_FALSE(decoded_info.size());
136+
}
137+
SANITY_CHECK_NOTHING();
138+
}
139+
140+
141+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode,
142+
::testing::Combine(
143+
::testing::ValuesIn(qrcode_model_path),
144+
::testing::ValuesIn(qrcode_images_name)
145+
));
146+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode_Multi,
147+
::testing::Combine(
148+
::testing::ValuesIn(qrcode_model_path),
149+
::testing::ValuesIn(qrcode_images_multiple)
150+
));
151+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode,
152+
::testing::Combine(
153+
::testing::ValuesIn(qrcode_model_path),
154+
::testing::Values("zero", "random", "chessboard"),
155+
::testing::Values(Size(640, 480), Size(1280, 720))
156+
));
157+
158+
} // namespace
159+
} // namespace

0 commit comments

Comments
 (0)