筛检&冲浪:设置 OPENCV_ENABLE_NONFREE CMake ==>解决方案 OpenCV 3 &OpenCV 4 [英] SIFT & SURF : Set OPENCV_ENABLE_NONFREE CMake ==> Solution OpenCV 3 & OpenCV 4

查看:327
本文介绍了筛检&冲浪:设置 OPENCV_ENABLE_NONFREE CMake ==>解决方案 OpenCV 3 &OpenCV 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在某些版本的 OpenCV 3 和 openCV 4(安装 opencv-contrib-python 之后)使用 SIFT 和 SURF 函数:

I try to use the SIFT and SURF function with some of the versions of OpenCV 3 and openCV 4 (after having installed opencv-contrib-python) with:

pip install opencv-contrib-python

我尝试了 3.4.3 和 3.4.9 和 4.1.0 版本,但有同样的问题:

i try version 3.4.3 and 3.4.9 and 4.1.0, but have same probleme:

sift = cv2.xfeatures2d.SIFT_create()
surf = cv2.xfeatures2d.SURF_create()
==> 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 'create'

但在 3.4.2 版本中,它工作正常.

but in version 3.4.2, it's work fine.

那么如何让 SIFT 和 SURF 在不同版本的 OpenCV 中工作呢?谢谢.

So how to make SIFT and SURF work in the different versions of OpenCV? Thank you.

欢迎详细解释

推荐答案

我看到相同的主题已经两年了,关于 SIFTSURF> 这会给某些人带来问题.总是有关于这两个的帖子.

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.

首先,你需要了解一些东西:OpenCV 是一个开源库,它实现了研究人员设计的算法,其中一些算法可以免费用于个人或商业用途,另一些可以免费用于个人用途.

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.

首先根据 OpenCV 的版本进行一个小说明:opencv2 ->opencv3 ->opencv4 ->opencv 的新版本

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

  • 我们不打算讨论 opencv 2(我想现在几乎没有人使用它).在此版本中,您唯一需要记住的是 SIFTSURF 工作正常.
  • OpenCV3 发布以来,SIFTSURF 实现已从 OpenCV 的默认安装中删除3,与 OpenCV 4 相同.
  • 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.

删除SIFTSURF 的原因是因为OpenCV 称之为非自由" 算法.SIFTSURF 是(夏季)专有算法和专利算法,这意味着您必须在技术上获得在商业算法中使用它们的许可(但是,它们对学术免费和研究目的).

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).

出于这个原因,OpenCV 决定将获得专利的算法(带有实验性实现)转移到名为 opencv_contrib" 的包中.这意味着访问 SIFT 和 SURF.

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.

  • C++ 中的 OpenCV 案例:您必须从源代码启用 opencv-contrib 支持编译和安装 OpenCV.(我们稍后会看到)

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

python 中的 OpenCV 案例:您需要通过 pip 安装 opencv-contrib-python 包,如下所示:

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

pip install opencv-contrib-python

但是,在 OpenCV 3 的某些版本中(您在 Python 中遇到问题的那个版本),SIFTSURF> 算法不想工作,你会得到这个错误:"module 'cv2.cv2' has no attribute 'xfeatures2d' ".

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' ".

我可以给你一个解释(这是我自己的观点),但在此之前你应该知道 OpenCV python 包是通过编译OpenCV 源.Pythons 包是 Wheel 类型的文件,所以扩展名为.whl".

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".

所以当你做** pip install opencv-python **时,你实际上会参考这个https://pypi.org/project/opencv-python/#files 它将选择与您的配置(操作系统以及python版本)相对应的wheel文件,对于opencv-contrib-python也是如此链接如下 https://pypi.org/project/opencv-contrib-python/#文件.

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.

那么为什么 SIFTSURF 不能在所有版本的 OpenCV 中工作?

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

假设 1:忘记在编译源代码和构建 opencv-contrib-python 包时激活额外的模块和开发人员提供的非自由算法.但是由于这个问题不是在一个版本中出现,而是在十个版本中出现,这就产生了第二个假设.

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.

假设 2:这是故意的,但为什么呢?

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.

版本历史和操作:来自SIFTSURF.

Version history and operation: from SIFT and SURF.

1- 对于 SIFT(测试):

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- 对于 SURF(假设(不是全部测试)):

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.

解决方案:

1- 在许多论坛中提到的最简单的解决方案(如果您正在寻找一点点而不是每次都发布相同的问题)是将 openCV 版本降级版本>3.4.2.17(如果您需要 SIFT 和 SURF 工作只需 pip install),因为问题从 3.4.3 版本开始.

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- 如果您需要一个特定版本,知道它是 SIFT 或 SURF 的问题,您可以通过安装 OpenCV 来纠正它,并启用 opencv-contrib 和来自源代码的非自由算法.这是一个教程:教程

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

对于编译 OpenCV,您需要启用 opencv-contrib 和 NONFREE 算法:

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 ..

在 python 3.6.9 下用 opencv 3.4.9 测试(适用于 SIFT 和 SURF)

opencv 3 和 4 的所有现有版本都在这里版本

All existing releases of opencv 3 and 4 are here Releases

openCV3 >= 3.4.11 的所有版本都包含 SIFT 的免费版本

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

openCV4 >= 4.4.0 的所有版本都包含 SIFT 的免费版本

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

这篇关于筛检&冲浪:设置 OPENCV_ENABLE_NONFREE CMake ==>解决方案 OpenCV 3 &OpenCV 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆