-
Notifications
You must be signed in to change notification settings - Fork 853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include non-free algorithms #126
Comments
Those algorithms have been included erroneously before because they were not properly protected in the upstream by the OPENCV_ENABLE_NONFREE flag. I am not a lawyer. I'm not sure if I can redistribute those algorithms. Edit: See: opencv/opencv_contrib#1668 |
I understand your concern. The problem is that SIFT is the gold standard algorithm, it is highly used in research and other non-commercial applications. The SIFT implementation is anyway available from the C++ repository of opencv, and I am sure that if the patent owner wanted to ban SIFT from opencv they would have done it before. Removing SIFT from this repo is first probably breaking a lot of scripts that were relying on the previous version, and prevent people to test this solution for their problem. What about adding a warning when a SIFT detector/descriptor object is created ? Like for deprecated stuff but here mentioning the patent. |
I know that both SIFT and SURF are used widely. I agree that the programmer or a company is responsible for checking that the patents and licenses of the software are respected. However, "probably does not matter" is not enough. These pre-built packages are freely available around the world so everything must be considered even if it concerns only USA. There have been other interesting discussions about this very same matter: https://answers.ros.org/question/34557/opencv-patent/ Snippet from https://github.com/opencv/opencv_contrib/blob/master/modules/xfeatures2d/src/sift.cpp:
I didn't remove anything from this repo. OpenCV developers moved SIFT and SURF behind the non-free build flag in the most recent release which is the way they should have been always but, for some reason, weren't. If I turn the non-free build flag on, it's not only SIFT and SURF that get included in the wheels. There are other non-free modules in OpenCV. I can't add any warnings in this repository to the OpenCV code (without very cumbersome patches) since this repository just pulls a certain vanilla OpenCV version from the upstream and builds it. If you need the non-free modules you can build the Python bindings yourself and flip the non-free flag on. After all, that's the official way. These packages are unofficial and not endorsed by OpenCV. Best solution would be probably to create proper support for sdist for these packages and allow users to force the rebuild of the packages themselves. This requires of course compilers and other tools to be installed on the target system and the installation would take about ~10-15 minutes. |
I'm afraid it does matter. Or to be more precise, it's not in the "definitely doesn't matter" category, or even in the "probably does not matter" category. More like in the "might well matter" category! Here's some background on the interesting question of why distributing source code might be in the "probably does not matter" category, but distributing built binaries isn't: (which in turn answers why the code is still in the upstream OpenCV repository, just guarded with a compiler flag)
More like 2 hours on a Pi :) Still, as the person who builds the wheels for opencv-python on the piwheels platform (with the relevant bits from skvark's repo here), I'm entirely in agreement with skvark here and will be following upstream's lead. IANAL (too), and while it's interesting (to some?) to read patent-related SE posts and the odd legal paper I wouldn't trust my conclusions to defend me from a pack of rabid patent attorneys. |
Is it possible to install opencv-python to include these non-free algorithms with |
Old versions have SIFT and SURF included due to the reasons explained above. The latest release does not include them. Any upcoming release will not include them (unless OpenCV developers move the algorithm to the free side of OpenCV after patent expiration). It's better not to rely on these packages if you wish to use non-free algorithms. |
@Jindil http://answers.opencv.org/question/18259/is-surf-algorithm-used-in-opencv-patented/ <- it says there are better, free alternatives. Judging by https://www.quora.com/Computer-Vision-They-dont-use-SIFT-at-Microsoft-they-use-MOPS-Meaning, they seem to only differ by some reference dataset or something. http://answers.opencv.org/question/73877/opencv-free-for-commercial-use/ <- this says they are free for non-commercial use only, so if they are included, @ubaierbhat you can tweak CMake command line ( |
I added a note about this to the README. Closing because this is not going to happen. |
Even after the expiration? :) https://patents.google.com/patent/US6711293 |
If the patent expires and the algorithm is moved to free side in OpenCV it will be included in the builds automatically. We will see next year. |
I got the same problem of the nonfree error when using the cv2.kinfu function: sudo pip2 install opencv-python==4.1.2.30 then in python cv2.kinfu.KinFu_create(params)error Traceback (most recent call last) error: OpenCV(4.1.2) /io/opencv_contrib/modules/rgbd/src/kinfu.cpp:314: 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' The errors also happens in C++ code even after I recompiled the opencv with the -D OPENCV_ENABLE_NONFREE=1 Any solution? |
I got the same problem when using cv2.detectAndCompute pip install opencv-python==4.1.2.30 AttributeError Traceback (most recent call last) AttributeError: module 'cv2.cv2' has no attribute 'detectAndCompute' Can someone help? |
@nairshobhit94 : SIFT is not available in open CV versions > 3.4.2 and you don’t need opencv-python to use SIFT. You only need the correct version of opencv-contrib-python. So try
and
|
@skvark Can you show How to changed setup.py for build with SIFT/SURF ? |
This sould do it:
|
@skvark I have build opencv 4.2 with nonFree enabled on Windows 64x, it is working fine. |
@skvark please tell in which directory do we have to run |
If you want to enable non-free modules (or other modules which are not enabled in the pre-built wheels) and package this project you must compile OpenCV from sources. To do that with the toolchain provided by this repository: git clone --recursive https://github.com/skvark/opencv-python.git
cd opencv-python
export CMAKE_ARGS="-DOPENCV_ENABLE_NONFREE=ON"
python setup.py bdist_wheel |
@skvark The patent for SIFT expired 10 days ago. Are you going to include it now ? |
Please open an issue to the OpenCV repository. I cannot enable it in this repository, the C++ macro which prevents it from being included in the builds is in there. |
See: opencv/opencv#16736 |
Completely new to this so excuse the ignorance. I cloned your repository. I downloaded OpenCV's latest version from theirs and pasted it into the opencv folder in your repo's folder. I set the environment variable using
I then ran the python command mentioned by you above. It gives the following error:
|
It seems that you do not have Git installed / Python does not find the |
Remember to add ENABLE_CONTRIB=1. And the latest 4.3.0 opencv-contrib includes SIFT without OPENCV_ENABLE_NONFREE flag. |
Here's how I got it working on macOS Catalina (10.15.4).
A test script:
On a mac, SIFT is kinda slow. But if you compile OpenCV with GPU computing support on a Linux box, it's ridiculously fast! Here's how you compile on Ubuntu with GPU support.
|
@rooseveltrp
|
@lober-io ensure you have cmake installed. I'll also recommend upgrading setuptools if not up-to date. You can get that done using |
Here's how I got It working on for Python 3.7.5 on Windows 10 Version 1903 (Warning: hacky):
Finally: |
Really helpful comments, |
I was able to get a successful build with the above solutions when i do not set the enabled contrib flag , but when i set the env variable to ENABLE_CONTRIB=1 then i get the below error. Any thoughts on what I could be missing? Error: |
@shivasj Try |
Thank you @konradmb removing the previous build folder fixed the issue |
Turns out CMAKE_ARGS="-DOPENCV_ENABLE_NONFREE=ON" pip install --no-binary=opencv-contrib-python opencv-contrib-python There's no need to compile anything separately. |
Since SURF is now off patent, can we include that back into the pypi builds of OpenCV? |
@awcchungster It's up to the upstream to move it into the free section of the build logic -- then any of OpenCV-Python builds will include it automatically. |
As @native-api wrote and as it has been explained in this issue also previously, all non-free modules are protected by a C++ macro in the upstream repositories where the actual OpenCV C++ code is located. This repository will never turn on the OPENCV_ENABLE_NONFREE flag by default because that will cause all patented / non-free modules to be included in the builds. For example, for SURF the macro is here: The correct place for these requests is the OpenCV contrib repository. |
We have identified an issue some of you are encountering when using the Surf algorithm, which results in the following error message:
This error occurs because the Surf algorithm is patented and requires specific configuration to be enabled. To resolve this issue and make it possible to use the Surf algorithm in the Google Colab environment, please refer to the following GitHub repository and the accompanying Google Colab notebook: https://github.com/MJAHMADEE/SURF The repository provides a comprehensive solution to this problem, ensuring that the Surf algorithm can be used without encountering the aforementioned error. The Google Colab notebook within the repository contains detailed instructions and the necessary setup to get you started. We hope this helps you overcome the issue and continue your work seamlessly. |
Hello,
with the recent update, in Opencv 3.4.3, the non-free algorithms such as SIFT and SURF are no more available.
As the error messages say, the library should be recompiled with
-D OPENCV_ENABLE_NONFREE=1
.Would it be possible to reintroduce these algorithms in the pip package?
The text was updated successfully, but these errors were encountered: