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