In this post, we will provide step by step instructions for installing OpenCV 3 (C++ and Python) on Ubuntu.
You can also use our Installation Script for OpenCV-3 and OpenCV-4 for Ubuntu 16.04 as described in this article.
Step 1: Update packages
sudo apt-get update
sudo apt-get upgrade
Step 2: Install OS libraries
Remove any previous installations of x264</h3>
sudo apt-get remove x264 libx264-dev
We will Install dependencies now
sudo apt-get install build-essential checkinstall cmake pkg-config yasm
sudo apt-get install git gfortran
sudo apt-get install libjpeg8-dev libjasper-dev libpng12-dev
# If you are using Ubuntu 14.04
sudo apt-get install libtiff4-dev
# If you are using Ubuntu 16.04
sudo apt-get install libtiff5-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt-get install libxine2-dev libv4l-dev
sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install qt5-default libgtk2.0-dev libtbb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libvorbis-dev libxvidcore-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install x264 v4l-utils
# Optional dependencies
sudo apt-get install libprotobuf-dev protobuf-compiler
sudo apt-get install libgoogle-glog-dev libgflags-dev
sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
Step 3: Install Python libraries
sudo apt-get install python-dev python-pip python3-dev python3-pip
sudo -H pip2 install -U pip numpy
sudo -H pip3 install -U pip numpy
We will use Virtual Environment to install Python libraries. It is generally a good practice in order to separate your project environment and global environment.
# Install virtual environment
sudo pip2 install virtualenv virtualenvwrapper
sudo pip3 install virtualenv virtualenvwrapper
echo "# Virtual Environment Wrapper" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc
############ For Python 2 ############
# create virtual environment
mkvirtualenv facecourse-py2 -p python2
workon facecourse-py2
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
# quit virtual environment
deactivate
######################################
############ For Python 3 ############
# create virtual environment
mkvirtualenv facecourse-py3 -p python3
workon facecourse-py3
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
# quit virtual environment
deactivate
######################################
Step 4: Download OpenCV and OpenCV_contrib
We will download opencv and opencv_contrib packages from their GitHub repositories.
Step 4.1: Download opencv from Github
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 3.3.1
cd ..
Step 4.2: Download opencv_contrib from Github
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 3.3.1
cd ..
Step 5: Compile and install OpenCV with contrib modules
Step 5.1: Create a build directory
cd opencv
mkdir build
cd build
Step 5.2: Run CMake
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
Step 5.3: Compile and Install
# find out number of CPU cores in your machine
nproc
# substitute 4 by output of nproc
make -j4
sudo make install
sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
Step 5.4: Create symlink in virtual environment
Depending upon Python version you have, paths would be different. OpenCV’s Python binary (cv2.so) can be installed either in directory site-packages or dist-packages. Use the following command to find out the correct location on your machine.
find /usr/local/lib/ -type f -name "cv2*.so"
It should output paths similar to one of these (or two in case OpenCV was compiled for both Python2 and Python3):
############ For Python 2 ############
## binary installed in dist-packages
/usr/local/lib/python2.6/dist-packages/cv2.so
/usr/local/lib/python2.7/dist-packages/cv2.so
## binary installed in site-packages
/usr/local/lib/python2.6/site-packages/cv2.so
/usr/local/lib/python2.7/site-packages/cv2.so
############ For Python 3 ############
## binary installed in dist-packages
/usr/local/lib/python3.5/dist-packages/cv2.cpython-35m-x86_64-linux-gnu.so
/usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so
## binary installed in site-packages
/usr/local/lib/python3.5/site-packages/cv2.cpython-35m-x86_64-linux-gnu.so
/usr/local/lib/python3.6/site-packages/cv2.cpython-36m-x86_64-linux-gnu.so
Double check the exact path on your machine before running the following commands
############ For Python 2 ############
cd ~/.virtualenvs/facecourse-py2/lib/python2.7/site-packages
ln -s /usr/local/lib/python2.7/dist-packages/cv2.so cv2.so
############ For Python 3 ############
cd ~/.virtualenvs/facecourse-py3/lib/python3.6/site-packages
ln -s /usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so cv2.so
Step 6: Test OpenCV3
We will test a red eye remover application written in OpenCV to test our C++ and Python installations. Download RedEyeRemover.zip and extract it into a folder.
Step 6.1: Test C++ code
Move inside extracted folder, compile and run.
# compile
# There are backticks ( ` ) around pkg-config command not single quotes
g++ -std=c++11 removeRedEyes.cpp `pkg-config --libs --cflags opencv` -o removeRedEyes
# run
./removeRedEyes
Step 6.2: Test Python code
Activate Python virtual environment
############ For Python 2 ############
workon facecourse-py2
############ For Python 3 ############
workon facecourse-py3
Quick Check
# open ipython (run this command on terminal)
ipython
# import cv2 and print version (run following commands in ipython)
import cv2
print cv2.__version__
# If OpenCV3 is installed correctly,
# above command should give output 3.3.1
# Press CTRL+D to exit ipython
Run RedEyeRemover demo
python removeRedEyes.py
Now you can exit from Python virtual environment.
deactivate
Whenever you are going to run Python scripts which use OpenCV you should activate the virtual environment we created, using workon command.
Hi,
Thanks for posting this. I am working through it, not done yet. I have one question or correction. In the following excerpt should “.bash_profile” be changed to “.bashrc” After all you just put new lines into .bashrc and the script can’t assume .bash_profile exists. Better to source the file that exist than the file that does not.
*******Here is the context******
# Install virtual environment
sudo pip2 install virtualenv virtualenvwrapper
sudo pip3 install virtualenv virtualenvwrapper
echo “# Virtual Environment Wrapper” >> ~/.bashrc
echo “source /usr/local/bin/virtualenvwrapper.sh” >> ~/.bashrc
source ~/.bash_profile
It was a typo. Fixed it. Thank you!
Or keeping .bashrc (Step 3, before row #4):
touch ~/.bashrc
There’s still a wrong “source .bash_profile” on row 6
Hi,
Very good explanation !
If I want to use only C++ ? What the libs that I don´t need to install ?
My intention is minimize the required memory for a embedded application (like beaglebone, raspberry).
Thanks
If you only want to install for C++, you should follow steps: 2.1, 2.2, 4.1, 4.2, 5.1, 5.2, 5.3.
Hi I have QT 5 and QT creator 4 is already installed my system when I follow the steps above I have this error..
Could not find a package configuration file provided by “Qt5Core” with any
of the following names:
Qt5CoreConfig.cmake
qt5core-config.cmake
Add the installation prefix of “Qt5Core” to CMAKE_PREFIX_PATH or set
“Qt5Core_DIR” to a directory containing one of the above files. If
“Qt5Core” provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
CMakeLists.txt:556 (include)
CMake Warning at cmake/OpenCVFindLibsGUI.cmake:19 (find_package):
By not providing “FindQt5Gui.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “Qt5Gui”, but
CMake did not find one.
Could not find a package configuration file provided by “Qt5Gui” with any
of the following names:
Qt5GuiConfig.cmake
qt5gui-config.cmake
Add the installation prefix of “Qt5Gui” to CMAKE_PREFIX_PATH or set
“Qt5Gui_DIR” to a directory containing one of the above files. If “Qt5Gui”
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:556 (include)
and cmake says
— Configuring incomplete, errors occurred!
what can I do?
You may not have qtbase5-dev and its dependencies installed or they are not in path. If you installed qt5 using apt-get, run
sudo apt install qtbase5-dev
. It will install the missing packages.I am not seeing the cv.so in site-packages area.
find /usr/local/lib/ -type f -name “cv2*.so”
/usr/local/lib/python2.7/dist-packages/cv2.so
/usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so
The site-packages dir is empty.
What could be wrong?
I am installing this on Ubuntu 14.04
Python modules are installed either in site-packages or dist-packages. So you can use /usr/local/lib/python2.7/dist-packages/cv2.so and /usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so paths as well to create a symlink.
Hi,
I have been trying to install this on my ubuntu machine but no luck. facing dependancy issue. will you help me ?
error —
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libavcodec-dev : Depends: libavutil-dev (= 7:2.8.6-1ubuntu2) but it is not going to be installed
Depends: libswresample-dev (= 7:2.8.6-1ubuntu2) but it is not going to be installed
libavformat-dev : Depends: libavformat-ffmpeg56 (= 7:2.8.6-1ubuntu2) but 7:2.8.11-0ubuntu0.16.04.1 is to be installed
Depends: libavutil-dev (= 7:2.8.6-1ubuntu2) but it is not going to be installed
Depends: libswresample-dev (= 7:2.8.6-1ubuntu2) but it is not going to be installed
libswscale-dev : Depends: libavutil-dev (= 7:2.8.6-1ubuntu2) but it is not going to be installed
Depends: libswscale-ffmpeg3 (= 7:2.8.6-1ubuntu2) but 7:2.8.11-0ubuntu0.16.04.1 is to be installed
E: Unable to correct problems, you have held broken packages.
This is a tricky situation.
Run these commands
sudo apt-get autoremove
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get update
sudo apt-get upgrade
If this doesn’t solve your problem, I suggest that you should take help from someone who knows about Ubuntu and has fixed this problem earlier. You will find a lot of solutions on internet to solve this, don’t try those solutions unless you exactly know what those commands do.
Thanks for the nice tutorial. It works!
Thanks for the kind words!
Hello,
I’m a student, pursuing Masters degree in India. As a part of my curriculum, I’m working in a project that requires OpenCV library. I use Python 2.7.12 in Linux Environment Ubuntu 16.04. I was following the above mentioned steps and it worked fine till Step 5.3. At step 5.3 I faced an error. And I couldn’t solve it. I’ve attached the screenshots of the error message. Please help me. Thank you.
Screenshot_1: https://uploads.disquscdn.com/images/c026873e202f5c32becb93a9428577693761142a7399ab5ffcca7ff490b55964.png
Screenshot_2: https://uploads.disquscdn.com/images/8ca270455b81e218a0bbf4b9fbe0215552f9a5fccd55c87665a2f447c28514fb.png
Use make j1 not j4
Thank you. But the actual problem was found to be absence of GPU in the system.
Thanks!
This is the best manual about OpenCV installation I ever saw!
All other doesn’t work;)
Thanks, Андрей.
Hi! I’, trying to install OpenCV 3.3.0 but I get an error while make-ing:
“CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266”
I’ve got CUDA 8 installed, its path set in PATH variable accordingly.
I googled this error but I can’t find a working solution. I see quite a lot of people solved it by adding “set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -D_FORCE_INLINES)” to openvc/cmake/OpenCVDetectCUDA.cmake but the patch is already there.
The only difference I see from this tutorial is that I’m using Anaconda environments instead of virtualenv but I don’t expect that to be the problem.
One doubt: I have already installed opencv2 using conda, to be used in Python 3. Maybe some conflict?
Any suggestion?
i also had issues building with anaconda in the path, then i removed it from env, and then it built successfully in a new terminal without anaconda in the env.
Hi,
I’m having a problem in the step 3.
############ For Python 2 ############
# create virtual environment
mkvirtualenv facecourse-py2 -p python2
Output:
Running virtualenv with interpreter /home/user/anaconda2/bin/python2
New python executable in /home/user/.virtualenvs/facecourse-py2/bin/python2
Not overwriting existing python script /home/user/.virtualenvs/facecourse-py2/bin/python (you must use /home/user/.virtualenvs/facecourse-py2/bin/python2)
Installing setuptools, pip, wheel…
Complete output from command /home/user/.virtua…urse-py2/bin/python2 – setuptools pip wheel:
Exception:
Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/commands/install.py”, line 272, in run
with self._build_session(options) as session:
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py”, line 72, in _build_session
insecure_hosts=options.trusted_hosts,
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/download.py”, line 329, in __init__
self.headers[“User-Agent”] = user_agent()
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/download.py”, line 69, in user_agent
“python”: platform.python_version(),
File “/home/user/anaconda2/lib/python2.7/platform.py”, line 1470, in python_version
return _sys_version()[1]
File “/home/user/anaconda2/lib/python2.7/platform.py”, line 1422, in _sys_version
repr(sys_version))
ValueError: failed to parse CPython sys.version: ‘2.7.12 (default, Nov 19 2016, 06:48:10) n[GCC 5.4.0 20160609]’
Traceback (most recent call last):
File “”, line 23, in
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/__init__.py”, line 233, in main
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py”, line 251, in main
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py”, line 72, in _build_session
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/download.py”, line 329, in __init__
File “/usr/local/lib/python3.5/dist-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/download.py”, line 69, in user_agent
File “/home/user/anaconda2/lib/python2.7/platform.py”, line 1470, in python_version
return _sys_version()[1]
File “/home/user/anaconda2/lib/python2.7/platform.py”, line 1422, in _sys_version
repr(sys_version))
ValueError: failed to parse CPython sys.version: ‘2.7.12 (default, Nov 19 2016, 06:48:10) n[GCC 5.4.0 20160609]’
—————————————-
…Installing setuptools, pip, wheel…done.
Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/virtualenv.py”, line 2328, in
main()
File “/usr/local/lib/python3.5/dist-packages/virtualenv.py”, line 713, in main
symlink=options.symlink)
File “/usr/local/lib/python3.5/dist-packages/virtualenv.py”, line 945, in create_environment
download=download,
File “/usr/local/lib/python3.5/dist-packages/virtualenv.py”, line 901, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File “/usr/local/lib/python3.5/dist-packages/virtualenv.py”, line 797, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/user/.virtua…urse-py2/bin/python2 – setuptools pip wheel failed with error code 1
Thank you a lot,
and sorry if the question is too obvious.
Excellent tutorial!
Thanks, Alejandro.
Unfortunately it doesn’t work on 17.04 🙁
Yeah, this is specifically for 16.04.
Iam actually using Ubuntu 17.04 and at step 5.2 ,I’m getting an error.
Error(CMake Error: The source directory “/home/manikanta/opencv” does not appear to contain CMakeLists.txt.
Specify –help for usage, or press the help button on the CMake GUI.)
Please help me with this.
Hello, Please help, I’m getting this error when I run ‘import cv2’ in ipython. (Step 6.2)
—————————————————————————
ImportError Traceback (most recent call last)
in ()
—-> 1 import cv2
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
——————————————————————————-
I have followed the procedure for Python 3.6 in this tutorial, but python 2.7 might have already been installed when i was working on earlier project. What do I do now? Should I start the procedure all over again? But if that is so, then what uninstallation commands do I have to run?
Or let me know how to uninstall all the installed packages so that I can start from scratch again. I’ll try installing both simultaneously this time.
I am getting the exact same error, actually, except I have python 3.5.
Hey,
I ran the step 5.4 for Python 2.7 and it worked. But “import cv2” (Step 6.2) only works on Python 2.7 now, I don’t know how to change the default setting and set it up with Python 3 although.
For your problem, I think running Step 5.4 properly again should work.
Older version will no longer available. Try new version.
This tutorial was very useful for me, but seems a luxury configuration:
* gfortran is not necessary for ocv (it is necessary for R, a statistical environment … and for me)
* yasm is not necessary.
*checkinstall is not necessary at all (except if one wants to make one’s build a Debian package : this might be useful if one has a lot of PCs, with about the same hardware and does not want to recompile on each and every PC )
* if protobuf is not install, opencv provides a substitute; same thing happens with jasper (BTW : does libjasper-dev exist on every ubuntu ; my virtual ubuntu 17 could not apt-get it … libopencorexxxs do not seem necessary, either..
But why using a virtual environment? Can’t we install this to just use normally like other packages?
Easier way is to install by Anaconda:
conda install -c menpo opencv
You can install it by Anaconda:
conda install –channel https://conda.anaconda.org/menpo opencv3
You can make your choice, it’s a good idea but not necessary to use virtual environment.
You can make your choice.
I cannot get the RemoveRedEyes example to compile. I get the following error:
/usr/bin/ld: warning: libIlmImf.so.6, needed by /usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libHalf.so.6, needed by /usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
I did a search on my system for these library files and found:
libIlmImf-2_2.so.22 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22
libHalf.so.12 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libHalf.so.12
I tried linking these libraries with the -L flag and get:
/usr/bin/ld: cannot find -libIlmImf
/usr/bin/ld: cannot find -libHalf
What should I do now? I’m kind of lost…
This tutorial works great.
The only problem is I don’t get the prompt back after running the example programs.
That happened to me too. Just kill it with htop.
Why to remove previous x264 installed packages?
I am curious about this myself. I didn’t do it but it still worked. Maybe on some distributions it won’t compile otherwise.
works like charm….Really helped to install C++, Python 2.7, 3.5 OpenCV in Ubuntu 16.04 in one go.
Hello, Thanks for Tuto !
To the step
Step 6.2: Test Python code
The test work for python 2 but not for python 3, how can i fix that ? cv2 is not found for python 3 on ipyhon.
Thanks in advance !
cant we just use
pip install opencv-python
Certainly!
Hi I am using ubuntu 16.04, where i have installed Anaconda3 and by creating conda env i have installed tensorflow,cuda,cuDNN and openCV 3.3.0 (using pip).
Then i import cv2 in python 3.5 most of the things works fine. but cv2.VideoCapture(0) returns false.
here is my code: (to capture video from webcam of my laptop)
”
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*’XVID’)
out = cv2.VideoWriter(‘output.avi’,fourcc, 20.0, (640,480))
while(True):
ret, frame = cap.read()
print(ret)
cv2.imshow(‘frame’,frame)
if cv2.waitKey(1) & 0xFF == ord(‘q’):
break
cap.release()
cv2.destroyAllWindows()
”
And here is error i am getting.
https://uploads.disquscdn.com/images/430b8fb6beeafd6bd3a964159fa1c27bf84a54c9fb0fa48aaa71e8ecb215e776.png
if anyone could solve this problem it will be very very appreciated.
I am also facing the same issue. Did you find the solution for the problem ?
i am also facing same issue
Look in above.
Actually I fixed the problem by installing ffmpeg
can you tell me how to install and also mention if any path to be set
sudo apt-get install ffmpeg
look in in above.
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
out.write(frame)
cv2.imshow(‘frame’,frame)
if cv2.waitKey(1) & 0xFF == ord(‘q’):
break
else:
break
don’t know why I’m getting this error help me to fix this please (I don’t have any GPU instlled in my computer )
In file included from /home/nikhil/opencv/modules/stitching/include/opencv2/stitching.hpp:49:0,
from /home/nikhil/opencv/modules/stitching/src/precomp.hpp:59,
from /home/nikhil/opencv/build/modules/stitching/opencv_stitching_pch_dephelp.cxx:1:
/home/nikhil/opencv/modules/stitching/include/opencv2/stitching/detail/matchers.hpp:52:42: fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory
compilation terminated.
modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/build.make:62: recipe for target ‘modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/opencv_stitching_pch_dephelp.cxx.o’ failed
make[2]: *** [modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/opencv_stitching_pch_dephelp.cxx.o] Error 1
CMakeFiles/Makefile2:20627: recipe for target ‘modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/all’ failed
make[1]: *** [modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs….
[ 21%] Linking CXX static library ../../lib/libopencv_test_optflow_pch_dephelp.a
[ 21%] Built target opencv_test_optflow_pch_dephelp
[ 21%] Linking CXX static library ../../lib/libopencv_optflow_pch_dephelp.a
[ 21%] Built target opencv_optflow_pch_dephelp
[ 21%] Linking CXX static library ../../lib/libopencv_sfm_pch_dephelp.a
[ 21%] Built target opencv_sfm_pch_dephelp
Makefile:162: recipe for target ‘all’ failed
make: *** [all] Error 2
If you don’t need QT or have no QT set WITH_QT=OFF
When I run the Cmake in step 5.2, I keep getting errors Configuring incomplete, errors occurred!
Hey, Thank you for great tutorial. I have one problem. I completed all the steps and I also have “cv2” files available in my build folder but when I import cv2, it again gives me same error that no module named cv2. Check screenshots for reference.
https://uploads.disquscdn.com/images/faedde628d001933e6c4db7a6c2371443e06b7997e8f4a63da3a270b816ac10b.png https://uploads.disquscdn.com/images/8c3f005471fcc0f54f5bb96d5726b66503fd582591ce0e12a2244dec9049e6ac.png
It is looks like you installed the module for python 2, but are trying to run it from python 3
can you explain how? Thanks
I am using raspberry pi 3 Debian Stretch ver 9. I am running OpenCV 3.4.0 What r u running? On IDLE come with 2 ……..pythons..one for python 2 and one for python 3 for raspberry pi 3. Which one r u using? On windows 10 or older used one..the latest is 3.6
Here is image.
https://uploads.disquscdn.com/images/0dd3c13aac85b23b455f7f42b93c9d9697523f1c7d774be989ed0dae08a51dd8.jpg
Hello, my raspberry just finished compiling and installing.
When I try to import cv2 in python3 I get this:
>>> import cv2
Illegal instruction
and I have this in he build directory:
grep -A99 Python version_string.tmp
” Python 3:n”
” Interpreter: /usr/bin/python3 (ver 3.5.3)n”
…
” Python (for build): /usr/bin/python2.7n”
Do you have any suggestion, if I did anything wrong?
Before you import cv2. Did you install python_opencv?
It is looks like you installed the module for python 2, but are trying to run it from python 3
pip3 install opencv-python
My other comment is waiting for approval, but in the meantime I found something (which is sad story for me, but): I had to add the deb-multimedia repository to install some prerequisites… and I read somewhere it’s not intended to work with arm6 (which my pi 1 B based on)
OIC. U r using rapsberry pi 1. But not rpi 3. The rpi 1B is 32-bit. R u using Debian Stretch? .
It’s a Raspbian Stretch.
I have a banana pi m2 berry too with an Ubuntu mate image but there I faced issues earlier which seems harder to solve so I gave up.
Now I’ll try the banana again with Raspbian, at least if the compile works it won1t take more than 24 hours 😀
OH!. U have quad core, right? Did u try sudo make -j1 instead of -j4?
Right, but there I face other issues, based on similar error messages discussed on some forums I guess the QT5 version available from the repo is too old (). Tried with -j1 but it didn’t help. It’s been told to be fixed in latest version of openCV but maybe that works properly with QT5.9 which has no available build for arm (at least I didn’t find and I don’t really want to compile everything)
You will have to go to banana pi forum community. I am not familiar with QT5.9
How can i fix this problem?
R u using python2 or python3?
Using python 2.7
Sorry. I used python 3 on raspberry pi 3. I deleted python 2
That’s shouldn’t be a deal breaker. I just need to know how to make sure python 3 is not summoned but python 2.7 is. Any idea? Since you mentioned the user was trying to run it from Python 3
Python 2 is differentiated from Python 3. The Python 2 will be fading out in 2019. The commands is not the same as Python 3.
Python 2 is differentiated from Python 3. The Python 2 will be fading out in 2019. The commands is not the same as Python 3.
OpenCV 4.0 releases on July, 2018.
hey Nishanth I m having same problem could you tell me how you solved it??
Hey – I wasnt able to get helpful inputs to solve the above problem. Since its a conflict, and after a couple of hours of trying unsuccessfully, I got desperate, I proceeded to bravely delete all python installations except python 2.7 from my system by rm -rf the library folders. I WOULDNT recommend the rm -rf way at all but sometimes i feel its the only way to effectively deal with residual installs and it worked for me.
Next, I deleted the ‘build’ folder in order to restart this installation and switched to using Adrian’s install method from:
https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
I faced stdin issues and HDF5 not available issues (after 70%-80% of compiling done) which I am guessing you might too post solving the python conflict. If you do please add the last two lines mentioned below:
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D INSTALL_PYTHON_EXAMPLES=ON
-D INSTALL_C_EXAMPLES=OFF
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python
-D BUILD_EXAMPLES=ON
-D ENABLE_PRECOMPILED_HEADERS=OFF
-D WITH_HDF5=OFF ..
second last line: solves the stdin error
last line: solves the hdf5 not found error.
Also dont forget to run the above command with the ‘..’ at the last line.
Hey – I wasnt able to get helpful inputs to solve the above problem. Since its a conflict, and after a couple of hours of trying unsuccessfully, I got desperate, I proceeded to bravely delete all python installations except python 2.7 from my system by rm -rf the library folders. I WOULDNT recommend the rm -rf way at all but sometimes i feel its the only way to effectively deal with residual installs and it worked for me.
Next, I deleted the ‘build’ folder in order to restart this installation and switched to using Adrian’s install method from:
https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
I faced stdin issues and HDF5 not available issues (after 70%-80% of compiling done) which I am guessing you might too post solving the conflict. If you do please follow these steps:
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D INSTALL_PYTHON_EXAMPLES=ON
-D INSTALL_C_EXAMPLES=OFF
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python
-D BUILD_EXAMPLES=ON
-D ENABLE_PRECOMPILED_HEADERS=OFF
-D WITH_HDF5=OFF ..
second last line: solves the stdin error
last line: solves the hdf5 not found error.
Also dont forget to run the above command with the ‘..’ at the last line.
Good news! *OpenCV 4.0* releases on *July, 2018.*
Good news! OpenCV 4.0 releases on July, 2018.
How do we rectify this?
4.12.2017
A well written tutorial. I would like to see a Debian Stretch version
so I could try it on a Raspberry Pi 3.
You flash Advert is annoying – one must reload the page after it starts.
I used this one:
https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/
This will come with built-in flask too.
Thanks, all the sample code run successfully.
Hi, Thanks for article. I’m using Ubuntu 14.04 and I followed all the steps and installed OpenCV 3.
I get a lot of error when compiling cpp example. Given below is the log (trimmed a lot of errors for easy readability). I was able to run removeRedEyes.py successfully.
Given below is the log (appologies for the huge log). Appreciate any pointers on what could be going wrong.
[email protected]:~/Downloads/RedEyeRemover$ g++-4.8 -std=c++11 removeRedEyes.cpp `pkg-config –libs –cflags opencv` -o removeRedEyes
/usr/local/lib/libopencv_imgcodecs.a(grfmt_jpeg.cpp.o): In function `cv::my_jpeg_load_dht(jpeg_decompress_struct*, unsigned char*, JHUFF_TBL**, JHUFF_TBL**) [clone .constprop.40]’:
grfmt_jpeg.cpp:(.text.unlikely._ZN2cvL16my_jpeg_load_dhtEP22jpeg_decompress_structPhPP9JHUFF_TBLS5_.constprop.40+0x11e): undefined reference to `jpeg_alloc_huff_table’
/usr/local/lib/libopencv_imgcodecs.a(grfmt_jpeg.cpp.o): In function `cv::JpegEncoder::write(cv::Mat const&, std::vector<int, std::allocator > const&)’:
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0xd8): undefined reference to `jpeg_CreateCompress’
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0xe5): undefined reference to `jpeg_std_error’
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x2b3): undefined reference to `jpeg_set_defaults’
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x2cf): undefined reference to `jpeg_set_quality’
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x2fc): undefined reference to `jpeg_quality_scaling’
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x30a): undefined reference to `jpeg_quality_scaling’
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x34c): undefined reference to `jpeg_default_qtables’
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x35e): undefined reference to `jpeg_start_compress’
grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x3e2):
…..
…..
….
(.text._ZL42OPENCL_FN_clEnqueueNDRangeKernel_switch_fnP17_cl_command_queueP10_cl_kerneljPKmS4_S4_jPKP9_cl_eventPS6_+0x18e): undefined reference to `dlsym’
opencl_core.cpp:(.text._ZL42OPENCL_FN_clEnqueueNDRangeKernel_switch_fnP17_cl_command_queueP10_cl_kerneljPKmS4_S4_jPKP9_cl_eventPS6_+0x262): undefined reference to `dlclose’
/usr/local/lib/libopencv_core.a(opencl_core.cpp.o): In function `OPENCL_FN_clEnqueueFillBuffer_switch_fn(_cl_command_queue*, _cl_mem*, void const*, unsigned long, unsigned long, unsigned long, unsigned int, _cl_event* const*, _cl_event**)’:
opencl_core.cpp:(.text._ZL39OPENCL_FN_clEnqueueFillBuffer_switch_fnP17_cl_command_queueP7_cl_memPKvmmmjPKP9_cl_eventPS6_+0x34): undefined reference to `dlsym’
opencl_core.cpp:(.text._ZL39OPENCL_FN_clEnqueueFillBuffer_switch_fnP17_cl_command_queueP7_cl_memPKvmmmjPKP9_cl_eventPS6_+0x175): undefined reference to `dlopen’
opencl_core.cpp:(.text._ZL39OPENCL_FN_clEnqueueFillBuffer_switch_fnP17_cl_command_queueP7_cl_memPKvmmmjPKP9_cl_eventPS6_+0x18e): undefined reference to `dlsym’
opencl_core.cpp:(.text._ZL39OPENCL_FN_clEnqueueFillBuffer_switch_fnP17_cl_command_queueP7_cl_memPKvmmmjPKP9_cl_eventPS6_+0x262): undefined reference to `dlclose’
/usr/local/lib/libopencv_core.a(opencl_core.cpp.o): In function `OPENCL_FN_clEnqueueCopyImage_switch_fn(_cl_command_queue*, _cl_mem*, _cl_mem*, unsigned long const*, unsigned long const*, unsigned long const*, unsigned int, _cl_event* const*, _cl_event**)’:
opencl_core.cpp:(.text._ZL38OPENCL_FN_clEnqueueCopyImage_switch_fnP17_cl_command_queueP7_cl_memS2_PKmS4_S4_jPKP9_cl_eventPS6_+0x34): undefined reference to `dlsym’
opencl_core.cpp:(.text._ZL38OPENCL_FN_clEnqueueCopyImage_switch_fnP17_cl_command_queueP7_cl_memS2_PKmS4_S4_jPKP9_cl_eventPS6_+0x175): undefined reference to `dlopen’
opencl_core.cpp:(.text._ZL38OPENCL_FN_clEnqueueCopyImage_switch_fnP17_cl_command_queueP7_cl_memS2_PKmS4_S4_jPKP9_cl_eventPS6_+0x18e): undefined reference to `dlsym’
opencl_core.cpp:(.text._ZL38OPENCL_FN_clEnqueueCopyImage_switch_fnP17_cl_command_queueP7_cl_memS2_PKmS4_S4_jPKP9_cl_eventPS6_+0x262): undefined reference to `dlclose’
/usr/local/lib/libopencv_core.a(opencl_core.cpp.o): In function `OPENCL_FN_clEnqueueCopyBuffer_switch_fn(_cl_command_queue*, _cl_mem*, _cl_mem*, unsigned long, unsigned long, unsigned long, unsigned int, _cl_event* const*, _cl_event**)’:
opencl_core.cpp:(.text._ZL39OPENCL_FN_clEnqueueCopyBuffer_switch_fnP17_cl_command_queueP7_cl_memS2_mmmjPKP9_cl_eventPS4_+0x34): undefined reference to `dlsym’
opencl_core.cpp:(.text._ZL39OPENCL_FN_clEnqueueCopyBuffer_switch_fnP17_cl_command_queueP7_cl_memS2_mmmjPKP9_cl_eventPS4_+0x175): undefined reference to `dlopen’
opencl_core.cpp:(.text._ZL39OPENCL_FN_clEnqueueCopyBuffer_switch_fnP17_cl_command_queueP7_cl_memS2_mmmjPKP9_cl_eventPS4_+0x18e): undefined reference to `dlsym’
opencl_core.cpp:(.text._ZL39OPENCL_FN_clEnqueueCopyBuffer_switch_fnP17_cl_command_queueP7_cl_memS2_mmmjPKP9_cl_eventPS4_+0x262): undefined reference to `dlclose’
/usr/local/lib/libopencv_core.a(opencl_core.cpp.o): In function `OPENCL_FN_clLinkProgram_switch_fn(_cl_context*, unsigned int, _cl_device_id* const*, char const*, unsigned int, _cl_program* const*, void (*)(_cl_program*, void*), void*, int*)’:
opencl_core.cpp:(.text._ZL33OPENCL_FN_clLinkProgram_switch_fnP11_cl_contextjPKP13_cl_device_idPKcjPKP11_cl_programPFvS8_PvESB_Pi+0x33): undefined reference to `dlsym’
opencl_core.cpp:(.text._ZL33OPENCL_FN_clLinkProgram_switch_fnP11_cl_contextjPKP13_cl_device_idPKcjPKP11_cl_programPFvS8_PvESB_Pi+0x175): undefined reference to `dlopen’
opencl_core.cpp:
…
…
…
mathfuncs_core.dispatch.cpp:(.text._ZN2cv3hal12magnitude32fEPKfS2_Pfi+0xcc): undefined reference to `ippicvsMagnitude_32f’
/usr/local/lib/libopencv_core.a(mathfuncs_core.dispatch.cpp.o): In function `cv::hal::magnitude64f(double const*, double const*, double*, int)’:
mathfuncs_core.dispatch.cpp:(.text._ZN2cv3hal12magnitude64fEPKdS2_Pdi+0xcc): undefined reference to `ippicvsMagnitude_64f’
/usr/local/lib/libopencv_core.a(mathfuncs_core.dispatch.cpp.o): In function `cv::hal::invSqrt32f(float const*, float*, int)’:
mathfuncs_core.dispatch.cpp:(.text._ZN2cv3hal10invSqrt32fEPKfPfi+0x4e): undefined reference to `ippicvsInvSqrt_32f_A21′
/usr/local/lib/libopencv_core.a(mathfuncs_core.dispatch.cpp.o): In function `cv::hal::invSqrt64f(double const*, double*, int)’:
mathfuncs_core.dispatch.cpp:(.text._ZN2cv3hal10invSqrt64fEPKdPdi+0x4e): undefined reference to `ippicvsInvSqrt_64f_A50′
/usr/local/lib/libopencv_core.a(mathfuncs_core.dispatch.cpp.o): In function `cv::hal::exp32f(float const*, float*, int)’:
mathfuncs_core.dispatch.cpp:(.text._ZN2cv3hal6exp32fEPKfPfi+0x4e): undefined reference to `ippicvsExp_32f_A21′
/usr/local/lib/libopencv_core.a(mathfuncs_core.dispatch.cpp.o): In function `cv::hal::exp64f(double const*, double*, int)’:
mathfuncs_core.dispatch.cpp:(.text._ZN2cv3hal6exp64fEPKdPdi+0x4e): undefined reference to `ippicvsExp_64f_A50′
/usr/local/lib/libopencv_core.a(mathfuncs_core.dispatch.cpp.o): In function `cv::hal::log32f(float const*, float*, int)’:
mathfuncs_core.dispatch.cpp:(.text._ZN2cv3hal6log32fEPKfPfi+0x4e): undefined reference to `ippicvsLn_32f_A21′
/usr/local/lib/libopencv_core.a(mathfuncs_core.dispatch.cpp.o): In function `cv::hal::log64f(double const*, double*, int)’:
mathfuncs_core.dispatch.cpp:(.text._ZN2cv3hal6log64fEPKdPdi+0x4e): undefined reference to `ippicvsLn_64f_A50′
Hello! Thanks for the easy to follow tutorial. However, I am facing an issue with installation. The system I am using is Ubuntu 17.10 with the following kernel details:
“Linux aditya 4.13.0-19-generic #22-Ubuntu SMP Mon Dec 4 11:58:07 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux”.
The g++ version that I am using as default with the Ubuntu is “g++ (Ubuntu 7.2.0-8ubuntu3) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.”
I have nvidia GPU and CUDA 9.0. The samples given with cuda are running nicely. However, compilation (“make”) of opencv shows that compilation is not possible :
”
[ 10%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o
nvcc warning : The ‘compute_20’, ‘sm_20’, and ‘sm_21’ architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
In file included from /usr/include/cuda_runtime.h:78:0,
from :0:
/usr/include/host_config.h:119:2: error: #error — unsupported GNU version! gcc versions later than 5 are not supported!
#error — unsupported GNU version! gcc versions later than 5 are not supported!
^~~~~
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:208 (message):
Error generating
/home/vega/openCV_SOURCE/opencv/build/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o
modules/core/CMakeFiles/opencv_core.dir/build.make:63: recipe for target ‘modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o’ failed
make[2]: *** [modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o] Error 1
CMakeFiles/Makefile2:2718: recipe for target ‘modules/core/CMakeFiles/opencv_core.dir/all’ failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:162: recipe for target ‘all’ failed
make: *** [all] Error 2
”
Please help me to proceed with compilation.
Thank You.
Abhijit
For the time being, I have edited CMakeLists.txt to switch off cuda. Is there any other way?
Thanks for a great tutorial. Everything went fine until I got to calling (running) the Red Eye Remover in python. I got a return: “QXcbConnection: Could not connect to display
Aborted (core dumped)”
Did I miss something?
https://uploads.disquscdn.com/images/d74e85b71009b5b750047f77436abbcfd56cc4c9224f03cc4d63b4dfe5ca14ea.jpg
Hello, I meet some problems with the video. Here is the code below and it does work except the output is v4l2: pixel format of incoming image is unsupported by OpenCV. Is there any solution?
#include “opencv2/opencv.hpp”
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow(“edges”,1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow(“edges”, edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
Kindly, look in OpenCV’s folder….samples/cpp
I do checked the samples/cpp/videocapture_basic.cpp, and i got the same error. What do you mean exactly?
Sorry. You are using Visual Studio. Fortunately, I’m using linux python.
Code ran successfully! As I am a beginner, Can any one brief, how testing of OpenCV3 worked??
Excellent Tutorial !! Thank you. Best one I came across.
I’m installing opencv on raspberry pi 2 model B. “make -j(nproc)” gets stuck at certain percentage (27%). I rebooted it and run the process again at it got stuck at same spot. (At the time of writing), I’m running it with only “make”. It’s too slow. Can you provide a solution or direction?
On raspberry pi 2, did it froze? Did you see on clock on taskbar stopping or not?
yes .. mine did ! what’s the solution plz !
There is no obvious solution, as RAM is too small to have it compiled.
Running with “only” make maybe sufficient (only one process is using RAM) and you can have your RPi compiling during night.
If this is not enough (RAM+swap too small) you can have a greater swap file (on an external disk, minimizing risks of SD card being worn) the following way:
* remove built in swap (on the SD card : 100 M are used, which is not enough)
sudo swapoff -a
prepare a new swap file (ca 1G), on an external disk
dd if=/dev/zero of=/path/to/new/swap/SWP bs=1k count=800k
(form memory)
mkswap /path/to/new/swap/SWP
These former 2 commands are used only once, at swap file generation
The following one is used only when one needs swap file
sudo swapon /path/to/new/swap/SWP
then, launch compilation (beware it may be very long)
Other solution is to have a look at dphys (wraps swapon/swapoff) but the idea is the same.
have to use virtual environment?
You can make your choice
thank’s 🙂
Hi,
I’m getting the following error when I’m trying to use opencv for a different application, kindly help:
undefined reference to `cv::VideoCapture::retrieve(cv::_OutputArray const&, int)’
CMakeFiles/vbtracker-cam.dir/TestStandalone.cpp.o: In function `Main::Main()’:
I am a novice but it seems the opencv_videoio library is not included.
Nice, except that I kept getting the error:
./removeRedEyes: error while loading shared libraries: libopencv_highgui.so.3.4: cannot open shared object file: No such file or directory
After some searching I found out that OpenCV libraries got installed here: /usr/local/lib/x86_64-linux-gnu/
so I had to update this command with the actual library path:
sudo sh -c ‘echo “/usr/local/lib/x86_64-linux-gnu” >> /etc/ld.so.conf.d/opencv.conf’
Now it is working! Thanks!
I have done all the steps and everything runs fine but at the end when I run find /usr/local/lib/ -type f -name “cv2*.so”
Nothing is printed out and I am unable to import cv2 or opencv2 in python3. I have tried repeating the whole installation steps but same result again.
I guess the problem is for those people who don’t want to use virtual environment. Can u please give this liberty not to install virtual environment and plz no anaconda suggestions (don’t want to install a package (anaconda) to run another package (python)) ?
You can skip virtual environment.
I skipped it but the problem was there that no cv2 file was appearing in dist packages. so after another attempt from the start and using git clone https://github.com/opencv/opencv.git with specific destination directory worked for me. sounds weird but worked on my system.
I’d recommend installing opencv before tensorflow unlike me who did the opposite. I don’t know what confict that might cause but since we change PATH and LD_LIBRARY_PATH settings during tensorflow installation in ubuntu so that could also be the reason.
R u using python2 or python3? Did u install OpenCV 3.4.1? Don’t use older version
Edit:
pip3 install opencv-python
i am using python3 and the opencv version installed is 3.3.1 as it was suggested in the tutorial. do you suggest to use command pip3 to update to the newer one ? and if so what other changes ?
OpenCV 3.3.1 is outdated. The OpenCV release is 3.4.1, Can you install 3.4.1?
BTW, change this 3.3.1 to 3.4.1
Yes you can do pip3 too,
so if i use pip3 install opencv-python, would I need to re-set the PATH settings?
I am new in Ubuntu and python so not sure if this step would need further tweaking…
I appreciate your assistance in this matter.
I’m using linux. But you can try it.
i am trying to install open cv.
at step 4 i get stuck in step 4.1
there’s some kind of bash error.
can somebody help me out. https://uploads.disquscdn.com/images/39c0ad5051222ca0aa9ef634b9664f0b7079b4944988e5c4d1bac5c0c2b01b2d.png
I am trying to install opencv3. But unable to go forward due to below error . Could you please assist me with this. https://uploads.disquscdn.com/images/ee75998829febe93fc373aa387a2652705c41c6e10a3f6ac62a44b2677c5cddb.png
R u using raspberry pi?
No it’s a laptop with 4GB Ram.
I don’t if it is quad core or not.
Try sudo make -j1
That will take as least 3 hrs or more depending on ur laptop.
Why we will Rremove any previous installations of x264 ?
I have followed the steps ( omited python libraries and examples and openGL, i want just c++ ) but i got error at 84%
[ 84%] Built target opencv_videostab
Makefile:160: recipe for target ‘all’ failed
make: *** [all] Error 2
What is happening? How can i fix this?
I also omited the python library but on CMAKE command it showed error and i coudnt complete my download how you did it?
R u using raspberry pi 3?
Hi, I think there is an error in line 20.
Maybe you mean libfaad-dev (with ‘d’ instead of ‘c’).
Thanks!
hey am following the above instructions, till Step 5.2 i am able to it from there onwards i got stuck
I think in 5.3 some details are missing .
Hi Rajiv. The command : make -j4 works fine if nproc returns 4. Can you please share with us the exact error?
Just in case you had problems with libtiff on Ubuntu 17.10 OpenCV 4.1 adding
-D BUILD_TIFF=ON to cmake will do the trick
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D INSTALL_C_EXAMPLES=ON
-D INSTALL_PYTHON_EXAMPLES=ON
-D WITH_TBB=ON
-D WITH_V4L=ON
-D WITH_QT=ON
-D WITH_OPENGL=ON
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules
-D BUILD_TIFF=ON
-D BUILD_EXAMPLES=ON ..
http://answers.opencv.org/question/35642/libtiff_40-link-errors/
Just in case you had problems with libtiff on Ubuntu 17.10 OpenCV 4.1 adding
-D BUILD_TIFF=ON to cmake will do the trick
http://answers.opencv.org/question/35642/libtiff_40-link-errors/
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D INSTALL_C_EXAMPLES=ON
-D INSTALL_PYTHON_EXAMPLES=ON
-D WITH_TBB=ON
-D WITH_V4L=ON
-D WITH_QT=ON
-D WITH_OPENGL=ON
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules
-D WITH_TIFF=ON
-D BUILD_TIFF=ON
-D BUILD_EXAMPLES=ON ..
Just in case you had problems with libtiff on Ubuntu 17.10 OpenCV 3.4.1
Do not install libtiff at all and adding:
-D BUILD_TIFF=ON
to cmake will do the trick
http://answers.opencv.org/question/35642/libtiff_40-link-errors/
I was following the installation guideline.After I installed,I was checking for the C++ outup and got this error
removeRedEyes.cpp: In function ‘int main(int, char**)’:
removeRedEyes.cpp:30:38: error: ‘CV_LOAD_IMAGE_COLOR’ was not declared in this scope
Mat img = imread(“red_eyes2.jpg”,CV_LOAD_IMAGE_COLOR);
^~~~~~~~~~~~~~~~~~~
removeRedEyes.cpp:30:38: note: suggested alternative: ‘CV_HAL_DFT_STAGE_COLS’
Mat img = imread(“red_eyes2.jpg”,CV_LOAD_IMAGE_COLOR);
^~~~~~~~~~~~~~~~~~~
CV_HAL_DFT_STAGE_COLS
I am using Ubuntu 18.04 but my python version works well.If anybody could help me to sought this out.
cv2 latest version is 3.4.0
Latest version is 3.4.1
New version is OpenCV 4.0 releases on July, 2018
I am very new to openCV and coming back to Linux after a 10 year sabbath – so I am very rusty on the OS side too – but not a novice. I am running cmake verbatim as shown in the instructions but am getting several issues. https://uploads.disquscdn.com/images/1f3dc60dc5be8515a032c99176b7205e979390da12f7af10df46712188165ec3.png
Any help would be much appreciated.
Hi, did you run the install commands before trying to compile?
This is most probably because of version changes between CMake and OpenCV. Please check : https://stackoverflow.com/questions/39736488/could-not-find-load-file-opencvmodules-cmake
Let us know if it does not work fine. Thanks!
Never mind. I figured it out.
That’s great. If you can share on how you solved this, it might be useful for other users if they encounter the same error. Thanks.
When trying to install virtual environment on pip I’m getting an error message saying ‘ The directory ‘/home/kshama/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
The directory ‘/home/kshama/.cache/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.’ How to enable cache for the parent directory ? Someone help please
Hi. Please try this: sudo -H pip install virtualenv
For more information: https://github.com/pypa/virtualenv/issues/988
Let us know if this does not work. Thanks!
https://stackoverflow.com/questions/50804344/opencv-contrib-xfeature2d-attributeerror-at-virtualenv
Any help here
For python3:
$(sudo) python3 -m pip install opencv-python opencv-contrib-python
Actually installed..
Just to inform you that OpenCV 4.0 will be release July, 2018.
How to install opencv in anaconda
I’m getting this error any idea?
https://uploads.disquscdn.com/images/3d37fd99b0c29282001c47be940b0e621ca6db23922829624f13166023881672.png
This is the only working tutorial for OpenCV + Ubuntu 16.04 that I’ve found!
Alas, I would like to use an IDE to code. Is there a tutorial for setting up OpenCV with any decent IDE?
I try to import the the cv2 library, like in the examples, but it returns the error message No module named ‘cv2’. Any idea what can i have done wrong? Thanks.
hi… during installation of opencv in ubuntu….
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D INSTALL_C_EXAMPLES=ON
-D INSTALL_PYTHON_EXAMPLES=ON
-D WITH_TBB=ON
-D WITH_V4L=ON
-D WITH_QT=ON
-D WITH_OPENGL=ON
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules
-D BUILD_EXAMPLES=ON ..
after executing above step following issue is occur…
Configuring incomplete, errors occurred!
See also “/home/user/opencv/build/CMakeFiles/CMakeOutput.log”.
See also “/home/user/opencv/build/CMakeFiles/CMakeError.log”.
plz help….
thanks….
You can redo it again.
I have the same problem with you, could you please help me if you figure that out? Thank you very much!
https://uploads.disquscdn.com/images/54113cb7488a7db6d0075c3fe69739904c8f7b1bd5023537276c1352b5c7f5b9.png
Hi, I’m using Ubuntu for windows and and having an error when running the python script:
QXcbConnection: Could not connect to display
Anybody have any ideas?
opencv is working…. thank you so much….
When I run workon facecourse-py3, I get the error, virtualenvwrapper.user_scripts could not run “/home/sverma/.virtualenvs/preactivate”: [Errno 8] Exec format error
virtualenvwrapper.user_scripts could not run “/home/sverma/.virtualenvs/facecourse-py3/bin/preactivate”: [Errno 8] Exec format error
I got “nproc” as 4. Then I tried the “make -j4” which ran till 64% and gave errors.
collect2: error: ld returned 1 exit status
modules/viz/CMakeFiles/opencv_test_viz.dir/build.make:238: recipe for target ‘bin/opencv_test_viz’ failed
make[2]: *** [bin/opencv_test_viz] Error 1
CMakeFiles/Makefile2:5804: recipe for target ‘modules/viz/CMakeFiles/opencv_test_viz.dir/all’ failed
make[1]: *** [modules/viz/CMakeFiles/opencv_test_viz.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs….
[ 64%] Built target example_datasets_ir_affine
[ 64%] Built target example_datasets_or_mnist
[ 64%] Built target example_datasets_tr_svt
Makefile:160: recipe for target ‘all’ failed
make: *** [all] Error 2
Hi, I have problem with step 5.2, please see the follow codes:
========================================
Configuring incomplete, errors occurred!
See also “/home/steven/opencv/build/CMakeFiles/CMakeOutput.log”.
See also “/home/steven/opencv/build/CMakeFiles/CMakeError.log”.
========================================
Could you please help me?
Thank you very much!
Steven
https://uploads.disquscdn.com/images/54113cb7488a7db6d0075c3fe69739904c8f7b1bd5023537276c1352b5c7f5b9.png
https://uploads.disquscdn.com/images/be3e5c9b6a34c83267f4862890a5d06b6bc97c243676428f70a709504dea5198.png
i have error in step :5.2
I am facing problem with linking, my program is not compiling and giving the following error,
Just invested my 3-4 hrs but no success, please help.
All the steps were followed on Ubuntu18.04
[email protected]:~/Downloads/RedEyeRemover$ g++ -std=c++11 removeRedEyes.cpp `pkg-config –libs –cflags opencv` -o removeRedEyes
/tmp/ccQgjaHc.o: In function `main’:
removeRedEyes.cpp:(.text+0x2e6): undefined reference to `cv::imread(cv::String const&, int)’
removeRedEyes.cpp:(.text+0x33d): undefined reference to `cv::CascadeClassifier::CascadeClassifier(cv::String const&)’
removeRedEyes.cpp:(.text+0xb8e): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)’
removeRedEyes.cpp:(.text+0xbf4): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)’
/tmp/ccQgjaHc.o: In function `cv::String::String(char const*)’:
removeRedEyes.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to `cv::String::allocate(unsigned long)’
/tmp/ccQgjaHc.o: In function `cv::String::~String()’:
removeRedEyes.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()’
/tmp/ccQgjaHc.o: In function `cv::String::operator=(cv::String const&)’:
removeRedEyes.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()’
collect2: error: ld returned 1 exit status
I’m trying to install OpenCV 3.3.1 on Ubuntu 18.04 with Python version is 3.6.4 in Anacoda, following this blog “Install OpenCV3 on Ubuntu | Learn OpenCV”. However it does NOT working out for the compiling at step 5.3: make -j4 with the following errors. (nproc =4 in my computer)
—
collect2: error: ld returned 1 exit status
modules/plot/CMakeFiles/example_plot_plot_demo.dir/build.make:100: recipe for target ‘bin/example_plot_plot_demo’ failed
make[2]: *** [bin/example_plot_plot_demo] Error 1
CMakeFiles/Makefile2:4766: recipe for target ‘modules/plot/CMakeFiles/example_plot_plot_demo.dir/all’ failed
make[1]: *** [modules/plot/CMakeFiles/example_plot_plot_demo.dir/all] Error 2
[ 44%] Linking CXX executable ../../bin/example_surface_matching_ppf_normal_computation
[ 44%] Built target example_surface_matching_ppf_normal_computation
Makefile:162: recipe for target ‘all’ failed
make: *** [all] Error 2
—
Anyone can help me on this issue? thanks.
i built myself opencv-4.0 and I have already opencv-3.4.1 so in that case how to configure pkg-config, ideal case to have both pkg-config opencv341 and opencv40
after install i followed
make install
sh -c ‘echo “/usr/local/lib” >> /etc/ld.so.conf’
ldconfig
and pkg-config seems not updated
Hello, Excellent script. The only issue is that I am not able to compile OpenCV with OpenGL support on ARM board (ODROID XU-4) for a possible conflict with different versions of openGL installed, for instance OpenGL-ES. Do you have any suggestions for solving this problem?