From 7c4b873ba316d90dd618e62ec5d157f1950ab80b Mon Sep 17 00:00:00 2001 From: Lukas-Alexander Weber <32765578+lukasalexanderweber@users.noreply.github.com> Date: Wed, 24 Mar 2021 16:02:20 +0100 Subject: [PATCH] Merge pull request #19762 from lukasalexanderweber:master MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Error Message for SURF if not implemented In OpenCV 4.5.1 import cv2 as cv cv.xfeatures2d_SURF.create will not create an AttributeError, even if the function is excluded (no nonfree option) In Line 305 (now 306) however ´finder = FEATURES_FIND_CHOICES[args.features]()´ will raise an error: OpenCV(4.5.1) ..\opencv_contrib\modules\xfeatures2d\src\surf.cpp:1029: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SURF::create' So we should check with cv.xfeatures2d_SURF.create() correctly if SURF is available --- samples/python/stitching_detailed.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/python/stitching_detailed.py b/samples/python/stitching_detailed.py index cd3f063e35..7bf5a9ac0d 100644 --- a/samples/python/stitching_detailed.py +++ b/samples/python/stitching_detailed.py @@ -29,8 +29,9 @@ BA_COST_CHOICES['no'] = cv.detail_NoBundleAdjuster FEATURES_FIND_CHOICES = OrderedDict() try: + cv.xfeatures2d_SURF.create() # check if the function can be called FEATURES_FIND_CHOICES['surf'] = cv.xfeatures2d_SURF.create -except AttributeError: +except (AttributeError, cv.error) as e: print("SURF not available") # if SURF not available, ORB is default FEATURES_FIND_CHOICES['orb'] = cv.ORB.create