Compiling Darknet with opencv-python - opencv

I installed Darknet with CUDA support. I ran
./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights data/dog.jpg
I want it to run with opencv support. I had already installed opencv.
I compiled darknet with remake/make after making OPENCV=1 in Makefile, but still it is not detecting the installed opencv.
How can I make it to detect the already installed opencv?
I have installed opencv with this command pip install opencv-python --user before installing darknet.

You need to install the c++ libraries not just the python wrapper. You can do it from the sources: https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html.

In order to compile Darknet you will need OpenCV works with C/C++ code, not python. To check whether you have installed OpenCV correctly and can be used in C program, run this command :
pkg-config --modversion opencv
If it doesn't show anything or shows wrong version, try to reinstall OpenCV OR it is possible that your machine doesn't locate opencv version correctly.
So add command to your ~/.bashrc for example :
vim ~/.bashrc
export PKG_CONFIG_PATH=/home/user/installation/OpenCV-3.4.0/lib/pkgconfig
source ~/.bashrc
Notes : Change the path according to your opencv installation directory that contains opencv.pc

If you're following this repo https://github.com/AlexeyAB/darknet for Windows/Linux you need to download openCV (both OpenCV 2.x.x and OpenCV <= 3.4.0 (3.4.1 and higher isn't supported)) and put in this path for
Windows: ( C:\opencv_3.0\opencv\build\include & C:\opencv_3.0\opencv\build\x64\vc14\lib)
More instructions in the repo. If you're on Windows/Linux and still trying to figure things out you may check a video I made on that topic https://youtu.be/-HtiYHpqnBs

Related

How to fix "fatal error: opencv2/core.hpp: No such file or directory" to build Darknet properly with conda virtual environment

I am using conda virtual environment on Ubuntu 20.04 and I got this error while using "make" in Darknet folder even if my virtual environment(conda) has Opencv installed.
Here is the screenshot of the error:
Here is that cv2 is working and its version(4.5.5):
Here is the environment variables for CUDA and Opencv I used (in .bashrc):
Thanks in advance for your any help!
It seems that the problem is originated from not building OpenCV as Darknet needs.
As #ChristophRackwitz implied, showing python version worked is not enough to build darknet with OpenCV capability. To be able to build darknet with OpenCV ON, OpenCV should be built with C++ functionalities as some of instructions might be followed:
Instruction 1
Instruction 2
and so on.

What is the proper way of adding a local dependency (openCV) in Meson?

I am using OpenCV in one of my projects. Until now, I was using version 3 under Ubuntu 18.04, so in my meson.build I had:
... dependencies: [dependency('opencv')])
Now, I've compiled OpenCV 4 from source and installed to the default dir, /usr/local/, and changed my meson.build to:
... dependencies: [dependency('opencv4')])
Resulting in a not found error (despite this works with Ubuntu 20.04 and the package from the official repos, which is version 4.2). How should I specify the library's location so Meson can find it?
I've seen find_library, but that's deprecated according the docs.
The dependency function is using pkg-config or cmake if pkg-config fails, to find external dependency (installed library).
When you install OpenCV4, please check if there is pkg-config for opencv4. Here is my command:
pkg-config --list-all | grep "opencv4"
and output:
opencv4 OpenCV - Open Source Computer Vision Library
Also, check PKG_CONFIG_PATH environment variable. pkg-config will use that path to search for .pc files.
Edit:
be sure to use -D OPENCV_GENERATE_PKGCONFIG=YES when building opencv with cmake.

How to add custom Opencv library into pycharm

Basically I am developing a project using OpenVino and OpenCV,to do so I cannot use the normal and easy way of using pip to install opencv library but instead Intel provided their own optimized version OpenCV.
I cannot find a place to add the path for the custom OpenCV in pycharm.
If anybody can enlighten me,please do so.
Thank you in advance.
please try the below steps.
Install Python 2.7.10
Install Pycharm(If not installed previously)
Download the OpenCV executable.
Install OpenCV
Add OpenCV in the system path(%OPENCV_DIR% = /path/of/opencv/directory)
Goto C:\opencv\build\python\2.7\x86 folder and copy cv2.pyd file.
Goto C:\Python27\DLLs directory and paste the cv2.pyd file.
Goto C:\Python27\Lib\site-packages directory and paste the cv2.pyd file.
Goto PyCharm IDE and goto DefaultSettings>PythonInterpreter.
Select the Python which you have installed on Step1.
Install the packages numpy,matplotlib and pip in pycharm.
Restart your PyCharm.
PyCharm now has OpenCV library installed and working.
Hope this will solve your issue

sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed

So I am trying to use:
sift = cv2.xfeatures2d.SIFT_create()
and it is coming up with this error:
cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: 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'
I am using Python 3.5.0 and opencv(3.4.3) and I am just using idle. This occured after I tried to install TensorFlow and I have tried looking around and have installed opencv-contrib-python but I am still getting the same error. Thank you in advance and I apologise if I have not included enough info
I had the same problem. It seems that SIRF and SURF are no longer available in opencv > 3.4.2.16. I chose an older opencv-python and opencv-contrib-python versions and solved this problem. Here is the history version about opencv-python, and I use the following code :
pip install opencv-python==3.4.2.16
pip install opencv-contrib-python==3.4.2.16
Edit
For Anaconda User just this instead of pip
conda install -c menpo opencv
this will install cv2 3.4.1 and everything you need to run SIFT
Since SIFT patent expired, SIFT has been moved to the main repo.
To use SIFT in Opencv, You should use cv2.SIFT_create() instead of cv2.xfeatures2d.SIFT_create() now. (xfeatures2d only exists in the contrib package, but sift is part of the main package now.)
Below link will be helpful.
https://github.com/opencv/opencv/issues/16736
Edit: The opencv-contrib-python-nonfree was removed from pypi.
On Linux/ MacOS, I've found a better solution! To access nonfree detectors use:
pip install opencv-contrib-python-nonfree
It may be due to a mismatch of opencv version and opencv-contrib version.
If you installed opencv from the source using CMake, and the source version is different from the version of opencv-contrib-python, uninstall the current opencv-contrib-python and do pip install opencv-contrib-python==<version of the source>.X or an another compatible version.
One version setup that I have running is opencv source (3.2), opencv-python (3.4.0.14) and opencv-contrib-python (3.4.2.17)

opencv is not working with tensorflow virtualenv

i have installed tensorflow(virtualenv) on ubuntu(14.04) and installed opencv. opencv is working with python tensorflow(virtualenv) is working with python but unable to use tensorflow(virtualenv) and opencv together with python.
openCV is also need to be there in virtualenv. You can create symbolic link of cv2.so inside virtualenv, if you have installed openCV globally.
For more details regarding creating symbolic link of openCV inside virtualenv,you can look into step 11 of following blog:
http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/

Resources