mirror of
https://github.com/opencv/opencv.git
synced 2024-12-13 07:59:27 +08:00
b2db959619
Fix barcode detectAndDecode #25035 The method `detectAndDecode()` in the `BarcodeDetector` class doesn't return the barcode corners. This PR fixes the and add test for `detectAndDecode`. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
121 lines
3.8 KiB
C++
121 lines
3.8 KiB
C++
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
#include "perf_precomp.hpp"
|
|
#include "opencv2/objdetect/barcode.hpp"
|
|
|
|
namespace opencv_test{namespace{
|
|
|
|
typedef ::perf::TestBaseWithParam< tuple<string, cv::Size> > Perf_Barcode_multi;
|
|
typedef ::perf::TestBaseWithParam< tuple<string, cv::Size> > Perf_Barcode_single;
|
|
|
|
PERF_TEST_P_(Perf_Barcode_multi, detect)
|
|
{
|
|
const string root = "cv/barcode/multiple/";
|
|
const string name_current_image = get<0>(GetParam());
|
|
const cv::Size sz = get<1>(GetParam());
|
|
const string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path);
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
cv::resize(src, src, sz);
|
|
|
|
vector< Point > corners;
|
|
auto bardet = barcode::BarcodeDetector();
|
|
bool res = false;
|
|
TEST_CYCLE()
|
|
{
|
|
res = bardet.detectMulti(src, corners);
|
|
}
|
|
SANITY_CHECK_NOTHING();
|
|
ASSERT_TRUE(res);
|
|
ASSERT_EQ(16ull, corners.size());
|
|
}
|
|
|
|
PERF_TEST_P_(Perf_Barcode_multi, detect_decode)
|
|
{
|
|
const string root = "cv/barcode/multiple/";
|
|
const string name_current_image = get<0>(GetParam());
|
|
const cv::Size sz = get<1>(GetParam());
|
|
const string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path);
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
cv::resize(src, src, sz);
|
|
|
|
vector<std::string> decoded_info;
|
|
vector<std::string> decoded_type;
|
|
vector< Point > corners;
|
|
auto bardet = barcode::BarcodeDetector();
|
|
bool res = false;
|
|
TEST_CYCLE()
|
|
{
|
|
res = bardet.detectAndDecodeWithType(src, decoded_info, decoded_type, corners);
|
|
}
|
|
SANITY_CHECK_NOTHING();
|
|
ASSERT_TRUE(res);
|
|
ASSERT_EQ(16ull, corners.size());
|
|
ASSERT_EQ(4ull, decoded_info.size());
|
|
}
|
|
|
|
PERF_TEST_P_(Perf_Barcode_single, detect)
|
|
{
|
|
const string root = "cv/barcode/single/";
|
|
const string name_current_image = get<0>(GetParam());
|
|
const cv::Size sz = get<1>(GetParam());
|
|
const string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path);
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
cv::resize(src, src, sz);
|
|
|
|
vector< Point > corners;
|
|
auto bardet = barcode::BarcodeDetector();
|
|
bool res = false;
|
|
TEST_CYCLE()
|
|
{
|
|
res = bardet.detectMulti(src, corners);
|
|
}
|
|
SANITY_CHECK_NOTHING();
|
|
ASSERT_TRUE(res);
|
|
ASSERT_EQ(4ull, corners.size());
|
|
}
|
|
|
|
PERF_TEST_P_(Perf_Barcode_single, detect_decode)
|
|
{
|
|
const string root = "cv/barcode/single/";
|
|
const string name_current_image = get<0>(GetParam());
|
|
const cv::Size sz = get<1>(GetParam());
|
|
const string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path);
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
cv::resize(src, src, sz);
|
|
|
|
vector<std::string> decoded_info;
|
|
vector<std::string> decoded_type;
|
|
vector< Point > corners;
|
|
auto bardet = barcode::BarcodeDetector();
|
|
bool res = false;
|
|
TEST_CYCLE()
|
|
{
|
|
res = bardet.detectAndDecodeWithType(src, decoded_info, decoded_type, corners);
|
|
}
|
|
SANITY_CHECK_NOTHING();
|
|
ASSERT_TRUE(res);
|
|
ASSERT_EQ(4ull, corners.size());
|
|
ASSERT_EQ(1ull, decoded_info.size());
|
|
}
|
|
|
|
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_multi,
|
|
testing::Combine(
|
|
testing::Values("4_barcodes.jpg"),
|
|
testing::Values(cv::Size(2041, 2722), cv::Size(1361, 1815), cv::Size(680, 907))));
|
|
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_single,
|
|
testing::Combine(
|
|
testing::Values("book.jpg", "bottle_1.jpg", "bottle_2.jpg"),
|
|
testing::Values(cv::Size(480, 360), cv::Size(640, 480), cv::Size(800, 600))));
|
|
|
|
}} //namespace
|