Install OpenCV4 on Raspberry Pi 3

Install OpenCV 4.2.0.

■ Environment  - Raspberry Pi 3   - g++ 4.9.2   - Python3.4.2

■ Prerequisites The following is installed  - Git  - cmake  - GNU Make

■ Procedure

    1. Increase the swap area so that memory allocation does not fail
$ sudo nano /etc/dphys-swapfile

Change CONF_SWAPSIZE from 100 to` `1024.

/etc/dphys-swapfile


CONF_SWAPSIZE=1024

Reflect the changes.

$ sudo /etc/init.d/dphys-swapfile restart
  1. Install dependent files
$ sudo apt update
$ sudo apt install build-essential cmake git pkg-config libgtk-3-dev "libcanberra-gtk*"
$ sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev
$ sudo apt install libjpeg-dev libpng-dev libtiff-dev gfortran openexr libatlas-base-dev opencl-headers
    1. Download the opencv source file
$ git clone --branch 4.2.0 https://github.com/opencv/opencv.git
$ git clone --branch 4.2.0 https://github.com/opencv/opencv_contrib.git
  1. Create a build directory
$ mkdir <path-to-opencv>/opencv/build
$ cd <path-to-opencv>/opencv/build
  1. Create a configuration file
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=OFF \
    -D INSTALL_PYTHON_EXAMPLES=OFF \
    -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D ENABLE_NEON=ON \
    -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic \
    -D ENABLE_VFPV3=ON \
    -D BUILD_TESTS=OFF \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D OPENCV_EXTRA_MODULES_PATH=/<path-to-opencv>/opencv_contrib/modules \
    -D BUILD_EXAMPLES=OFF ..

`Configuring done` and `Generating done` are displayed, and confirm that the process was completed normally.

  1. Compile
$ make -j4
  1. Install the compiled file
$ sudo make install
  1. Confirm that it was installed successfully
$ pkg-config --modversion opencv4

Output


4.2.0
$ python3 -c "import cv2; print(cv2.__version__)"

Output


4.2.0

■ Reference link How to Install OpenCV on Raspberry Pi 3 https://linuxize.com/post/how-to-install-opencv-on-raspberry-pi/

Recommended Posts

Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
raspberry pi 4 centos7 install on docker
Install ghoto2 on Raspberry Pi (memo)
OpenCV installation procedure on Raspberry Pi
pigpio on Raspberry pi
Install 64-bit OS (bate) on Raspberry Pi
Install docker-compose on 64-bit Raspberry Pi OS
Cython on Raspberry Pi
Install Raspberry Pi OS (Raspbian)
Install OpenCV on Ubuntu + python
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Build an OpenCV4 environment on Raspberry Pi using Poetry
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Install pyenv on Raspberry Pi and version control Python
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
Testing uart communication on Raspberry Pi
MQTT on Raspberry Pi and Mac
Install OpenCV and Chainer on Ubuntu
Build and install OpenCV on Windows
How to install OpenCV on Mac
Try using ArUco on Raspberry Pi
Power on / off Raspberry pi on Arduino
Detect switch status on Raspberry Pi 3
L Chika on Raspberry Pi C #
Build wxPython on Ubuntu 20.04 on raspberry pi 4
Install opencv on Mac using Anaconda Navigator
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Detect "brightness" using python on Raspberry Pi 3!
"Honwaka Notification Lamp" on Raspberry Pi Part 1
Enable UART + serial communication on Raspberry Pi
Accelerate Deep Learning on Raspberry Pi 4 CPU
Set swap space on Ubuntu on Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Raspberry Pi backup
Use the Grove sensor on the Raspberry Pi
Run servomotor on Raspberry Pi 3 using python
Working with sensors on Mathematica on Raspberry Pi
Build OpenCV-Python environment on Raspberry Pi B +
Detect temperature using python on Raspberry Pi 3!
Opencv install struggle
Mount Windows shared folder on Raspberry Pi
Matrix multiplication on Raspberry Pi GPU (Part 2)
I installed OpenCV-Python on my Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Why detectMultiScale () is slow on Raspberry Pi B +
How to install OpenCV on Jetson Nano Python
Detect slide switches using python on Raspberry Pi 3!
Build a Django environment on Raspberry Pi (MySQL)
Try using a QR code on a Raspberry Pi
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Detect magnet switches using python on Raspberry Pi 3!
Enjoy electronic work with GPIO on Raspberry Pi
Power on / off your PC with raspberry pi
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Make DHT11 available on Raspberry Pi + python (memo)
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Sound the buzzer using python on Raspberry Pi 3!
Play with your Ubuntu desktop on your Raspberry Pi 4
Introduced Ceph on Kubernetes on Raspberry Pi 4B (ARM64)