dnn_superres.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifndef _OPENCV_DNN_SUPERRES_HPP_
  5. #define _OPENCV_DNN_SUPERRES_HPP_
  6. /** @defgroup dnn_superres DNN used for super resolution
  7. This module contains functionality for upscaling an image via convolutional neural networks.
  8. The following four models are implemented:
  9. - EDSR <https://arxiv.org/abs/1707.02921>
  10. - ESPCN <https://arxiv.org/abs/1609.05158>
  11. - FSRCNN <https://arxiv.org/abs/1608.00367>
  12. - LapSRN <https://arxiv.org/abs/1710.01992>
  13. */
  14. #include "opencv2/core.hpp"
  15. #include "opencv2/dnn.hpp"
  16. namespace cv
  17. {
  18. namespace dnn_superres
  19. {
  20. //! @addtogroup dnn_superres
  21. //! @{
  22. /** @brief A class to upscale images via convolutional neural networks.
  23. The following four models are implemented:
  24. - edsr
  25. - espcn
  26. - fsrcnn
  27. - lapsrn
  28. */
  29. class CV_EXPORTS_W DnnSuperResImpl
  30. {
  31. private:
  32. /** @brief Net which holds the desired neural network
  33. */
  34. dnn::Net net;
  35. std::string alg; //algorithm
  36. int sc; //scale factor
  37. void reconstruct_YCrCb(InputArray inpImg, InputArray origImg, OutputArray outpImg, int scale);
  38. void preprocess_YCrCb(InputArray inpImg, OutputArray outpImg);
  39. public:
  40. /** @brief Empty constructor for python
  41. */
  42. CV_WRAP static Ptr<DnnSuperResImpl> create();
  43. // /** @brief Empty constructor
  44. // */
  45. DnnSuperResImpl();
  46. /** @brief Constructor which immediately sets the desired model
  47. @param algo String containing one of the desired models:
  48. - __edsr__
  49. - __espcn__
  50. - __fsrcnn__
  51. - __lapsrn__
  52. @param scale Integer specifying the upscale factor
  53. */
  54. DnnSuperResImpl(const String& algo, int scale);
  55. /** @brief Read the model from the given path
  56. @param path Path to the model file.
  57. */
  58. CV_WRAP void readModel(const String& path);
  59. /** @brief Read the model from the given path
  60. @param weights Path to the model weights file.
  61. @param definition Path to the model definition file.
  62. */
  63. void readModel(const String& weights, const String& definition);
  64. /** @brief Set desired model
  65. @param algo String containing one of the desired models:
  66. - __edsr__
  67. - __espcn__
  68. - __fsrcnn__
  69. - __lapsrn__
  70. @param scale Integer specifying the upscale factor
  71. */
  72. CV_WRAP void setModel(const String& algo, int scale);
  73. /** @brief Set computation backend
  74. */
  75. CV_WRAP void setPreferableBackend(int backendId);
  76. /** @brief Set computation target
  77. */
  78. CV_WRAP void setPreferableTarget(int targetId);
  79. /** @brief Upsample via neural network
  80. @param img Image to upscale
  81. @param result Destination upscaled image
  82. */
  83. CV_WRAP void upsample(InputArray img, OutputArray result);
  84. /** @brief Upsample via neural network of multiple outputs
  85. @param img Image to upscale
  86. @param imgs_new Destination upscaled images
  87. @param scale_factors Scaling factors of the output nodes
  88. @param node_names Names of the output nodes in the neural network
  89. */
  90. CV_WRAP void upsampleMultioutput(InputArray img, std::vector<Mat> &imgs_new, const std::vector<int>& scale_factors, const std::vector<String>& node_names);
  91. /** @brief Returns the scale factor of the model:
  92. @return Current scale factor.
  93. */
  94. CV_WRAP int getScale();
  95. /** @brief Returns the scale factor of the model:
  96. @return Current algorithm.
  97. */
  98. CV_WRAP String getAlgorithm();
  99. };
  100. //! @} dnn_superres
  101. }} // cv::dnn_superres::
  102. #endif