2018-07-11 01:24:09 +08:00
|
|
|
// 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.
|
2018-06-27 21:37:10 +08:00
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
namespace opencv_test { namespace {
|
2018-07-11 01:24:09 +08:00
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
std::string qrcode_images_name[] = {
|
2018-08-07 22:37:51 +08:00
|
|
|
// "20110817_030.jpg",
|
2018-07-11 01:24:09 +08:00
|
|
|
"20110817_048.jpg",
|
|
|
|
"img_20120226_161648.jpg",
|
|
|
|
"img_2714.jpg",
|
|
|
|
"img_2716.jpg",
|
|
|
|
"img_3011.jpg",
|
|
|
|
"img_3029.jpg",
|
|
|
|
"img_3070.jpg",
|
|
|
|
"qr_test_030.jpg"
|
|
|
|
};
|
|
|
|
|
|
|
|
// #define UPDATE_QRCODE_TEST_DATA
|
|
|
|
#ifdef UPDATE_QRCODE_TEST_DATA
|
|
|
|
|
|
|
|
TEST(Objdetect_QRCode, generate_test_data)
|
2018-06-27 21:37:10 +08:00
|
|
|
{
|
2018-07-24 18:08:58 +08:00
|
|
|
const std::string root = "qrcode/";
|
|
|
|
const std::string dataset_config = findDataFile(root + "dataset_config.json");
|
2018-07-11 01:24:09 +08:00
|
|
|
FileStorage file_config(dataset_config, FileStorage::WRITE);
|
|
|
|
|
|
|
|
file_config << "test_images" << "[";
|
2018-07-24 18:08:58 +08:00
|
|
|
size_t images_count = sizeof(qrcode_images_name) / sizeof(qrcode_images_name[0]);
|
2018-07-11 01:24:09 +08:00
|
|
|
for (size_t i = 0; i < images_count; i++)
|
|
|
|
{
|
|
|
|
file_config << "{:" << "image_name" << qrcode_images_name[i];
|
2018-07-24 18:08:58 +08:00
|
|
|
std::string image_path = findDataFile(root + qrcode_images_name[i]);
|
|
|
|
std::vector<Point> corners;
|
2018-07-11 01:24:09 +08:00
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE);
|
2018-07-24 18:08:58 +08:00
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
EXPECT_TRUE(detectQRCode(src, corners));
|
2018-07-11 01:24:09 +08:00
|
|
|
file_config << "x" << "[:";
|
2018-07-24 18:08:58 +08:00
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
2018-07-11 01:24:09 +08:00
|
|
|
file_config << "]";
|
|
|
|
file_config << "y" << "[:";
|
2018-07-24 18:08:58 +08:00
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].y; }
|
2018-07-11 01:24:09 +08:00
|
|
|
file_config << "]" << "}";
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
file_config.release();
|
2018-06-27 21:37:10 +08:00
|
|
|
}
|
|
|
|
|
2018-07-11 01:24:09 +08:00
|
|
|
#else
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
typedef testing::TestWithParam< std::string > Objdetect_QRCode;
|
2018-07-11 01:24:09 +08:00
|
|
|
TEST_P(Objdetect_QRCode, regression)
|
|
|
|
{
|
2018-07-24 18:08:58 +08:00
|
|
|
const std::string name_current_image = GetParam();
|
|
|
|
const std::string root = "qrcode/";
|
2018-07-11 01:24:09 +08:00
|
|
|
const int pixels_error = 3;
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
2018-07-11 01:24:09 +08:00
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE);
|
2018-07-24 18:08:58 +08:00
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
|
|
|
|
std::vector<Point> corners;
|
2018-08-07 22:37:51 +08:00
|
|
|
ASSERT_TRUE(detectQRCode(src, corners));
|
2018-07-11 01:24:09 +08:00
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
const std::string dataset_config = findDataFile(root + "dataset_config.json", false);
|
|
|
|
FileStorage file_config(dataset_config, FileStorage::READ);
|
|
|
|
ASSERT_TRUE(file_config.isOpened()) << "Can't read validation data: " << dataset_config;
|
2018-07-11 01:24:09 +08:00
|
|
|
{
|
|
|
|
FileNode images_list = file_config["test_images"];
|
2018-07-24 18:08:58 +08:00
|
|
|
size_t images_count = static_cast<size_t>(images_list.size());
|
|
|
|
ASSERT_GT(images_count, 0u) << "Can't find validation data entries in 'test_images': " << dataset_config;
|
2018-07-11 01:24:09 +08:00
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
for (size_t index = 0; index < images_count; index++)
|
2018-07-11 01:24:09 +08:00
|
|
|
{
|
2018-07-24 18:08:58 +08:00
|
|
|
FileNode config = images_list[(int)index];
|
|
|
|
std::string name_test_image = config["image_name"];
|
2018-07-11 01:24:09 +08:00
|
|
|
if (name_test_image == name_current_image)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2018-07-24 18:08:58 +08:00
|
|
|
int x = config["x"][i];
|
|
|
|
int y = config["y"][i];
|
2018-07-11 01:24:09 +08:00
|
|
|
EXPECT_NEAR(x, corners[i].x, pixels_error);
|
|
|
|
EXPECT_NEAR(y, corners[i].y, pixels_error);
|
|
|
|
}
|
2018-07-24 18:08:58 +08:00
|
|
|
return; // done
|
2018-07-11 01:24:09 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-24 18:08:58 +08:00
|
|
|
std::cerr
|
|
|
|
<< "Not found results for '" << name_current_image
|
|
|
|
<< "' image in config file:" << dataset_config << std::endl
|
|
|
|
<< "Re-run tests with enabled UPDATE_QRCODE_TEST_DATA macro to update test data."
|
|
|
|
<< std::endl;
|
2018-07-11 01:24:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode, testing::ValuesIn(qrcode_images_name));
|
|
|
|
|
2018-07-11 01:24:09 +08:00
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
|
|
|
|
TEST(Objdetect_QRCode_basic, not_found_qrcode)
|
2018-07-11 01:24:09 +08:00
|
|
|
{
|
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat zero_image = Mat::zeros(256, 256, CV_8UC1);
|
|
|
|
EXPECT_FALSE(detectQRCode(zero_image, corners));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
|
|
|
|
#endif // UPDATE_QRCODE_TEST_DATA
|
|
|
|
|
|
|
|
}} // namespace
|