I am trying to run a DNN model using OpenCV on NVIDIA GPUs. Cuda works fine.
I am trying to run models using OpenCL:
network.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
network.setPreferableTarget(cv::dnn::DNN_TARGET_OPENCL);
I got lower fps than the CPU. The task manager shows no increase in GPU usage.
Does the OpenCV dnn module utilize NVIDIA GPU if I select OpenCL?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
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
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'
but in version 3.4.2, it's work fine.
So how to make SIFT and SURF work in the different versions of OpenCV? Thank you.
A detailed explanation will be welcome
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, 4.5.x, 4.6.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
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, 4.5.x, 4.6.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
AutoKeras is built on Keras framework and Google automl is built on tensorflow. So on which framework does the h2o build ? or is it made from scratch ?
H2O's AutoML (first released in 2017) is built on the Open Source H2O distributed machine learning stack. It's built on Java but it has Python and R bindings, so you can use those languages.
If I want to use my computer's GPU with OpenCV, is it necessary that I build OpenCV from source with CUDA enabled? Or can I install OpenCV with CUDA support via apt-get? I noticed the following 2 packages in apt-get:
libopencv-gpu-dev - development files for libopencv-gpu2.4v5
libopencv-gpu2.4v5 - computer vision GPU library
But I am not sure if these will work with OpenCV3 or if they are only compatible with OpenCV2. I know that the gpu module in Opencv2 was split up into multiple CUDA modules in OpenCV3.
Yes it is necessary that you build opencv from the source with CUDA option enabled. The apt-get packages won't work with OpenCV3 and above versions. I suggest you install the CUDA Toolkit first and then attempt installation of OpenCV or the GPU functions won't work.
I builded OpenCV 3.4 with CUDA, Intel TBB, Intel MKL in VS 2015 like this
When I run traincascade for classifier training, 100% of CPU is used, but the GPU is not used 0%.
Does the OpenCV-traincascade use the functions of the library CUDA for calculations on the GPU?
No
https://devtalk.nvidia.com/default/topic/951477/jetson-tk1/are-tools-like-opencv_traincascade-gpu-accelerated-in-opencv4tegra-/
To train cascade is meant to be used as an offline tool to create a cascade detector, you should try using a powerful desktop system for training, and then use OpenCV4Tegra on Jetson to run the trained classifier on the device.
There is a CUDA accelerated version of the cascade training tool available in the Ubuntu Desktop x64 version of the OpenCV4Tegra package, which can be downloaded here:
http://developer.nvidia.com/embedded/dlc/l4t-24-1-opencv4tegra-ubuntu
Which sums it up more eloquantly than I could.
Also No - answered here
In Summary
The opencv_traincascade functionality is not developed using GPU code, for reasons I do not know. This tool however is meant to be run offline, and then the results from this training used in your actual detection run-time code which can be GPU optimised.