原文地址

It's been two years already that I see the same subject that hangs on several times concerning SIFT and SURF which cause problems for some. there is always a post about these two.

First of all, you need to understand something: OpenCV is an open source library, which implements algorithms designed by researchers, some of these algorithms are free to use whether for personal or commercial use, others are free for personal use.

Beginning with a small explanation depending on the versions of OpenCV: opencv2 -> opencv3 -> opencv4 -> new_versions of opencv

  • We’re not going to talk about opencv 2 (I guess hardly anyone uses it right now). The only thing you have to remember from this version is that SIFT and SURF worked fine.
  • Since the release of OpenCV3, the SIFT and SURF implementations have been removed from the default installation of OpenCV 3, same for OpenCV 4.

The reason for removing SIFT and SURF is because of what OpenCV calls “non-free” algorithms. SIFT and SURF are (summer) both proprietary and patented algorithms, which means that you must technically obtain permission to use them in commercial algorithms (they are, however, free for academic and research purposes).

For this reason, OpenCV made the decision to move patented algorithms (with experimental implementations) to the package named "opencv_contrib". This means to access SIFT and SURF.

  • Case of OpenCV in C++: you have to compile and install OpenCV from source with opencv-contrib support enabled. (We will see this later)

  • Case of OpenCV in python: you need to install via pip the opencv-contrib-python package as follows:

    pip install opencv-contrib-python
    

however, in some of the versions of OpenCV 3, (the one you are having trouble with in python), both SIFT and SURF algorithms do not want to work, and you get this error: "module 'cv2.cv2' has no attribute 'xfeatures2d' ”.

I can give you an explanation (which is my own opinion), but before that you should know that the OpenCV python package is built by compiling the OpenCV source. Pythons packages are Wheel type files so the extension is ".whl".

So when you do ** pip install opencv-python **, you will actually consult this https://pypi.org/project/opencv-python/#files which will choose the wheel file corresponding to your configuration (operating system as well as the version of python), same for opencv-contrib-python whose link is the following https://pypi.org/project/opencv-contrib-python/#files.

So why don't SIFT and SURF work in all versions of OpenCV?

Hypothesis 1: Forget about activating extra modules, and non-free algorithms from the developers when compiling the source and building the opencv-contrib-python package. But since this problem is not present in just one release, but in ten, this generates a second hypothesis.

Hypothesis 2: it was done on purpose, but why?

Note: this is just my opinion, if anyone has the exact reason, please share it with us.

Version history and operation: from SIFT and SURF.

1- For SIFT (Tested):

sift = cv2.sift_create() # work in:
# 3.4.11, 4.4.0. ==> Sift became free since March 2020
sift = cv2.xfeatures2D.SIFT_create () # work in:
# 3.2.x, 3.3.x, 3.4.0, 3.4.1, 3.4.2, 3.4.10, 4.3.0, 4.4.0
sift = cv2.xfeatures2D.SIFT_create () # ==> Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create' (the versions where the problem is present)
# 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 3.4.8, 3.4.9, 4.0.x, 4.1.x, 4.2.x

2- For SURF (Supposed (Not test all)):

SURF = cv2.xfeatures2D.SURF_create () # work in :
# 3.2.x, 3.3.x, 3.4.0, 3.4.1, 3.4.2
SURF = cv2.xfeatures2D.SURF_create () # ==> Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create' (the versions where the problem is present)
# 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 3.4.8, 3.4.9, 3.4.10, 3.4.11, 4.0.x, 4.1.x, 4.2.x, 4.3.0, 4.4.0.

SOLUTION:

1- The easiest solution as mentioned in a lot of forums (if you are looking for a little bit instead of posting the same problem each time) is to downgrade the openCV version to version 3.4.2.17 (if you need SIFT and SURF work just with pip install), because the problems start from version 3.4.3.

2- If you need a particular version knowing that it is a problem with SIFT or SURF, you can correct it, by installing OpenCV with enable opencv-contrib and NONFREE algorithms from source. here is a tutorial to follow:Tutorial

For compilation OpenCV With enable opencv-contrib and NONFREE algorithms you need this:

cmake -D CMAKE_BUILD_TYPE = RELEASE \ -D CMAKE_INSTALL_PREFIX = /usr/local \ -D INSTALL_PYTHON_EXAMPLES = ON \ -D INSTALL_C_EXAMPLES = OFF \ -D OPENCV_ENABLE_NONFREE = ON \ -D OPENCV_EXTRA_MODULES_PATH=(Path_to_opencv-contrib)/opencv_contrib/modules \-D PYTHON_EXECUTABLE=~/.virtualenvs/(Python_environement)/bin/python \-D BUILD_EXAMPLES=ON ..

Tested with opencv 3.4.9 under python 3.6.9 (Works fine for SIFT and SURF)

All existing releases of opencv 3 and 4 are here Releases

All versions of openCV3 >= 3.4.11 include the free version of SIFT

All versions of openCV4 >= 4.4.0 include the free version of SIFT

【转载】关于Opencv里SIFT和SURF是有专利算法的说明相关推荐

  1. Opencv实现Sift、Surf、ORB特征提取与匹配

    在opencv3中,这三个算子都转移到一个名为xfeature2d的第三方库中,而在opencv2中这三个算子在nonfree库中. 关于在vs下配置opencv可参考我转载的另外一篇文章.注意版本号 ...

  2. SIFT、SURF等关键点特征提取算法代码

    文章目录 1.关键点特征提取算法 2.SIFT代码(python+opencv) 2.SURF代码(python+opencv) 3.SIFT和SURF的比较 1.关键点特征提取算法 特征提取是提取出 ...

  3. SLAM前端 ---------特征提取之ORB(ORB与SIFT与SURF)

    ORB 论文翻译: 一种特征匹配替代方法:对比SIFT或SURF 1.ORB特征简介  ORB是Oriented FAST and Rotated BRIEF(oFAST and rBRIEF)的简称 ...

  4. 在OpenCV里实现扑克牌识别2

    要对扑克牌的识别,前面只是对每一个牌做了标记,这样提供了一个识别的基础,也就是识别的知识库.要把新拍摄进来的牌进行识别,比如像下图: 在这里看到一下子拍摄到四张牌,目标是把这四张牌识别出来,那么需要怎 ...

  5. 图像特征检测描述(一):SIFT、SURF、ORB、HOG、LBP特征的原理概述及OpenCV代码实现

    图像处理开发需求.图像处理接私活挣零花钱,请加微信/QQ 2487872782 图像处理开发资料.图像处理技术交流请加QQ群,群号 271891601 什么叫特征检测?就是检测图像中目标的特征呗,所谓 ...

  6. OpenCV3如何使用SIFT和SURF Where did SIFT and SURF go in OpenCV 3?

    If you've had a chance to play around with OpenCV 3 (and do a lot of work with keypoint If you've ha ...

  7. Python+OpenCV:ORB: An efficient alternative to SIFT or SURF

    Python+OpenCV:ORB: An efficient alternative to SIFT or SURF 理论 As an OpenCV enthusiast, the most imp ...

  8. OpenCV 尺度不变特征检测:SIFT、SURF、BRISK、ORB

    这个学期在上数字图像处理这门课.这门课没有考试,只有大作业,要求使用labwindows和NI Vision进行开发.我选的题目是全景图像的合成(图像拼接),其中要使用到一些特征点检测和匹配的算法.本 ...

  9. Opencv Sift和Surf特征实现图像无缝拼接生成全景图像

    Sift和Surf算法实现两幅图像拼接的过程是一样的,主要分为4大部分: 1. 特征点提取和描述 2. 特征点配对,找到两幅图像中匹配点的位置 3. 通过配对点,生成变换矩阵,并对图像1应用变换矩阵生 ...

最新文章

  1. 王爽汇编第九章学习笔记
  2. 在两个有序的数组中找第N个数,二分查找 O(lgm+lgn)级
  3. linux交叉编译时报错:file not recognized: File format not recognized
  4. 当心XML文件中的非法字符
  5. python可以体现数学中映射概念的是_【课时27+集合+在我的世界里+你就是唯一】 - #1...
  6. 转!!URL和URI区别
  7. 2020 cr节目源_直播源2020-10-10
  8. ScreenToGif2.19.3中文版GIF录制工具
  9. 微信小程序父子组件传值
  10. 基于经纬度矩阵计算距离矩阵
  11. Julia教程:Julia语言入门
  12. 单纯p2p理财模式难以发展壮大和长久存在!
  13. Java String类源码阅读笔记
  14. linux命令行怎么结束进程,linux结束进程命令
  15. 求生之路2服务器ip直连,正版求生之路2好友直连显示该会话已不可用,无法联机...
  16. 女明星被美瞳耽误了演技!挑隐形眼镜把好这4关!
  17. 银行本、异地,本、跨行存取款手续费大全
  18. 【速通指南】《信息资源管理》信息系统资源管理,第3章
  19. 桥牌坐庄训练bm2000 level3闯关记录——A6
  20. 机械专业就业与计算机专业待遇,机械类专业如何去选择,就业前景究竟是怎么样的...

热门文章

  1. Markdown语法中输入数学公式(MathJax)及特殊符号
  2. 全网首次解密600多个AI工具汇总(三)
  3. SNMP协议端口区别
  4. vaadin之UI组件
  5. 唤镜引擎简单塔防事件截图
  6. 对在线教育的理解与思考
  7. python高级(如何为元组中的每个元素命名,提高程序可读性)
  8. 名帖303 梁诗正 行书《题跋富春山居图卷》
  9. npm使用淘宝镜像加速以及使用cnpm
  10. GRASP模式学习心得