test_qr_utils.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include "test_precomp.hpp"
  5. namespace opencv_test {
  6. static inline
  7. void check_qr(const string& root, const string& name_current_image, const string& config_name,
  8. const std::vector<Point>& corners,
  9. const std::vector<string>& decoded_info, const int max_pixel_error,
  10. bool isMulti = false) {
  11. const std::string dataset_config = findDataFile(root + "dataset_config.json");
  12. FileStorage file_config(dataset_config, FileStorage::READ);
  13. ASSERT_TRUE(file_config.isOpened()) << "Can't read validation data: " << dataset_config;
  14. FileNode images_list = file_config[config_name];
  15. size_t images_count = static_cast<size_t>(images_list.size());
  16. ASSERT_GT(images_count, 0u) << "Can't find validation data entries in 'test_images': " << dataset_config;
  17. for (size_t index = 0; index < images_count; index++) {
  18. FileNode config = images_list[(int)index];
  19. std::string name_test_image = config["image_name"];
  20. if (name_test_image == name_current_image) {
  21. if (isMulti) {
  22. for(int j = 0; j < int(corners.size()); j += 4) {
  23. bool ok = false;
  24. for (int k = 0; k < int(corners.size() / 4); k++) {
  25. int count_eq_points = 0;
  26. for (int i = 0; i < 4; i++) {
  27. int x = config["x"][k][i];
  28. int y = config["y"][k][i];
  29. if(((abs(corners[j + i].x - x)) <= max_pixel_error) && ((abs(corners[j + i].y - y)) <= max_pixel_error))
  30. count_eq_points++;
  31. }
  32. if (count_eq_points == 4) {
  33. ok = true;
  34. break;
  35. }
  36. }
  37. EXPECT_TRUE(ok);
  38. }
  39. }
  40. else {
  41. for (int i = 0; i < (int)corners.size(); i++) {
  42. int x = config["x"][i];
  43. int y = config["y"][i];
  44. EXPECT_NEAR(x, corners[i].x, max_pixel_error);
  45. EXPECT_NEAR(y, corners[i].y, max_pixel_error);
  46. }
  47. }
  48. if (decoded_info.size() == 0ull)
  49. return;
  50. if (isMulti) {
  51. size_t count_eq_info = 0;
  52. for(int i = 0; i < int(decoded_info.size()); i++) {
  53. for(int j = 0; j < int(decoded_info.size()); j++) {
  54. std::string original_info = config["info"][j];
  55. if(original_info == decoded_info[i]) {
  56. count_eq_info++;
  57. break;
  58. }
  59. }
  60. }
  61. EXPECT_EQ(decoded_info.size(), count_eq_info);
  62. }
  63. else {
  64. std::string original_info = config["info"];
  65. EXPECT_EQ(decoded_info[0], original_info);
  66. }
  67. return; // done
  68. }
  69. }
  70. FAIL() << "Not found results for '" << name_current_image << "' image in config file:" << dataset_config <<
  71. "Re-run tests with enabled UPDATE_QRCODE_TEST_DATA macro to update test data.\n";
  72. }
  73. }