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.
Related
I am trying to install ViZDoom on Ubuntu system. I am following the steps given the following link https://github.com/mwydmuch/ViZDoom/blob/master/doc/Building.md.
As shown below:
sudo apt-get install build-essential zlib1g-dev libsdl2-dev libjpeg-dev \
nasm tar libbz2-dev libgtk2.0-dev cmake git libfluidsynth-dev libgme-dev \
libopenal-dev timidity libwildmidi-dev unzip
sudo apt-get install libboost-all-dev
sudo apt-get install python3-dev python3-pip
pip3 install numpy
sudo apt-get install julia
julia
julia> using Pkg
julia> Pkg.add("CxxWrap")
pip install git+https://github.com/mwydmuch/ViZDoom.git
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON=ON -DBUILD_JAVA=ON -DBUILD_LUA=ON -DBUILD_JULIA=ON
make
However, when I do this
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON3=ON -DBUILD_JAVA=ON -DBUILD_LUA=ON -DBUILD_JULIA=ON
I am getting the following error:
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- filesystem
-- thread
-- system
-- date_time
-- chrono
-- regex
-- iostreams
-- atomic
CMake Deprecation Warning at cmake_modules/CreateLaunchers.cmake:48 (cmake_policy):
The OLD behavior for policy CMP0026 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
src/vizdoom/CMakeLists.txt:13 (include)
-- Could NOT find GME (missing: GME_INCLUDE_DIR)
-- Using system zlib
-- Using system jpeg library
-- Using system bzip2 library
-- Using internal gme library
-- /usr/include
-- /usr/include
-- /home/tie/ViZDoom/src/vizdoom/lzma/C
-- Could not find FMOD include files
-- Could NOT find SndFile (missing: SNDFILE_LIBRARY SNDFILE_INCLUDE_DIR)
-- Could NOT find MPG123 (missing: MPG123_LIBRARIES MPG123_INCLUDE_DIR)
-- Selected assembler: /usr/bin/as
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- thread
-- system
-- date_time
-- chrono
-- atomic
-- Fluid synth libs: /usr/lib/x86_64-linux-gnu/libfluidsynth.so
-- pybind11 v2.8.1
CMake Error at src/lib_julia/CMakeLists.txt:1 (find_package):
By not providing "FindJlCxx.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "JlCxx", but
CMake did not find one.
Could not find a package configuration file provided by "JlCxx" with any of
the following names:
JlCxxConfig.cmake
jlcxx-config.cmake
Add the installation prefix of "JlCxx" to CMAKE_PREFIX_PATH or set
"JlCxx_DIR" to a directory containing one of the above files. If "JlCxx"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/tie/ViZDoom/build/CMakeFiles/CMakeOutput.log".
See also "/home/tie/ViZDoom/build/CMakeFiles/CMakeError.log".
I also install Julia successfully:
I think that there is CMake error or some version mismatch error but being new to it, I am unable to resolve it.
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.
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
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
I am trying to install OpenCV 3.0 for Python on Ubuntu 14.04 but after many installations (and StackOverflow pages read) it still does not work.
In Python (Python 2.7) when importing typing import cv2 I obtain this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
I have seen that this error may be due to the file /etc/ld.so.conf.d/opencv.conf and therefore I wrote inside it the line /usr/local/opencv/ but it did not help (actually there is no folder opencvin /usr/local/ on my computer...
For the installation I followed the instructions on this website: http://milq.github.io/install-opencv-ubuntu-debian/
I suspect errors occurred during the cmake phase because I got failures like -- Performing Test HAVE_CXX_WMISSING_PROTOTYPES - Failed. I don't know what that means and if it is important for the installation...
I have other errors like
-- checking for module 'gstreamer-base-1.0'
-- package 'gstreamer-base-1.0' not found
During the make phase I obtained this error
[ 31%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/qrc_window_QT.cpp.o
In file included from /home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:9:0:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp: In function ‘int qInitResources_window_QT()’:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:1749:25: warning: no previous declaration for ‘int qInitResources_window_QT()’ [-Wmissing-declarations]
int QT_MANGLE_NAMESPACE(qInitResources_window_QT)()
^
/usr/include/qt5/QtCore/qglobal.h:100:36: note: in definition of macro ‘QT_MANGLE_NAMESPACE’
# define QT_MANGLE_NAMESPACE(name) name
^
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp: In function ‘int qCleanupResources_window_QT()’:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:1758:25: warning: no previous declaration for ‘int qCleanupResources_window_QT()’ [-Wmissing-declarations]
int QT_MANGLE_NAMESPACE(qCleanupResources_window_QT)()
^
/usr/include/qt5/QtCore/qglobal.h:100:36: note: in definition of macro ‘QT_MANGLE_NAMESPACE’
# define QT_MANGLE_NAMESPACE(name) name
^
[ 31%] Generating opencl_kernels_superres.cpp, opencl_kernels_superres.hpp
Do you know what is wrong?
I finally managed to solve my problems. Since this may interested other people, here how I proceed.
I removed entirely opencv from my computer:
sudo make unistall in the repository where I wrote sudo make install
sudo find / -name "*opencv*" -exec rm -i {} \; to remove all files containing "opencv"
sudo find / -name "*cv2.so*" -exec rm -i {} \; to remove all files containing "cv2.so"
conda uninstall opencv (if needed)
I followed this link to install OpenCV2.4.10 for Python2.7: I did only the points 5,6,7 and 12 (the remaining ones are useless for what I wanted). I changed a bit the cmake command and I typed
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_OPENGL=ON -D WITH_VTK=ON -D WITH_GTK=ON ..
Now if when typing import cv2 in Python you get an error like "No module named cv2", edit your .bashrc file with the following command
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
You will have to reload the .bashrc file (source .bahsrc) to apply the change.
Finally I rebooted my computer. And it worked!
To conclude, I don't know why it did not work previously but it appears that with this version of OpenCV I did not encounter any problem!
Good luck!
You didn't install it correctly that's why you can't import it. Here is a guide on how to install it, (it is for an .older version but the commands are the same). OpenCV 3.0 Trouble with Installation