Skip to content

Instantly share code, notes, and snippets.

@kevin-george
Last active July 13, 2017 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevin-george/955e1d20d2305dbe3b1e8e6675230268 to your computer and use it in GitHub Desktop.
Save kevin-george/955e1d20d2305dbe3b1e8e6675230268 to your computer and use it in GitHub Desktop.
Install opencv 2.4 from source with python2.x exntensions on Ubuntu 16.04
# Install all the dependencies
sudo apt-get update
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libpng-dev libtiff-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-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
# Get latest opencv code
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 2.4
# Build opencv
mkdir build
cd build
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 #Assuming the machine has 4 cores
sudo make install
# Check opencv installation
# Check if /usr/local/lib/python2.7/site-packages/ has cv2.so
if [ ! -f "/usr/local/lib/python2.7/site-packages/cv2.so" ]
then
echo "/usr/local/lib/python2.7/site-packages/cv2.so not found!!\n"
echo "Run find / -name cv2.so and copy cv2.so to /usr/local/lib/python2.7/site-packages/"
fi
## Add the location to PYTHONPATH
echo "export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages" >> ~/.bashrc
source ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment