3
3
// of this distribution and at http://opencv.org/license.html.
4
4
5
5
#include " perf_precomp.hpp"
6
-
7
6
namespace opencv_test
8
7
{
9
8
namespace
10
9
{
10
+ std::string qrcode_model_path[] = {" " , " dnn/wechat_2021-01" };
11
11
12
12
std::string qrcode_images_name[] = {
13
13
" version_1_top.jpg" ,
@@ -20,183 +20,137 @@ std::string qrcode_images_name[] = {
20
20
std::string qrcode_images_multiple[] = {" 2_qrcodes.png" , " 3_qrcodes.png" , " 3_close_qrcodes.png" ,
21
21
" 4_qrcodes.png" , " 5_qrcodes.png" , " 7_qrcodes.png" };
22
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)
23
+ WeChatQRCode createQRDetectorWithDNN (std::string& model_path)
37
24
{
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 ());
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 );
52
32
}
53
- SANITY_CHECK_NOTHING ( );
33
+ return WeChatQRCode (path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel );
54
34
}
55
35
36
+ typedef ::perf::TestBaseWithParam< tuple< std::string,std::string > > Perf_Objdetect_QRCode;
37
+
56
38
PERF_TEST_P_ (Perf_Objdetect_QRCode, detect_and_decode)
57
39
{
58
- const std::string name_current_image = GetParam ();
40
+ std::string model_path = get<0 >(GetParam ());
41
+ std::string name_current_image = get<1 >(GetParam ());
59
42
const std::string root = " cv/qrcode/" ;
60
43
61
44
std::string image_path = findDataFile (root + name_current_image);
62
45
Mat src = imread (image_path, IMREAD_GRAYSCALE), straight_barcode;
63
46
ASSERT_FALSE (src.empty ()) << " Can't read image: " << image_path;
64
47
65
48
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 ]);
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
+ }
69
56
TEST_CYCLE ()
70
57
{
71
- auto decoded_info = detector.detectAndDecode (src, corners);
58
+ decoded_info = detector.detectAndDecode (src, corners);
72
59
ASSERT_FALSE (decoded_info[0 ].empty ());
73
60
}
74
61
SANITY_CHECK_NOTHING ();
75
62
}
76
63
77
- typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode_Multi;
64
+ typedef ::perf::TestBaseWithParam< tuple< std::string,std::string > > Perf_Objdetect_QRCode_Multi;
78
65
79
- PERF_TEST_P_ (Perf_Objdetect_QRCode_Multi, detect_and_decode_without_nn)
66
+ PERF_TEST_P_ (Perf_Objdetect_QRCode_Multi, detect_and_decode)
80
67
{
81
- const std::string name_current_image = GetParam ();
68
+ std::string model_path = get<0 >(GetParam ());
69
+ std::string name_current_image = get<1 >(GetParam ());
82
70
const std::string root = " cv/qrcode/multiple/" ;
83
71
84
72
std::string image_path = findDataFile (root + name_current_image);
85
73
Mat src = imread (image_path, IMREAD_GRAYSCALE), straight_barcode;
86
74
ASSERT_FALSE (src.empty ()) << " Can't read image: " << image_path;
87
75
88
76
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
- }
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);
99
83
}
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
84
TEST_CYCLE ()
117
- {
118
- auto decoded_info = detector.detectAndDecode (src, corners);
85
+ {
86
+ decoded_info = detector.detectAndDecode (src, corners);
119
87
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
- }
88
+ }
89
+ for ( size_t i = 0 ; i < decoded_info. size (); i++)
90
+ {
91
+ ASSERT_FALSE (decoded_info[i]. empty ());
124
92
}
125
93
SANITY_CHECK_NOTHING ();
126
94
}
127
95
128
- typedef ::perf::TestBaseWithParam< tuple< std::string, Size > > Perf_Objdetect_Not_QRCode;
96
+ typedef ::perf::TestBaseWithParam< tuple<std::string, std::string, Size> >Perf_Objdetect_Not_QRCode;
129
97
130
- PERF_TEST_P_ (Perf_Objdetect_Not_QRCode, detect_and_decode_without_nn )
98
+ PERF_TEST_P_ (Perf_Objdetect_Not_QRCode, detect_and_decode )
131
99
{
132
- std::string type_gen = get<0 >(GetParam ());
133
- Size resolution = get<1 >(GetParam ());
100
+ std::string model_path = get<0 >(GetParam ());
101
+ std::string type_gen = get<1 >(GetParam ());
102
+ Size resolution = get<2 >(GetParam ());
134
103
Mat not_qr_code (resolution, CV_8UC1, Scalar (0 ));
135
104
if (type_gen == " random" )
136
105
{
137
106
RNG rng;
138
107
rng.fill (not_qr_code, RNG::UNIFORM, Scalar (0 ), Scalar (1 ));
139
108
}
140
- if (type_gen == " chessboard" )
109
+ else if (type_gen == " chessboard" )
141
110
{
142
- uint8_t next_pixel = 0 ;
143
- for (int r = 0 ; r < not_qr_code.rows * not_qr_code. cols ; r ++)
111
+ uint8_t next_pixel = 255 ;
112
+ for (int j = 0 ; j < not_qr_code.cols ; j ++)
144
113
{
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;
114
+ not_qr_code.ptr <uchar>(0 )[j] = next_pixel;
148
115
next_pixel = 255 - next_pixel;
149
116
}
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++)
117
+ for (int r = not_qr_code.cols ; r < not_qr_code.rows * not_qr_code.cols ; r++)
176
118
{
177
119
int i = r / not_qr_code.cols ;
178
120
int j = r % not_qr_code.cols ;
179
- not_qr_code.ptr <uchar>(i)[j] = next_pixel;
180
- next_pixel = 255 - next_pixel;
121
+ not_qr_code.ptr <uchar>(i)[j] = 255 - not_qr_code.ptr <uchar>(i-1 )[j];
181
122
}
182
123
}
183
124
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 ()
125
+ std::vector< String > decoded_info;
126
+ auto detector = createQRDetectorWithDNN (model_path);
127
+ // warmup
128
+ if (!model_path.empty ())
189
129
{
190
- auto decoded_info = detector.detectAndDecode (not_qr_code, corners);
130
+ decoded_info = detector.detectAndDecode (not_qr_code, corners);
131
+ }
132
+ TEST_CYCLE ()
133
+ {
134
+ decoded_info = detector.detectAndDecode (not_qr_code, corners);
191
135
ASSERT_FALSE (decoded_info.size ());
192
136
}
193
137
SANITY_CHECK_NOTHING ();
194
138
}
195
139
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));
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
+ ));
198
151
INSTANTIATE_TEST_CASE_P (/* nothing*/ , Perf_Objdetect_Not_QRCode,
199
152
::testing::Combine (
153
+ ::testing::ValuesIn (qrcode_model_path),
200
154
::testing::Values(" zero" , " random" , " chessboard" ),
201
155
::testing::Values(Size(640 , 480 ), Size(1280 , 720 ))
202
156
));
0 commit comments