【OpenCV】2020年关于SIFT/SURF专利版权问题的解决办法

分类: pythonlua |
前言
OpenCV 3.4之后因专利版权问题移除了SIFT/SURF的相关库,因此在使用较新版本的cv库时会报错
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::SIFT::create’
而网上如今绝大多数解决方法都是回退OpenCV的版本+装contrib支持库,这样还意味着你需要回退或者创建一个支持3.4之前的python版本虚拟环境(如py35、py36),总而言之就是相当麻烦!
解决办法
好消息是2020年3月17日之后一代传奇算法SIFT专利到期了!因此只需更新cv版本即可免费使用!
https://img-blog.csdnimg.cn/20201108164418154.png#pic_center
https://img-blog.csdnimg.cn/202011081638421.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NsZWFubGlp,size_16,color_FFFFFF,t_70#pic_center
如图,我这里使用的是4.4.0.44版本,已经可以成功跑起来了。
后记
另外一个有趣的发现是,如果你沿用之前的代码即
descriptor = cv2.xfeatures2d.SIFT_create()
会出现一个warning
[ WARN:0] global c:\users\appveyor\appdata\local\temp\1\pip-req-build-wwma2wne\opencv_contrib\modules\xfeatures2d\misc\python\shadow_sift.hpp (15)
cv::xfeatures2d::SIFT_create DEPRECATED:
cv.xfeatures2d.SIFT_create() is deprecated due SIFT tranfer to the main repository.
这是因为新版本的SIFT可以直接引用,不再需要安装contrib包,即
descriptor = cv2.SIFT_create()
官方公告可参见 OpenCV Google Summer of Code 2020