wechat_qrcode.hpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. //
  5. // Tencent is pleased to support the open source community by making WeChat QRCode available.
  6. // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  7. #ifndef __OPENCV_WECHAT_QRCODE_HPP__
  8. #define __OPENCV_WECHAT_QRCODE_HPP__
  9. #include "opencv2/core.hpp"
  10. /** @defgroup wechat_qrcode WeChat QR code detector for detecting and parsing QR code.
  11. */
  12. namespace cv {
  13. namespace wechat_qrcode {
  14. //! @addtogroup wechat_qrcode
  15. //! @{
  16. /**
  17. * @brief WeChat QRCode includes two CNN-based models:
  18. * A object detection model and a super resolution model.
  19. * Object detection model is applied to detect QRCode with the bounding box.
  20. * super resolution model is applied to zoom in QRCode when it is small.
  21. *
  22. */
  23. class CV_EXPORTS_W WeChatQRCode {
  24. public:
  25. /**
  26. * @brief Initialize the WeChatQRCode.
  27. * It includes two models, which are packaged with caffe format.
  28. * Therefore, there are prototxt and caffe models (In total, four paramenters).
  29. *
  30. * @param detector_prototxt_path prototxt file path for the detector
  31. * @param detector_caffe_model_path caffe model file path for the detector
  32. * @param super_resolution_prototxt_path prototxt file path for the super resolution model
  33. * @param super_resolution_caffe_model_path caffe file path for the super resolution model
  34. */
  35. CV_WRAP WeChatQRCode(const std::string& detector_prototxt_path = "",
  36. const std::string& detector_caffe_model_path = "",
  37. const std::string& super_resolution_prototxt_path = "",
  38. const std::string& super_resolution_caffe_model_path = "");
  39. ~WeChatQRCode(){};
  40. /**
  41. * @brief Both detects and decodes QR code.
  42. * To simplify the usage, there is a only API: detectAndDecode
  43. *
  44. * @param img supports grayscale or color (BGR) image.
  45. * @param points optional output array of vertices of the found QR code quadrangle. Will be
  46. * empty if not found.
  47. * @return list of decoded string.
  48. */
  49. CV_WRAP std::vector<std::string> detectAndDecode(InputArray img, OutputArrayOfArrays points = noArray());
  50. /**
  51. * @brief set scale factor
  52. * QR code detector use neural network to detect QR.
  53. * Before running the neural network, the input image is pre-processed by scaling.
  54. * By default, the input image is scaled to an image with an area of 160000 pixels.
  55. * The scale factor allows to use custom scale the input image:
  56. * width = scaleFactor*width
  57. * height = scaleFactor*width
  58. *
  59. * scaleFactor valuse must be > 0 and <= 1, otherwise the scaleFactor value is set to -1
  60. * and use default scaled to an image with an area of 160000 pixels.
  61. */
  62. CV_WRAP void setScaleFactor(float _scalingFactor);
  63. CV_WRAP float getScaleFactor();
  64. protected:
  65. class Impl;
  66. Ptr<Impl> p;
  67. };
  68. //! @}
  69. } // namespace wechat_qrcode
  70. } // namespace cv
  71. #endif // __OPENCV_WECHAT_QRCODE_HPP__