barcode.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // Copyright (c) 2020-2021 darkliang wangberlinT Certseeds
  5. #ifndef __OPENCV_BARCODE_HPP__
  6. #define __OPENCV_BARCODE_HPP__
  7. #include <opencv2/core.hpp>
  8. #include <ostream>
  9. /** @defgroup barcode Barcode detecting and decoding methods
  10. */
  11. namespace cv {
  12. namespace barcode {
  13. //! @addtogroup barcode
  14. //! @{
  15. enum BarcodeType
  16. {
  17. NONE, EAN_8, EAN_13, UPC_A, UPC_E, UPC_EAN_EXTENSION
  18. };
  19. static inline std::ostream &operator<<(std::ostream &out, const BarcodeType &barcode_type)
  20. {
  21. switch (barcode_type)
  22. {
  23. case BarcodeType::EAN_8:
  24. out << "EAN_8";
  25. break;
  26. case BarcodeType::EAN_13:
  27. out << "EAN_13";
  28. break;
  29. case BarcodeType::UPC_E:
  30. out << "UPC_E";
  31. break;
  32. case BarcodeType::UPC_A:
  33. out << "UPC_A";
  34. break;
  35. case BarcodeType::UPC_EAN_EXTENSION:
  36. out << "UPC_EAN_EXTENSION";
  37. break;
  38. default:
  39. out << "NONE";
  40. }
  41. return out;
  42. }
  43. class CV_EXPORTS_W BarcodeDetector
  44. {
  45. public:
  46. /**
  47. * @brief Initialize the BarcodeDetector.
  48. * @param prototxt_path prototxt file path for the super resolution model
  49. * @param model_path model file path for the super resolution model
  50. */
  51. CV_WRAP BarcodeDetector(const std::string &prototxt_path = "", const std::string &model_path = "");
  52. ~BarcodeDetector();
  53. /** @brief Detects Barcode in image and returns the rectangle(s) containing the code.
  54. *
  55. * @param img grayscale or color (BGR) image containing (or not) Barcode.
  56. * @param points Output vector of vector of vertices of the minimum-area rotated rectangle containing the codes.
  57. * For N detected barcodes, the dimensions of this array should be [N][4].
  58. * Order of four points in vector< Point2f> is bottomLeft, topLeft, topRight, bottomRight.
  59. */
  60. CV_WRAP bool detect(InputArray img, OutputArray points) const;
  61. /** @brief Decodes barcode in image once it's found by the detect() method.
  62. *
  63. * @param img grayscale or color (BGR) image containing bar code.
  64. * @param points vector of rotated rectangle vertices found by detect() method (or some other algorithm).
  65. * For N detected barcodes, the dimensions of this array should be [N][4].
  66. * Order of four points in vector<Point2f> is bottomLeft, topLeft, topRight, bottomRight.
  67. * @param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
  68. * @param decoded_type vector of BarcodeType, specifies the type of these barcodes
  69. */
  70. CV_WRAP bool decode(InputArray img, InputArray points, CV_OUT std::vector<std::string> &decoded_info, CV_OUT
  71. std::vector<BarcodeType> &decoded_type) const;
  72. /** @brief Both detects and decodes barcode
  73. * @param img grayscale or color (BGR) image containing barcode.
  74. * @param decoded_info UTF8-encoded output vector of string(s) or empty vector of string if the codes cannot be decoded.
  75. * @param decoded_type vector of BarcodeType, specifies the type of these barcodes
  76. * @param points optional output vector of vertices of the found barcode rectangle. Will be empty if not found.
  77. */
  78. CV_WRAP bool detectAndDecode(InputArray img, CV_OUT std::vector<std::string> &decoded_info, CV_OUT
  79. std::vector<BarcodeType> &decoded_type, OutputArray points = noArray()) const;
  80. protected:
  81. struct Impl;
  82. Ptr<Impl> p;
  83. };
  84. //! @}
  85. }
  86. } // cv::barcode::
  87. #endif //__OPENCV_BARCODE_HPP__