barcode.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_OBJDETECT_BARCODE_HPP
  6. #define OPENCV_OBJDETECT_BARCODE_HPP
  7. #include <opencv2/core.hpp>
  8. #include <opencv2/objdetect/graphical_code_detector.hpp>
  9. namespace cv {
  10. namespace barcode {
  11. //! @addtogroup objdetect_barcode
  12. //! @{
  13. class CV_EXPORTS_W_SIMPLE BarcodeDetector : public cv::GraphicalCodeDetector
  14. {
  15. public:
  16. /** @brief Initialize the BarcodeDetector.
  17. */
  18. CV_WRAP BarcodeDetector();
  19. /** @brief Initialize the BarcodeDetector.
  20. *
  21. * Parameters allow to load _optional_ Super Resolution DNN model for better quality.
  22. * @param prototxt_path prototxt file path for the super resolution model
  23. * @param model_path model file path for the super resolution model
  24. */
  25. CV_WRAP BarcodeDetector(CV_WRAP_FILE_PATH const std::string &prototxt_path, CV_WRAP_FILE_PATH const std::string &model_path);
  26. ~BarcodeDetector();
  27. /** @brief Decodes barcode in image once it's found by the detect() method.
  28. *
  29. * @param img grayscale or color (BGR) image containing bar code.
  30. * @param points vector of rotated rectangle vertices found by detect() method (or some other algorithm).
  31. * For N detected barcodes, the dimensions of this array should be [N][4].
  32. * Order of four points in vector<Point2f> is bottomLeft, topLeft, topRight, bottomRight.
  33. * @param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
  34. * @param decoded_type vector strings, specifies the type of these barcodes
  35. * @return true if at least one valid barcode have been found
  36. */
  37. CV_WRAP bool decodeWithType(InputArray img,
  38. InputArray points,
  39. CV_OUT std::vector<std::string> &decoded_info,
  40. CV_OUT std::vector<std::string> &decoded_type) const;
  41. /** @brief Both detects and decodes barcode
  42. * @param img grayscale or color (BGR) image containing barcode.
  43. * @param decoded_info UTF8-encoded output vector of string(s) or empty vector of string if the codes cannot be decoded.
  44. * @param decoded_type vector of strings, specifies the type of these barcodes
  45. * @param points optional output vector of vertices of the found barcode rectangle. Will be empty if not found.
  46. * @return true if at least one valid barcode have been found
  47. */
  48. CV_WRAP bool detectAndDecodeWithType(InputArray img,
  49. CV_OUT std::vector<std::string> &decoded_info,
  50. CV_OUT std::vector<std::string> &decoded_type,
  51. OutputArray points = noArray()) const;
  52. /** @brief Get detector downsampling threshold.
  53. *
  54. * @return detector downsampling threshold
  55. */
  56. CV_WRAP double getDownsamplingThreshold() const;
  57. /** @brief Set detector downsampling threshold.
  58. *
  59. * By default, the detect method resizes the input image to this limit if the smallest image size is is greater than the threshold.
  60. * Increasing this value can improve detection accuracy and the number of results at the expense of performance.
  61. * Correlates with detector scales. Setting this to a large value will disable downsampling.
  62. * @param thresh downsampling limit to apply (default 512)
  63. * @see setDetectorScales
  64. */
  65. CV_WRAP BarcodeDetector& setDownsamplingThreshold(double thresh);
  66. /** @brief Returns detector box filter sizes.
  67. *
  68. * @param sizes output parameter for returning the sizes.
  69. */
  70. CV_WRAP void getDetectorScales(CV_OUT std::vector<float>& sizes) const;
  71. /** @brief Set detector box filter sizes.
  72. *
  73. * Adjusts the value and the number of box filters used in the detect step.
  74. * The filter sizes directly correlate with the expected line widths for a barcode. Corresponds to expected barcode distance.
  75. * If the downsampling limit is increased, filter sizes need to be adjusted in an inversely proportional way.
  76. * @param sizes box filter sizes, relative to minimum dimension of the image (default [0.01, 0.03, 0.06, 0.08])
  77. */
  78. CV_WRAP BarcodeDetector& setDetectorScales(const std::vector<float>& sizes);
  79. /** @brief Get detector gradient magnitude threshold.
  80. *
  81. * @return detector gradient magnitude threshold.
  82. */
  83. CV_WRAP double getGradientThreshold() const;
  84. /** @brief Set detector gradient magnitude threshold.
  85. *
  86. * Sets the coherence threshold for detected bounding boxes.
  87. * Increasing this value will generate a closer fitted bounding box width and can reduce false-positives.
  88. * Values between 16 and 1024 generally work, while too high of a value will remove valid detections.
  89. * @param thresh gradient magnitude threshold (default 64).
  90. */
  91. CV_WRAP BarcodeDetector& setGradientThreshold(double thresh);
  92. };
  93. //! @}
  94. }} // cv::barcode::
  95. #endif // OPENCV_OBJDETECT_BARCODE_HPP