Skip to content

Instantly share code, notes, and snippets.

@dynamicguy
Last active April 3, 2024 20:20
Show Gist options
  • Select an option

  • Save dynamicguy/3d1fce8dae65e765f7c4 to your computer and use it in GitHub Desktop.

Select an option

Save dynamicguy/3d1fce8dae65e765f7c4 to your computer and use it in GitHub Desktop.
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>
@lidaweironaldo

Copy link
Copy Markdown

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

@201power

201power commented May 4, 2016

Copy link
Copy Markdown

Very useful, thanks

@tinashemudavanhu

Copy link
Copy Markdown

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

Copy link
Copy Markdown

great!

@tinashemudavanhu

tinashemudavanhu commented May 17, 2016

Copy link
Copy Markdown

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

tmkasun commented May 27, 2016

Copy link
Copy Markdown

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

Iseguel commented Jun 17, 2016

Copy link
Copy Markdown

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

@karanpathak

karanpathak commented Jul 10, 2016

Copy link
Copy Markdown

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

and cv2.ORB is working fine

Please Help !!!

ghost commented Aug 5, 2016

Copy link
Copy Markdown

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

@lhcavalcanti

Copy link
Copy Markdown

anyone has some script like that one for mac OS?

@absentm

absentm commented Jan 6, 2017

Copy link
Copy Markdown

@mikeTools, sure! it;s ok!

@karanpathak

karanpathak commented Jan 15, 2017

Copy link
Copy Markdown

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

hlaidev commented Jan 25, 2017

Copy link
Copy Markdown

broke my virtualenv after running the script.

@sammyaksangai

Copy link
Copy Markdown

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

@yejingx

yejingx commented Mar 28, 2017

Copy link
Copy Markdown

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

coyotte508 commented Jun 10, 2017

Copy link
Copy Markdown

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

@Ha-Ham

Ha-Ham commented Jul 20, 2017

Copy link
Copy Markdown

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

@TrinhNC

TrinhNC commented Sep 8, 2017

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

@Nagaraj104065

Nagaraj104065 commented Dec 30, 2017

Copy link
Copy Markdown

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

eede commented Jan 23, 2018

Copy link
Copy Markdown

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

@hayaalsh

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Are this only work in ubuntu 16.04 ?

@shubhampateliitm

Copy link
Copy Markdown

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

@Geobm

Geobm commented Jul 18, 2020

Copy link
Copy Markdown

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

Same problem here, but Ubuntu 18.04.1

$ 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 ```

throws me:


E: Unable to locate package libxine-dev
E: Unable to locate package libgstreamer0.10-dev
E: Couldn't find any package by glob 'libgstreamer0.10-dev'E: Couldn't find any package by regex 'libgstreamer0.10-dev'
E: Unable to locate package libgstreamer-plugins-base0.10-devE: Couldn't find any package by glob 'libgstreamer-plugins-base0.10-dev'
E: Couldn't find any package by regex 'libgstreamer-plugins-base0.10-dev'

I've tried different ways to install libxine-dev effortless. Any idea how to solve it?

@hasantha-nirmal

Copy link
Copy Markdown

If any of you use Ubuntu 16.04 with cuda 10.0 ,then please install 2.4.13.2 instead of this version, cause due to cuda mismatch the build won't work.

And cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler .. @HamdiHamed1992
if this error occurs:
'nvcc fatal : Unsupported gpu architecture 'compute_20'

@AbdullahKhanML

Copy link
Copy Markdown

Outstanding! Worked the first time. Thanks

Outstanding! Worked the first time. Thanks!

Which version of Ubuntu have you used for installing it? I am installing it on Ubuntu 16.04.7 on a VirtualBox (Win 10), but get errors.

@AbdullahKhanML

Copy link
Copy Markdown

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

Hello, I also want to make it work on Python 3.5/3.5+ -- any luck getting it worked on Python 3.5+?

@AbdullahKhanML

Copy link
Copy Markdown

Everything goes fine until I run the following command.

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

When I run the above command, it gives me the following error:

"E: Package 'libxine-dev' has no installation candidate"

I have python 3.8.9 installed on Ubuntu 16.04.7

@rupikaraj

Copy link
Copy Markdown

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

Same problem here, but Ubuntu 18.04.1

$ 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 ```

throws me:


E: Unable to locate package libxine-dev
E: Unable to locate package libgstreamer0.10-dev
E: Couldn't find any package by glob 'libgstreamer0.10-dev'E: Couldn't find any package by regex 'libgstreamer0.10-dev'
E: Unable to locate package libgstreamer-plugins-base0.10-devE: Couldn't find any package by glob 'libgstreamer-plugins-base0.10-dev'
E: Couldn't find any package by regex 'libgstreamer-plugins-base0.10-dev'

I've tried different ways to install libxine-dev effortless. Any idea how to solve it?

I'm using ubuntu 18.04, and still got the same error.
I tried 'libxine2' instead of 'libxine-dev' and it works !

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