diff --git a/modules/objdetect/src/barcode_decoder/common/super_scale.cpp b/modules/objdetect/src/barcode_decoder/common/super_scale.cpp index 0c9f75f156..4b7099a27d 100644 --- a/modules/objdetect/src/barcode_decoder/common/super_scale.cpp +++ b/modules/objdetect/src/barcode_decoder/common/super_scale.cpp @@ -8,11 +8,14 @@ #include "../../precomp.hpp" #include "super_scale.hpp" - -#ifdef HAVE_OPENCV_DNN +#include "opencv2/core.hpp" +#include "opencv2/core/utils/logger.hpp" namespace cv { namespace barcode { + +#ifdef HAVE_OPENCV_DNN + constexpr static float MAX_SCALE = 4.0f; int SuperScale::init(const std::string &proto_path, const std::string &model_path) @@ -71,7 +74,26 @@ int SuperScale::superResolutionScale(const Mat &src, Mat &dst) } return 0; } + +#else // HAVE_OPENCV_DNN + +int SuperScale::init(const std::string &proto_path, const std::string &model_path) +{ + CV_UNUSED(proto_path); + CV_UNUSED(model_path); + return 0; +} + +void SuperScale::processImageScale(const Mat &src, Mat &dst, float scale, const bool & isEnabled, int sr_max_size) +{ + CV_UNUSED(sr_max_size); + if (isEnabled) + { + CV_LOG_WARNING(NULL, "objdetect/barcode: SuperScaling disabled - OpenCV has been built without DNN support"); + } + resize(src, dst, Size(), scale, scale, INTER_CUBIC); +} +#endif // HAVE_OPENCV_DNN + } // namespace barcode } // namespace cv - -#endif // HAVE_OPENCV_DNN diff --git a/modules/objdetect/src/barcode_decoder/common/super_scale.hpp b/modules/objdetect/src/barcode_decoder/common/super_scale.hpp index 70e47424e4..024ea86e54 100644 --- a/modules/objdetect/src/barcode_decoder/common/super_scale.hpp +++ b/modules/objdetect/src/barcode_decoder/common/super_scale.hpp @@ -9,8 +9,8 @@ #define OPENCV_BARCODE_SUPER_SCALE_HPP #ifdef HAVE_OPENCV_DNN - -#include "opencv2/dnn.hpp" +# include "opencv2/dnn.hpp" +#endif namespace cv { namespace barcode { @@ -26,44 +26,16 @@ public: void processImageScale(const Mat &src, Mat &dst, float scale, const bool &use_sr, int sr_max_size = 160); +#ifdef HAVE_OPENCV_DNN private: dnn::Net srnet_; bool net_loaded_ = false; int superResolutionScale(const cv::Mat &src, cv::Mat &dst); +#endif }; -} // namespace barcode -} // namespace cv - -#else // HAVE_OPENCV_DNN - -#include "opencv2/core.hpp" -#include "opencv2/core/utils/logger.hpp" - -namespace cv { -namespace barcode { - -class SuperScale -{ -public: - int init(const std::string &, const std::string &) - { - return 0; - } - void processImageScale(const Mat &src, Mat &dst, float scale, const bool & isEnabled, int) - { - if (isEnabled) - { - CV_LOG_WARNING(NULL, "objdetect/barcode: SuperScaling disabled - OpenCV has been built without DNN support"); - } - resize(src, dst, Size(), scale, scale, INTER_CUBIC); - } -}; - -} // namespace barcode -} // namespace cv - -#endif // !HAVE_OPENCV_DNN +} // namespace barcode +} // namespace cv #endif // OPENCV_BARCODE_SUPER_SCALE_HPP