I have searched google for the process of installing OpenCV on Raspbian Jessie on Raspberry Pi 3 but have not yet found any useful help for the query. Following are the links,

http://www.pyimagesearch.com/2015/07/27/installing-opencv-3-0-for-both-python-2-7-and-python-3-on-your-raspberry-pi-2/

http://www.pyimagesearch.com/2015/10/26/how-to-install-opencv-3-on-raspbian-jessie/

Many of these guides make use of the Virtual Environments which I do not wish to use due to unnecessary complications. Please post full instructions that are very simple and easy to understand.

  • 1
    So have you tried skipping the virtualenv portion? Virtualenv can make this type of project easier, not harder. As it gives you a place to experiment without hoseing your systems python, if it does not work you delete a single directory. – Steve Robillard Jun 29 '17 at 20:04

I was doubtful too about virtualenv, and quite happy to live without it :) Here are the commands I took from both tutorial you provided, for OpenCV 3.1.0

generic stuff

sudo apt-get update
sudo apt-get upgrade
sudo rpi-update
sudo reboot
sudo apt-get install build-essential git cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
cd ~
git clone https://github.com/Itseez/opencv.git
cd opencv
git checkout 3.1.0
cd ~
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv_contrib
git checkout 3.1.0

If you want to use OpenCV with python 2.7 :

sudo apt-get install python2.7-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
pip install numpy
cd ~/opencv
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/modules \
    -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig

If you want to use OpenCV with python 3 :

sudo apt-get install python3-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
pip install numpy
cd ~/opencv
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/modules \
    -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig

Bonus tips :

I'd rather use make instead of make -j4. It's 4 times slower, but avoid some compilation errors (course scenario). You still can try make -j4. In cases of errors just use make clean to remove previously compiled stuff, then run make.

I had some difficulties when downloading opencv and opencv-contrib. Instead of cloning the git, you can download the source in tar.gz format here : https://github.com/opencv/opencv/releases

I will add to what @Technico.top has suggested. There's another method of installing OpenCV using emulation software to compile the software on your PC that doesn't require cross-complication. This means that you'll install the target debian/ubuntu distro on an SD card, expand the filesystem, boot it once to check whether everything works or not, then mount the SD Card to your PC using card reader. You should be able to see two partitions, boot and root of linux file system.

  • create a directory sdcard/ this will server as mount point for your filesystem on the SD cards.
  • Install qemu-static-user (or qemu-user-static in Debian Stretch )in order to emulate arm based hardware on your x86 CPU.
  • mount your physical /proc to your sd-root folder: mount --bind /proc sdcard/proc
  • repeat above step for tmp,sys,run,dev,dev/pts,home - if you have multiple partitions. If you only have a only two partitions, this maybe look like this: sudo mount /dev/sdb1 sdcard/boot/ and sudo mount /dev/sdb2 sdcard/
  • copy the qemu binary onto the sdroot directory using cp /usr/bin/qemu-arm-static sdcard/usr/bin/
  • chroot into the root filesystem. this will essential drop you in shell on the SD card used by the RaspberryPi while it's mounted on your PC. while you are inside your sdcard/ directory, run the following command: chroot . /bin/bash --login.
  • [Optional] Save DNS entries in resolv.conf or any other "Network-related" operations routinely did needs to be done at this point.
  • Now you may proceed with the start the standard installation guide. command that your will run in the chroot sheell, like apt install allow you to install and compile opencv much faster, depending on your hardware.
  • It's worth mentioning that there's a script called opencv3-setup that manages all the download and dependency installation, which makes it easier to install all the necessarily packages.
  • After make and make install commands are executed successfully you can safely remove SD Card using umount /dev/sdb2 and umount /dev/sdb1.
  • Now put the SD Card in RPi or any target ARM SBC and check for OpenCV Installation.

The point mentioned by Technico.top that make -j4 is slower in raspberry pi, but if you install by the method which i have elucidated opencv installation is very fast, I have an Intel i7 PC with 16 GB RAM and it was able to install opencv into SD Card very fast compared to traditional complication that has been reported to range between 6-27 hours.

References -https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot - https://community.arm.com/iot/embedded/b/embedded-blog/posts/cross-compilation-for-arm

  • The package name for Ubuntu 18.04 is qemu-user-static not qemu-static-user. – Ereli Jun 10 at 17:31

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.