mirror of
https://github.com/opencv/opencv.git
synced 2024-12-16 10:29:11 +08:00
9fa014edcd
Add detect qr with aruco #23264 Using Aruco to detect finder patterns to search QR codes. TODO (in next PR): - add single QR detect (update `detect()` and `detectAndDecode()`) - need reduce full enumeration of finder patterns - need add finder pattern info to `decode` step - need to merge the pipeline of the old and new algorithm [Current results:](https://docs.google.com/spreadsheets/d/1ufKyR-Zs-IGXwvqPgftssmTlceVjiQX364sbrjr2QU8/edit#gid=1192415584) +20% total detect, +8% total decode in OpenCV [QR benchmark](https://github.com/opencv/opencv_benchmarks/tree/develop/python_benchmarks/qr_codes) ![res1](https://user-images.githubusercontent.com/22337800/231228556-191d3eae-a318-44e1-af99-e7d420bf6248.png) 78.4% detect, 58.7% decode vs 58.5 detect, 50.5% decode in default [main.py.txt](https://github.com/opencv/opencv/files/10762369/main.py.txt) ![res2](https://user-images.githubusercontent.com/22337800/231229123-ed7f1eda-159a-444b-a3ff-f107d8eb4a20.png) add new info to [google docs](https://docs.google.com/spreadsheets/d/1ufKyR-Zs-IGXwvqPgftssmTlceVjiQX364sbrjr2QU8/edit?usp=sharing) ### 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 - [ ] 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
79 lines
3.4 KiB
C++
79 lines
3.4 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 "test_precomp.hpp"
|
|
|
|
namespace opencv_test {
|
|
|
|
static inline
|
|
void check_qr(const string& root, const string& name_current_image, const string& config_name,
|
|
const std::vector<Point>& corners,
|
|
const std::vector<string>& decoded_info, const int max_pixel_error,
|
|
bool isMulti = false) {
|
|
const std::string dataset_config = findDataFile(root + "dataset_config.json");
|
|
FileStorage file_config(dataset_config, FileStorage::READ);
|
|
ASSERT_TRUE(file_config.isOpened()) << "Can't read validation data: " << dataset_config;
|
|
FileNode images_list = file_config[config_name];
|
|
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;
|
|
for (size_t index = 0; index < images_count; index++) {
|
|
FileNode config = images_list[(int)index];
|
|
std::string name_test_image = config["image_name"];
|
|
if (name_test_image == name_current_image) {
|
|
if (isMulti) {
|
|
for(int j = 0; j < int(corners.size()); j += 4) {
|
|
bool ok = false;
|
|
for (int k = 0; k < int(corners.size() / 4); k++) {
|
|
int count_eq_points = 0;
|
|
for (int i = 0; i < 4; i++) {
|
|
int x = config["x"][k][i];
|
|
int y = config["y"][k][i];
|
|
if(((abs(corners[j + i].x - x)) <= max_pixel_error) && ((abs(corners[j + i].y - y)) <= max_pixel_error))
|
|
count_eq_points++;
|
|
}
|
|
if (count_eq_points == 4) {
|
|
ok = true;
|
|
break;
|
|
}
|
|
}
|
|
EXPECT_TRUE(ok);
|
|
}
|
|
}
|
|
else {
|
|
for (int i = 0; i < (int)corners.size(); i++) {
|
|
int x = config["x"][i];
|
|
int y = config["y"][i];
|
|
EXPECT_NEAR(x, corners[i].x, max_pixel_error);
|
|
EXPECT_NEAR(y, corners[i].y, max_pixel_error);
|
|
}
|
|
}
|
|
#ifdef HAVE_QUIRC
|
|
if (decoded_info.size() == 0ull)
|
|
return;
|
|
if (isMulti) {
|
|
size_t count_eq_info = 0;
|
|
for(int i = 0; i < int(decoded_info.size()); i++) {
|
|
for(int j = 0; j < int(decoded_info.size()); j++) {
|
|
std::string original_info = config["info"][j];
|
|
if(original_info == decoded_info[i]) {
|
|
count_eq_info++;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
EXPECT_EQ(decoded_info.size(), count_eq_info);
|
|
}
|
|
else {
|
|
std::string original_info = config["info"];
|
|
EXPECT_EQ(decoded_info[0], original_info);
|
|
}
|
|
#endif
|
|
return; // done
|
|
}
|
|
}
|
|
FAIL() << "Not found results for '" << name_current_image << "' image in config file:" << dataset_config <<
|
|
"Re-run tests with enabled UPDATE_QRCODE_TEST_DATA macro to update test data.\n";
|
|
}
|
|
|
|
}
|