Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
install opencv-2.4.11 in ubuntu
# install dependencies
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y cmake
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y pkg-config
sudo apt-get install -y python-numpy python-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libjpeg-dev libpng-dev libtiff-dev libjasper-dev
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils
# download opencv-2.4.11
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.11/opencv-2.4.11.zip
unzip opencv-2.4.11.zip
cd opencv-2.4.11
mkdir release
cd release
# compile and install
cmake -G "Unix Makefiles" -D CMAKE_CXX_COMPILER=/usr/bin/g++ CMAKE_C_COMPILER=/usr/bin/gcc -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_FAT_JAVA_LIB=ON -D INSTALL_TO_MANGLED_PATHS=ON -D INSTALL_CREATE_DISTRIB=ON -D INSTALL_TESTS=ON -D ENABLE_FAST_MATH=ON -D WITH_IMAGEIO=ON -D BUILD_SHARED_LIBS=OFF -D WITH_GSTREAMER=ON ..
make all -j4 # 4 cores
sudo make install
# ignore libdc1394 error http://stackoverflow.com/questions/12689304/ctypes-error-libdc1394-error-failed-to-initialize-libdc1394
#python
#> import cv2
#> cv2.SIFT
#<built-in function SIFT>

Outstanding! Worked the first time. Thanks!

Very useful. Thanks.

Hey I'm on 15.04 but I'm not able to compile OpenCv 2.4.11, seems like there is a problem with ffmpeg with the highgui module.

Mattmezz, the 'sudo apt-get install -y libopencv-dev' is missing in the script, please add it to the script or do it manually. it will solve your problem

if it doesnt work, add this option to the cmake " -D WITH_FFMPEG=OFF " it will disable the ffmpeg ( i think u dont need it ), but it will solve your problem 100% (only for Ubuntu 15.04, because the ffmpeg is dropped or replaced , i dont know exactly)

ekeup commented Aug 18, 2015

I'm running Ubuntu 14.10 and had to add:
sudo apt-get install libqt4-dev
and add this in the cmake "-D WITH_FFMPEG=OFF" (as Yami-Bitshark recommended)

Great script man! worked without any hassles

Worked on ubuntu 12.04.

message from ubuntu-15.10

Note, selecting 'libpng12-dev' instead of 'libpng-dev'
Note, selecting 'libtiff5-dev' instead of 'libtiff-dev'

Python:

import cv2
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named cv2

=> [SOLVED] $ sudo apt-get install python-opencv

I am on 15.04 but can't compile opencv 2.4.11 and i tried what Yami-Bitshark said anything else to add or remove?

In case of error "nvcc fatal : Unsupported gpu architecture 'compute_11' ", add "-D CUDA_GENERATION=Kepler .." to the end of cmake.

201power commented May 4, 2016

Very useful, thanks

I am getting the following error when running cmake

Parse error in command line argument: -D
Should be: VAR:type=value
CMake Error: No cmake script provided.
CMake Error: Problem processing arguments. Aborting.

great!

GingerMuda commented May 17, 2016

I was getting import cv2 errors so just thought of posting a solution here incase someone might have the same problem. If opencv installs successfully, you need to check if cv2.so is in /usr/local/lib/python2.7/site-packages/ directory. If its not there then you have to copy it there because cmake fails to copy it there. To find its location you search for it with find / -name "cv2.so". Same applies with cv.py, it also has to be copied in the same directory. You search for it using find / -name "cv.py"Open nano ~/.bashrc and add the following statement at the end; export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages Make sure you reboot your device.

tmkasun commented May 27, 2016

Thanks ,
I also had to run sudo apt-get install python-opencv to work with python (2.7)
@GingerMuda Will it work for python 3.4 as well ?

Iseguel commented Jun 17, 2016

Great script, worked on Ubuntu 16.04
Note, selecting 'libxine2' instead of 'libxine-dev'

karanpathak commented Jul 10, 2016

I have imported cv2 but
cv2.SIFT
shows: AttributeError: 'module' object has no attribute 'SIFT'

and cv2.ORB is working fine

Please Help !!!

I am using Ubuntu 15.04 and it doesn't work, I tried -D WITH_FFMPEG=OFF nothing solved, please help

anyone has some script like that one for mac OS?

absentm commented Jan 6, 2017

@Miketools, sure! it;s ok!

karanpathak commented Jan 15, 2017

SOLVED

cv2.SIFT shows: AttributeError: 'module' object has no attribute 'SIFT'

Copy opencv-2.4.11/release/lib/cv2.so file to /usr/lib/python2.7/dist-packages

hlaidev commented Jan 25, 2017

broke my virtualenv after running the script.

Thanks. It worked on python 2.7.12. (which is my default one). How to make it work on python 3.5?

yejingx commented Mar 28, 2017

try http://techtidings.blogspot.hk/2012/01/problem-with-libglso-on-64-bit-ubuntu.html if

make[2]: *** No rule to make target `/usr/lib/x86_64-linux-gnu/libGL.so', needed by `bin/opencv_annotation'.  Stop.

because of a broken link.

coyotte508 commented Jun 10, 2017

Ubuntu 16.04, libxine-dev is not found, fails the rest. Maybe it should be on a separate line?

for people who are facing this error :
nvcc fatal : Unsupported gpu architecture 'compute_11'
try to compile with this cmake command under the release folder :
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..

TrinhTUHH commented Sep 8, 2017

If there is error with graphcuts.cpp, try this:
Open the file "/opencv-2.4.11/modules/gpu/src/graphcuts.cpp" and replace
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
by
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

@TrinhTUHH thanks. It seems this problem was solved in the latest version (2.4.13.4)

Nagaraj104065 commented Dec 30, 2017

HOW TO FIX
make[2]: *** [modules/core/CMakeFiles/cuda_compile.dir/__/dynamicuda/src/cuda/./cuda_compile_generated_matrix_operations.cu.o] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2

Built target pch_Generate_opencv_perf_highgui
make: *** [all] Error 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment