Skip to content

Instantly share code, notes, and snippets.

Embed
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>
@boneheadmed

This comment has been minimized.

Copy link

commented May 8, 2015

Outstanding! Worked the first time. Thanks!

@majidhazari

This comment has been minimized.

Copy link

commented Jun 12, 2015

Very useful. Thanks.

@mattmezza

This comment has been minimized.

Copy link

commented Jul 28, 2015

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.

@Yami-Bitshark

This comment has been minimized.

Copy link

commented Aug 1, 2015

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

@Yami-Bitshark

This comment has been minimized.

Copy link

commented Aug 1, 2015

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

This comment has been minimized.

Copy link

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)

@agakshat

This comment has been minimized.

Copy link

commented Sep 19, 2015

Great script man! worked without any hassles

@jorgepsmatos

This comment has been minimized.

Copy link

commented Oct 17, 2015

Worked on ubuntu 12.04.

@samuelololol

This comment has been minimized.

Copy link

commented Nov 14, 2015

message from ubuntu-15.10

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

This comment has been minimized.

Copy link

commented Nov 17, 2015

Python:

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

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

@khushali

This comment has been minimized.

Copy link

commented Feb 16, 2016

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?

@lidaweironaldo

This comment has been minimized.

Copy link

commented Mar 27, 2016

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

@201power

This comment has been minimized.

Copy link

commented May 4, 2016

Very useful, thanks

@GingerMuda

This comment has been minimized.

Copy link

commented May 5, 2016

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.

@liguanbin

This comment has been minimized.

Copy link

commented May 6, 2016

great!

@GingerMuda

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Jun 17, 2016

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

@karanpathak

This comment has been minimized.

Copy link

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 !!!

@ghost

This comment has been minimized.

Copy link

commented Aug 5, 2016

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

@lhcavalcanti

This comment has been minimized.

Copy link

commented Sep 16, 2016

anyone has some script like that one for mac OS?

@absentm

This comment has been minimized.

Copy link

commented Jan 6, 2017

@Miketools, sure! it;s ok!

@karanpathak

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Jan 25, 2017

broke my virtualenv after running the script.

@sammyaksangai

This comment has been minimized.

Copy link

commented Mar 23, 2017

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

@yejingx

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Jun 10, 2017

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

@HamdiHamed1992

This comment has been minimized.

Copy link

commented Jul 20, 2017

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

This comment has been minimized.

Copy link

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)

@lmiguelmh

This comment has been minimized.

Copy link

commented Oct 27, 2017

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

@Nagaraj104065

This comment has been minimized.

Copy link

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

@eede

This comment has been minimized.

Copy link

commented Jan 23, 2018

Ubuntu 16.04 requires unzip to be installed as well. Thanks for the script.

@Haya-Alsharif

This comment has been minimized.

Copy link

commented Jul 22, 2018

All the dependencies in the shell looks fine, however to install opencv-2.4.11 there is an easier way to do it by running: sudo apt-get install python-opencv in your command line. Note that the SIFT/SURF API has changed due to patent issues and can be called like this:

import cv2
cv2.xfeatures2d.SIFT_create()

Notice that the second line used to be called using cv2.SIFT. Details can be found here

@SantoDon

This comment has been minimized.

Copy link

commented Nov 22, 2018

Are this only work in ubuntu 16.04 ?

@lifeisshubh

This comment has been minimized.

Copy link

commented Apr 10, 2019

one thing is truly told by Linus Torvald that Ubuntu is horrible with the make command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.