Skip to content

Commit a568233

Browse files
author
Maksim Milaschenko
committed
add barcode perf tests
1 parent 960b3f6 commit a568233

File tree

6 files changed

+214
-4
lines changed

6 files changed

+214
-4
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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{namespace{
8+
9+
typedef ::perf::TestBaseWithParam< string > Perf_Barcode_multi;
10+
typedef ::perf::TestBaseWithParam< string > Perf_Barcode_single;
11+
12+
PERF_TEST_P_(Perf_Barcode_multi, detect)
13+
{
14+
const string name_current_image = GetParam();
15+
const string root = "cv/barcode/multiple/";
16+
17+
auto bardet = barcode::BarcodeDetector();
18+
vector< Point > corners;
19+
string image_path = findDataFile(root + name_current_image);
20+
Mat src = imread(image_path);
21+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
22+
23+
cout << src.size << endl;
24+
TEST_CYCLE() ASSERT_TRUE(bardet.detect(src, corners));
25+
26+
SANITY_CHECK_NOTHING();
27+
}
28+
29+
PERF_TEST_P_(Perf_Barcode_multi, decode)
30+
{
31+
const string name_current_image = GetParam();
32+
const string root = "cv/barcode/multiple/";
33+
34+
auto bardet = barcode::BarcodeDetector();
35+
vector<cv::String> decoded_info;
36+
vector<barcode::BarcodeType> decoded_type;
37+
vector< Point > corners;
38+
string image_path = findDataFile(root + name_current_image);
39+
40+
Mat src = imread(image_path);
41+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
42+
43+
cout << src.size << endl;
44+
bardet.detect(src, corners);
45+
46+
TEST_CYCLE() ASSERT_TRUE(bardet.decode(src, corners, decoded_info, decoded_type));
47+
SANITY_CHECK_NOTHING();
48+
}
49+
50+
PERF_TEST_P_(Perf_Barcode_single, detect)
51+
{
52+
const string name_current_image = GetParam();
53+
const string root = "cv/barcode/single/";
54+
auto bardet = barcode::BarcodeDetector();
55+
vector< Point > corners;
56+
string image_path = findDataFile(root + name_current_image);
57+
Mat src = imread(image_path);
58+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
59+
60+
cout << src.size << endl;
61+
TEST_CYCLE() ASSERT_TRUE(bardet.detect(src, corners));
62+
SANITY_CHECK_NOTHING();
63+
}
64+
65+
PERF_TEST_P_(Perf_Barcode_single, decode)
66+
{
67+
const string name_current_image = GetParam();
68+
const string root = "cv/barcode/single/";
69+
70+
auto bardet = barcode::BarcodeDetector();
71+
vector<cv::String> decoded_info;
72+
vector<barcode::BarcodeType> decoded_type;
73+
74+
string image_path = findDataFile(root + name_current_image);
75+
Mat src = imread(image_path);
76+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
77+
vector< Point > corners;
78+
79+
cout << src.size << endl;
80+
bardet.detect(src, corners);
81+
82+
TEST_CYCLE() ASSERT_TRUE(bardet.decode(src, corners, decoded_info, decoded_type));
83+
SANITY_CHECK_NOTHING();
84+
}
85+
86+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_multi, ::testing::Values("4_barcodes.jpg"));
87+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_single, ::testing::Values("book.jpg", "bottle_1.jpg", "bottle_2.jpg"));
88+
89+
}} //namespace

modules/barcode/perf/perf_main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
using namespace perf;
8+
9+
CV_PERF_TEST_MAIN(barcode)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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/barcode.hpp"
10+
11+
#endif

modules/barcode/test/perf_barcode

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include "test_precomp.hpp"
2+
3+
namespace opencv_test{namespace{
4+
5+
typedef ::perf::TestBaseWithParam< string > Perf_Barcode_multi;
6+
typedef ::perf::TestBaseWithParam< string > Perf_Barcode_single;
7+
8+
PERF_TEST_P_(Perf_Barcode_multi, detect)
9+
{
10+
const string name_current_image = GetParam();
11+
const string root = "barcode/multiple/";
12+
13+
auto bardet = barcode::BarcodeDetector();
14+
vector< Point > corners;
15+
string image_path = findDataFile(root + name_current_image);
16+
Mat src = imread(image_path);
17+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
18+
19+
cout << src.size << endl;
20+
TEST_CYCLE() ASSERT_TRUE(bardet.detect(src, corners));
21+
22+
SANITY_CHECK(corners);
23+
}
24+
25+
PERF_TEST_P_(Perf_Barcode_multi, decode)
26+
{
27+
const string name_current_image = GetParam();
28+
const string root = "barcode/multiple/";
29+
30+
auto bardet = barcode::BarcodeDetector();
31+
vector<cv::String> decoded_info;
32+
vector<barcode::BarcodeType> decoded_type;
33+
vector< Point > corners;
34+
string image_path = findDataFile(root + name_current_image);
35+
36+
Mat src = imread(image_path);
37+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
38+
39+
cout << src.size << endl;
40+
bardet.detect(src, corners);
41+
42+
TEST_CYCLE() bardet.decode(src, corners, decoded_info, decoded_type);
43+
SANITY_CHECK(corners);
44+
}
45+
46+
PERF_TEST_P_(Perf_Barcode_single, detect)
47+
{
48+
const string name_current_image = GetParam();
49+
const string root = "barcode/single/";
50+
auto bardet = barcode::BarcodeDetector();
51+
vector< Point > corners;
52+
string image_path = findDataFile(root + name_current_image);
53+
Mat src = imread(image_path);
54+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
55+
56+
cout << src.size << endl;
57+
TEST_CYCLE() ASSERT_TRUE(bardet.detect(src, corners));
58+
SANITY_CHECK(corners);
59+
}
60+
61+
PERF_TEST_P_(Perf_Barcode_single, decode)
62+
{
63+
const string name_current_image = GetParam();
64+
const string root = "barcode/single/";
65+
66+
auto bardet = barcode::BarcodeDetector();
67+
vector<cv::String> decoded_info;
68+
vector<barcode::BarcodeType> decoded_type;
69+
70+
string image_path = findDataFile(root + name_current_image);
71+
Mat src = imread(image_path);
72+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
73+
vector< Point > corners;
74+
75+
cout << src.size << endl;
76+
bardet.detect(src, corners);
77+
78+
TEST_CYCLE() bardet.decode(src, corners, decoded_info, decoded_type);
79+
SANITY_CHECK(corners);
80+
}
81+
82+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_multi, ::testing::Values("4_barcodes.jpg"));
83+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_single, ::testing::Values("book.jpg", "bottle_1.jpg", "bottle_2.jpg"));
84+
85+
}} //namespace

modules/wechat_qrcode/src/zxing/qrcode/decoder/decoded_bit_stream_parser.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void DecodedBitStreamParser::append(std::string& result, string const& in,
6565

6666
void DecodedBitStreamParser::append(std::string& result, const char* bufIn, size_t nIn,
6767
ErrorHandler& err_handler) {
68-
if (err_handler.ErrCode()) return;
68+
// avoid null pointer exception
69+
if (err_handler.ErrCode() || bufIn == nullptr) return;
6970
#ifndef NO_ICONV_INSIDE
7071
if (nIn == 0) {
7172
return;
@@ -190,16 +191,20 @@ void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits_, string& res
190191
CharacterSetECI* currentCharacterSetECI,
191192
ArrayRef<ArrayRef<char> >& byteSegments,
192193
ErrorHandler& err_handler) {
193-
int nBytes = count;
194194
BitSource& bits(*bits_);
195195
// Don't crash trying to read more bits than we have available.
196196
int available = bits.available();
197197
// try to repair count data if count data is invalid
198198
if (count * 8 > available) {
199-
count = (available + 7 / 8);
199+
count = (available + 7) / 8;
200200
}
201+
size_t nBytes = count;
202+
203+
ArrayRef<char> bytes_(nBytes);
204+
// issue https://github.com/opencv/opencv_contrib/issues/3478
205+
if (bytes_->empty())
206+
return;
201207

202-
ArrayRef<char> bytes_(count);
203208
char* readBytes = &(*bytes_)[0];
204209
for (int i = 0; i < count; i++) {
205210
// readBytes[i] = (char) bits.readBits(8);

modules/wechat_qrcode/test/test_qrcode.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,5 +455,16 @@ TEST_P(Objdetect_QRCode_Easy_Multi, regression) {
455455
std::string qrcode_model_path[] = {"", "dnn/wechat_2021-01"};
456456
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Easy_Multi, testing::ValuesIn(qrcode_model_path));
457457

458+
TEST(Objdetect_QRCode_bug, issue_3478) {
459+
auto detector = wechat_qrcode::WeChatQRCode();
460+
std::string image_path = findDataFile("qrcode/issue_3478.png");
461+
Mat src = imread(image_path, IMREAD_GRAYSCALE);
462+
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
463+
std::vector<std::string> outs = detector.detectAndDecode(src);
464+
ASSERT_EQ(1, (int) outs.size());
465+
ASSERT_EQ(16, (int) outs[0].size());
466+
ASSERT_EQ("KFCVW50 ", outs[0]);
467+
}
468+
458469
} // namespace
459470
} // namespace opencv_test

0 commit comments

Comments
 (0)