Skip to content

Commit e05c63a

Browse files
author
Mariya Sinitsina
committed
add perfomance tests for wechat qrcode
1 parent ccc2772 commit e05c63a

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
CV_PERF_TEST_MAIN(wechat_qrcode)
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: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
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+
7+
namespace opencv_test
8+
{
9+
namespace
10+
{
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+
bool Find_Models_Files(std::vector<std::string>& models) {
24+
string path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel;
25+
string model_version = "_2021-01";
26+
path_detect_prototxt = findDataFile("dnn/wechat"+model_version+"/detect.prototxt", false);
27+
path_detect_caffemodel = findDataFile("dnn/wechat"+model_version+"/detect.caffemodel", false);
28+
path_sr_prototxt = findDataFile("dnn/wechat"+model_version+"/sr.prototxt", false);
29+
path_sr_caffemodel = findDataFile("dnn/wechat"+model_version+"/sr.caffemodel", false);
30+
models = {path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel};
31+
return true;
32+
}
33+
34+
typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode;
35+
36+
PERF_TEST_P_(Perf_Objdetect_QRCode, detect_and_decode_without_nn)
37+
{
38+
const std::string name_current_image = GetParam();
39+
const std::string root = "cv/qrcode/";
40+
41+
std::string image_path = findDataFile(root + name_current_image);
42+
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
43+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
44+
45+
std::vector< Mat > corners;
46+
auto detector = wechat_qrcode::WeChatQRCode();
47+
48+
TEST_CYCLE()
49+
{
50+
auto decoded_info = detector.detectAndDecode(src, corners);
51+
ASSERT_FALSE(decoded_info[0].empty());
52+
}
53+
SANITY_CHECK_NOTHING();
54+
}
55+
56+
PERF_TEST_P_(Perf_Objdetect_QRCode, detect_and_decode)
57+
{
58+
const std::string name_current_image = GetParam();
59+
const std::string root = "cv/qrcode/";
60+
61+
std::string image_path = findDataFile(root + name_current_image);
62+
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
63+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
64+
65+
std::vector< Mat > corners;
66+
std::vector<std::string> models;
67+
ASSERT_TRUE(Find_Models_Files(models));
68+
auto detector = wechat_qrcode::WeChatQRCode(models[0], models[1], models[2], models[3]);
69+
TEST_CYCLE()
70+
{
71+
auto decoded_info = detector.detectAndDecode(src, corners);
72+
ASSERT_FALSE(decoded_info[0].empty());
73+
}
74+
SANITY_CHECK_NOTHING();
75+
}
76+
77+
typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode_Multi;
78+
79+
PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, detect_and_decode_without_nn)
80+
{
81+
const std::string name_current_image = GetParam();
82+
const std::string root = "cv/qrcode/multiple/";
83+
84+
std::string image_path = findDataFile(root + name_current_image);
85+
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
86+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
87+
88+
std::vector< Mat > corners;
89+
auto detector = wechat_qrcode::WeChatQRCode();
90+
91+
TEST_CYCLE()
92+
{
93+
auto decoded_info = detector.detectAndDecode(src, corners);
94+
ASSERT_TRUE(decoded_info.size());
95+
for(size_t i = 0; i < decoded_info.size(); i++)
96+
{
97+
ASSERT_FALSE(decoded_info[i].empty());
98+
}
99+
}
100+
SANITY_CHECK_NOTHING();
101+
}
102+
103+
PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, detect_and_decode)
104+
{
105+
const std::string name_current_image = GetParam();
106+
const std::string root = "cv/qrcode/multiple/";
107+
108+
std::string image_path = findDataFile(root + name_current_image);
109+
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
110+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
111+
112+
std::vector<std::string> models;
113+
ASSERT_TRUE(Find_Models_Files(models));
114+
auto detector = wechat_qrcode::WeChatQRCode(models[0], models[1], models[2], models[3]);
115+
std::vector< Mat > corners;
116+
TEST_CYCLE()
117+
{
118+
auto decoded_info = detector.detectAndDecode(src, corners);
119+
ASSERT_TRUE(decoded_info.size());
120+
for(size_t i = 0; i < decoded_info.size(); i++)
121+
{
122+
ASSERT_FALSE(decoded_info[i].empty());
123+
}
124+
}
125+
SANITY_CHECK_NOTHING();
126+
}
127+
128+
typedef ::perf::TestBaseWithParam< tuple< std::string, Size > > Perf_Objdetect_Not_QRCode;
129+
130+
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect_and_decode_without_nn)
131+
{
132+
std::string type_gen = get<0>(GetParam());
133+
Size resolution = get<1>(GetParam());
134+
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
135+
if (type_gen == "random")
136+
{
137+
RNG rng;
138+
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
139+
}
140+
if (type_gen == "chessboard")
141+
{
142+
uint8_t next_pixel = 0;
143+
for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
144+
{
145+
int i = r / not_qr_code.cols;
146+
int j = r % not_qr_code.cols;
147+
not_qr_code.ptr<uchar>(i)[j] = next_pixel;
148+
next_pixel = 255 - next_pixel;
149+
}
150+
}
151+
std::vector< Mat > corners;
152+
auto detector = wechat_qrcode::WeChatQRCode();
153+
154+
TEST_CYCLE()
155+
{
156+
auto decoded_info = detector.detectAndDecode(not_qr_code, corners);
157+
ASSERT_FALSE(decoded_info.size());
158+
}
159+
SANITY_CHECK_NOTHING();
160+
}
161+
162+
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect_and_decode)
163+
{
164+
std::string type_gen = get<0>(GetParam());
165+
Size resolution = get<1>(GetParam());
166+
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
167+
if (type_gen == "random")
168+
{
169+
RNG rng;
170+
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
171+
}
172+
if (type_gen == "chessboard")
173+
{
174+
uint8_t next_pixel = 0;
175+
for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
176+
{
177+
int i = r / not_qr_code.cols;
178+
int j = r % not_qr_code.cols;
179+
not_qr_code.ptr<uchar>(i)[j] = next_pixel;
180+
next_pixel = 255 - next_pixel;
181+
}
182+
}
183+
std::vector< Mat > corners;
184+
std::vector<std::string> models;
185+
ASSERT_TRUE(Find_Models_Files(models));
186+
auto detector = wechat_qrcode::WeChatQRCode(models[0], models[1], models[2], models[3]);
187+
188+
TEST_CYCLE()
189+
{
190+
auto decoded_info = detector.detectAndDecode(not_qr_code, corners);
191+
ASSERT_FALSE(decoded_info.size());
192+
}
193+
SANITY_CHECK_NOTHING();
194+
}
195+
196+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode, testing::ValuesIn(qrcode_images_name));
197+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode_Multi, testing::ValuesIn(qrcode_images_multiple));
198+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode,
199+
::testing::Combine(
200+
::testing::Values("zero", "random", "chessboard"),
201+
::testing::Values(Size(640, 480), Size(1280, 720))
202+
));
203+
204+
} // namespace
205+
} // namespace

0 commit comments

Comments
 (0)