Skip to content

Instantly share code, notes, and snippets.

@fovea1959
Last active May 21, 2018 18:10
Show Gist options
  • Select an option

  • Save fovea1959/5dc4fb93742606295c49d40848bd5941 to your computer and use it in GitHub Desktop.

Select an option

Save fovea1959/5dc4fb93742606295c49d40848bd5941 to your computer and use it in GitHub Desktop.
Building opencv 3.2 on a raspberry pi

These are probably from an earlier version of https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/

  • install prereqs
apt-get update
apt-get upgrade

apt-get install build-essential git cmake pkg-config
apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
apt-get install libxvidcore-dev libx264-dev
apt-get install libgtk2.0-dev
apt-get install libatlas-base-dev gfortran
apt-get install python2.7-dev python3-dev
  • download and unzip opencv
cd ~
wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip
unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.2.0.zip
unzip opencv_contrib.zip
  • edit .profile to read
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
  • use profile
source ~/.profile
  • put together a new Python 3 virtualenv w/ numpy
mkvirtualenv cv -p python3
pip install numpy
  • get ready to build
cd ~/opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=OFF \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
    -D BUILD_EXAMPLES=ON \
    -D ENABLE_NEON=ON ..
  • build it. this will take a while. leave off -j3 to single thread the build (takes longer, but more reliable
sudo bash -c "time make -j3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment