---
# System prepended metadata

title: Raspberrypi OpenCV install

---

# Raspberrypi OpenCV install 
## install opencv in python 2
### install opencv
```
sudo apt-get install libopencv-dev
sudo apt-get install python-opencv
```
### test ###
terminal->python2
```
import cv2
cv2.__version__
```
## install opencv in python 3.7 
### update and upgrade your pi
```
sudo apt-get update
sudo apt-get upgrade
```
### install numpy ###
```
pip3 install numpy
```
### Expand Filesystem ###
```
sudo raspi-config
```
#### Advanced Options->Expand Filesystem->reboot your raspberrypi ####
### Install library OpenCV need
```
sudo apt-get install build-essential cmake git unzip pkg-config
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libgtk2.0-dev libcanberra-gtk*
sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev
sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev
sudo apt-get install libv4l-dev v4l-utils
sudo apt-get install libjasper-dev libopenblas-dev libatlas-base-dev libblas-dev
sudo apt-get install liblapack-dev gfortran
sudo apt-get install gcc-arm*
sudo apt-get install protobuf-compiler
```
### Download OpenCV ###
```
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
```
### mkdir ###
```
cd opencv
mkdir build
cd build
```
### cmake ###
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
        -D CMAKE_INSTALL_PREFIX=/usr/local \
        -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
        -D ENABLE_NEON=ON \
        -D ENABLE_VFPV3=ON \
        -D WITH_OPENMP=ON \
        -D BUILD_TIFF=ON \
        -D WITH_FFMPEG=ON \
        -D WITH_GSTREAMER=ON \
        -D WITH_TBB=ON \
        -D BUILD_TBB=ON \
        -D BUILD_TESTS=OFF \
        -D WITH_EIGEN=OFF \
        -D WITH_V4L=ON \
        -D WITH_LIBV4L=ON \
        -D WITH_VTK=OFF \
        -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic \
        -D OPENCV_ENABLE_NONFREE=ON \
        -D INSTALL_C_EXAMPLES=OFF \
        -D INSTALL_PYTHON_EXAMPLES=OFF \
        -D BUILD_NEW_PYTHON_SUPPORT=ON \
        -D BUILD_opencv_python3=TRUE \
        -D OPENCV_GENERATE_PKGCONFIG=ON \
        -D BUILD_EXAMPLES=OFF ..
```
### compile ###
```
make -j4
```
### install
```
sudo make insall
```
### test ###
terminal->python3
```
import cv2
cv2.__version__
```
