CMake not being able to find Python Library - python

I am following this tutorial to install OpenCV 3.0 and Python 2.7 but however, I am getting Cmake errors at step 8.
-- Could NOT find PythonLibs: Found unsuitable version "2.7.11", but required is exact version "2.7.13" (found
/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/bin)
-- Could NOT find PythonInterp: Found unsuitable version "2.7.13", but required is at least "3.4" (found
/Users/SabrinaZuraimi/.virtualenvs/cv/bin/python)
-- Could NOT find PythonInterp: Found unsuitable version "2.7.13", but required is at least "3.2" (found
/Users/SabrinaZuraimi/.virtualenvs/cv/bin/python)
There is 2 versions of Python(2.7.11 and 2.7.13) in the usr/local/Cellar/Python but I don't understand why there is an error saying that i can't find 2.7.13
The command that I typed into the terminal was
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON2_PACKAGES_PATH=~/.virtualenvs/cv/lib/python2.7/site-packages \
-D PYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/bin \
-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers \
-D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF\
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..
I am not very familiar with cmake, and I appreciate any help that I can get.

that tutorial is out-of-date. you can try this new tutorial

Related

Unable to install OpenCV Python on M1 Mac

I've been following this thread (https://trayansh.medium.com/setting-machine-learning-environment-on-m1-mac-apple-silicon-959836bf494d), successfully installed TensorFlow but while making the config file(Cmake Command) for openCV it is giving me an error:-
CMake Error at cmake/OpenCVModule.cmake:354 (message):
Duplicated modules LOCATIONS has been found
Call Stack (most recent call first):
cmake/OpenCVModule.cmake:371 (_assert_uniqueness)
modules/CMakeLists.txt:7 (ocv_glob_modules)
I've been trying to install it for two days now and no progress. :(
The CMake command I used was
cmake \
-DCMAKE_SYSTEM_PROCESSOR=arm64 \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DWITH_OPENJPEG=OFF \
-DWITH_IPP=OFF \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=/Users/yashdhingra/Documents/Python/opencompile/opencv-4.5.0/modules \
-D PYTHON3_EXECUTABLE=/opt/homebrew/Caskroom/miniforge/base/envs/MLenv/python3 \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_EXAMPLES=ON ..
I did change the path of the modules and the Virtual Env_python as instructed in the guide.
This CMake error (Duplicated modules LOCATIONS has been found) is because you point the extra modules path to the main opencv module you are trying to build from.
You need to set the extra modules path to opencv-contrib and not opencv.
OPENCV_EXTRA_MODULES_PATH=/Users/yashdhingra/Documents/Python/opencompile/opencv_contrib-4.5.0/modules
You have perhaps copied the extra modules into the main module directory, and then are using -D OPENCV_EXTRA_MODULES_PATH=/opt/OpenCV3.4/modules to locate this. But the module locator looks at ALL the modules that are in a directory; and then it also requires each module to be unique and seen only once. Since the cmake looks at all the modules in the main /module directory by default, and then looks at all the modules in the EXTRA_MODULES path again when you specify this cmake option, it gets confused, and thinks it is seeing the exact same modules twice, and then barfs.
Solution 1: Simply don't specify -D OPENCV_EXTRA_MODULES_PATH=/opt/OpenCV3.4/modules in your cmake instructions if you have included all extra modules into the default system module file by hand. It will only review this directory once, and will happily compile all of them.
Solution 2: Keep the extra modules in their own separate directory, and specify cmake option -D OPENCV_EXTRA_MODULES_PATH=/my_extra_modules_directory which is separate from the main /modules directory.

Building OpenCV for Python

I'm using this: http://docs.opencv.org/3.1.0/d7/d9f/tutorial_linux_install.html
to build opencv on ununtu 16LTS for Python 3.
On step 4 in Building OpenCV from Source Using CMake i'm stuck with typing in the right parameters. Could you, please check my variants, because i could only find folders and no files with suggested extensions. Also, shall i type a flag -D before each param?
-D PYTHON3_EXECUTABLE=$HOME/anaconda3/bin
-D PYTHON_INCLUDE_DIR=/usr/include/python3.5
-D PYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python3.5m
-D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.a
-D PYTHON3_NUMPY_INCLUDE_DIRS= I dont have anything similar like path in the tutorial, but i have a "numpy" folder in /usr/include/python3.5!
So what should i do?
Also, what shall i write in:
-D CMAKE_INSTALL_PREFIX
OPENCV_EXTRA_MODULES_PATH (in this tutrial(previus step), o downloaded opencv-contrib. So should i type in: OPENCV_EXTRA_MODULES_PATH=/home/vladislav/opencv/opencv_contrib
BUILD_DOCS
BUILD_EXAMPLES
ERROR: When i run as it is told in the tutorial, i got mistakes like this: CMake Error: The source directory "/home/vladislav/opencv/build/PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so" does not exist.
That's an example of my working cmake params (Ubuntu 16.04, Latest OpenCV, Python 3.5), but you need to adjust the paths by your own.
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D PYTHON3_EXECUTABLE=/usr/bin/python3.5 \
-D PYTHON3_INCLUDE_DIR=/usr/include/python3.5 \
-D PYTHON3_LIBRARY=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5.so \
-D PYTHON3_NUMPY_INCLUDE_DIR=/usr/local/lib/python3.5/dist-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/usr/local/lib/python3.5/dist-packages \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
in my case opencv_contrib is in the same folder like opencv your cmake command starts from your build folder (mkdir build in opencv folder) so in my case I need to jump to dirs back and important: refer to the opencv_contrib/modules folder
Sometimes it's a little bit clearer to use the cmake-gui
sudo apt install cmake-gui

Requested modules not available: vtkRenderingOpenGL-cmake/OpenCVDetectVTK.cmake:6 (find_package)

I am basically trying to install OpenCV3 with Python3.5. I have successfully gone through all the steps in this tutorial for git checkout 3.1.0 of opencv. However when I enter this command:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON3_PACKAGES_PATH=~/.virtualenvs/cv3/lib/python3.5/site-packages \
-D PYTHON3_LIBRARY=/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib \
-D PYTHON3_INCLUDE_DIR=/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/include/python3.5m/ \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..
I get this error:
...etc...
-- Checking for module 'gstreamer-base-1.0'
-- No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-video-1.0'
-- No package 'gstreamer-video-1.0' found
-- Checking for module 'gstreamer-app-1.0'
-- No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
-- No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
-- No package 'gstreamer-pbutils-1.0' found
-- Checking for module 'gstreamer-base-0.10'
-- No package 'gstreamer-base-0.10' found
-- Checking for module 'gstreamer-video-0.10'
-- No package 'gstreamer-video-0.10' found
-- Checking for module 'gstreamer-app-0.10'
-- No package 'gstreamer-app-0.10' found
-- Checking for module 'gstreamer-riff-0.10'
-- No package 'gstreamer-riff-0.10' found
-- Checking for module 'gstreamer-pbutils-0.10'
-- No package 'gstreamer-pbutils-0.10' found
-- Checking for module 'libdc1394-2'
-- No package 'libdc1394-2' found
-- Checking for module 'libdc1394'
-- No package 'libdc1394' found
-- Checking for module 'libv4l1'
-- No package 'libv4l1' found
-- Checking for module 'libv4l2'
-- No package 'libv4l2' found
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - not found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- Checking for module 'libavcodec'
-- Found libavcodec, version 57.48.101
-- Checking for module 'libavformat'
-- Found libavformat, version 57.41.100
-- Checking for module 'libavutil'
-- Found libavutil, version 55.28.100
-- Checking for module 'libswscale'
-- Found libswscale, version 4.1.100
-- Checking for module 'libavresample'
-- Found libavresample, version 3.0.0
-- Looking for libavformat/avformat.h
-- Looking for libavformat/avformat.h - found
-- Looking for ffmpeg/avformat.h
-- Looking for ffmpeg/avformat.h - not found
-- Checking for module 'libgphoto2'
-- No package 'libgphoto2' found
-- ICV: Removing previous unpacked package: /Users/mona/computer_vision/Face_Recognition/opencv/3rdparty/ippicv/unpack
-- ICV: Unpacking ippicv_macosx_20151201.tgz to /Users/mona/computer_vision/Face_Recognition/opencv/3rdparty/ippicv/unpack...
-- ICV: Package successfully downloaded
-- found IPP (ICV version): 9.0.1 [9.0.1]
-- at: /Users/mona/computer_vision/Face_Recognition/opencv/3rdparty/ippicv/unpack/ippicv_osx
-- Found Doxygen: /usr/local/bin/doxygen (found version "1.8.11")
-- To enable PlantUML support, set PLANTUML_JAR environment variable or pass -DPLANTUML_JAR=<filepath> option to cmake
-- Found PythonInterp: /usr/local/bin/python2.7 (found suitable version "2.7.12", minimum required is "2.7")
-- Could NOT find PythonLibs: Found unsuitable version "2.7.10", but required is exact version "2.7.12" (found /usr/lib/libpython2.7.dylib)
-- Found PythonInterp: /usr/local/bin/python3.4 (found suitable version "3.4.1", minimum required is "3.4")
-- Could NOT find PythonLibs: Found unsuitable version "3.5.2", but required is exact version "3.4.1" (found /usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib)
-- Found apache ant 1.9.7: /usr/local/bin/ant
-- Found JNI: /System/Library/Frameworks/JavaVM.framework
-- Could NOT find Matlab (missing: MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
CMake Error at /usr/local/Cellar/vtk/7.0.0_1/lib/cmake/vtk-7.0/vtkModuleAPI.cmake:120 (message):
Requested modules not available:
vtkRenderingOpenGL
Call Stack (most recent call first):
/usr/local/lib/cmake/vtk-7.0/VTKConfig.cmake:88 (vtk_module_config)
cmake/OpenCVDetectVTK.cmake:6 (find_package)
CMakeLists.txt:597 (include)
I have tried it with both ON and OFF for -D INSTALL_C_EXAMPLES=ON \ line still no success. Any feedback is really appreciated!
This is the log for flag set to OFF: http://pastebin.com/NF1bbpBC
It took me a good few hours to get this fixed. Here's what I did:
wget https://github.com/Itseez/opencv/archive/3.1.0.zip
wget https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
unzip 3.1.0.zip
unzip 3.1.0.zip.1
cd opencv-3.1.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_opencv_java=OFF \
-D WITH_IPP=OFF -D WITH_1394=OFF \
-D WITH_FFMPEG=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_opencv_python2=ON \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_video=OFF \
-D BUILD_opencv_videoio=OFF \
-D BUILD_opencv_videostab=OFF \
-D PYTHON_EXECUTABLE=$(which python) \
-D OPENCV_EXTRA_MODULES_PATH=/Users/mona/computer_vision/Face_Recognition/opencv_contrib-3.1.0/modules ..
In the last one make sure to have the absolute path not something like -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/opencv_contrib-3.1.0/modules ..
Also you would need vi cmake/OpenCVDetectVTK.cmake and change line 6 so it has vtkRenderingOpenGL2 instead of vtkRenderingOpenGL:
6 find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL2 vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
Verify if you are using VTK7.
If yes, then replace vtkRenderingOpenGL by vtkRenderingOpenGL2 in in line 6 of the file /cmake/OpenCVDetectVTK.cmake
The answer was posted here: https://github.com/opencv/opencv/issues/6180#issuecomment-204500571

'libavformat/avformat.h' file not found #include <libavformat/avformat.h>

When following the below tutorial:
brew install python3 pip3 install numpy brew install cmake git clone
--depth=1 https://github.com/Itseez/opencv.git cd opencv mkdir build cd build
note: in the next line, adjust paths to point to the correct python version cmake -DBUILD_opencv_python3=YES -DBUILD_opencv_python2=NO
-DINSTALL_PYTHON_EXAMPLES=YES -DPYTHON3_EXECUTABLE=/usr/local/bin/python3 -DPYTHON3_INCLUDE_DIR=/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/include/python3.5m/
-DPYTHON3_LIBRARY=/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib
-DPYTHON3_NUMPY_INCLUDE_DIRS=/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/include/
-DPYTHON3_PACKAGES_PATH=/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/
.. make -j8 make install python3 -c "import cv2;
print(cv2.version)"
I get this error for line 10 $ make -j8:
[ 39%] Built target opencv_shape
In file included from /Users/mona/Downloads/opencv/modules/videoio/src/cap_ffmpeg.cpp:47:
In file included from /Users/mona/Downloads/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:65:
/Users/mona/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:77:12: fatal error:
'libavformat/avformat.h' file not found
#include <libavformat/avformat.h>
^
1 error generated.
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
[ 40%] Linking CXX shared library ../../lib/libopencv_photo.dylib
[ 40%] Built target opencv_photo
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [all] Error 2
Monas-MacBook-Pro:build mona$
Why is this tutorial not passing on my OSX?
So this is how I solved the problem. Please let me know if you might have further questions:
~  c   master ⭑  Face_Recognition  ls  10:03:38 PM
3.1.0.zip 3.1.0.zip.1 opencv-3.1.0 opencv_contrib-3.1.0 papers
-------------------------------------------------------
In opencv-3.1.0/modules/viz/src/vtk/vtkCocoaInteractorFix.mm
#if VTK_MAJOR_VERSION >= 6 && VTK_MINOR_VERSION >=2
If we use VTK 7.0.0, although it is a newer version, the minor version is less than two, so the vtkCocoaInteractorFix.mm will handle this as older VTK versions and that causes the problem.
So to fix this we just need to add the version number 7 to the line.
#if VTK_MAJOR_VERSION >= 6 && VTK_MINOR_VERSION >=2 || VTK_MAJOR_VERSION >=7
---------------------------------------------------------------------------
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_opencv_java=OFF \
-D WITH_IPP=OFF -D WITH_1394=OFF \
-D WITH_FFMPEG=OFF\
-D BUILD_EXAMPLES=ON \
-D BUILD_TESTS=ON \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_DOCS=ON \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_video=ON \
-D BUILD_opencv_videoio=ON \
-D BUILD_opencv_videostab=ON \
-D PYTHON_EXECUTABLE=$(which python) \
-D OPENCV_EXTRA_MODULES_PATH=/Users/mona/computer_vision/Face_Recognition/opencv_contrib-3.1.0/modules ..
-------------------------------------------------------
make -j4
-------------------------------------------------------
sudo make install
Main points are -D WITH_FFMPEG=OFF and also giving the absolute path to opencv modules in -D OPENCV_EXTRA_MODULES_PATH=/Users/mona/computer_vision/Face_Recognition/opencv_contrib-3.1.0/modules ..

Building OpenCV cmake error: could NOT find PythonInterp

To build OpenCV, I ran this in the terminal in my ~/opencv/build directory :
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/path/to/opencv-3.0.0/build -D PYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin
-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers -D PYTHON2_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib-3.0.0/modules ../
But no matter what happens, I see this error in the Traceback : (Could NOT find PythonInterp:)
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numpy.distutils
-- Could NOT find PythonInterp: Found unsuitable version "2.7.11",
but required is at least "3.4" (found /usr/local/bin/python)
-- Could NOT find PythonInterp: Found unsuitable version "2.7.11",
but required is at least "3.2" (found /usr/local/bin/python)
Further down the line, this shows up
--
-- Python 2:
-- Interpreter: /usr/local/bin/python2.7 (ver 2.7.11)
--
-- Python 3:
-- Interpreter: NO
--
-- Python (for build): /usr/local/bin/python2.7
--
-- Java:
-- ant: NO
-- JNI:
The correct output should look somewhat like this:
correct Python Interp output
I have tried everything, but this keeps coming up!
In essence, I cannot build OpenCV properly, and hence cannot install it properly.
Your error talks about not being able to find numpy, so install numpy:
pip install numpy
In addition, change your include directory to make sure you are actually including it. For the PYTHON2_INCLUDE_DIR:
-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers
Then, run make clean, and delete your /build directory, and run your cmake, then make again.
You can specify the path to each version of Python manually.

Categories