- techesoterica.com
- A blog dealing with sensory substitution and other esoteric concepts and technologies like speech-recognition and chaos theory
- Main navigation
- Installing opencv on Arch Linux from source
- Installing dependencies
- Note
- Setting up python version 3
- Download OpenCV
- Expand OpenCV and set up the folders
- Building OpenCV
- Make the virtual environment
- Install numpy
- Generate the build files
- Increase the size of the swap file
- Compile and install OpenCV
- Turn off the swap file
- Linking in the OpenCV binding into our python virtual environment
- Note
- Testing your installation
- Troubleshooting
- Build-essential Manjaro GNU/Linux Installation Guide
- Manjaro Linux Install Build Essentials – Quick-Start Guide
- 1. Terminal Quick Start
- Contents
- Follow Us
- The GNU/Linux Free Software Phylosophy
- Steve Jobs’ Last Words
- Credits
techesoterica.com
A blog dealing with sensory substitution and other esoteric concepts and technologies like speech-recognition and chaos theory
Main navigation
Installing opencv on Arch Linux from source
I am going to be showing you how to install the OpenCV computer vision library from source. This is the best way to install this library to ensure that you get the full set of features this library has to offer. Moreover, it allows you to customize your installation. For example, you may not want any python bindings.
This post has been inspired by the tutorials at PyImageSearch and Learn OpenCV.
The bulk of this tutorial has been taken from the superb tutorial at
Install OpenCV 4 on your Raspberry Pi
Installing dependencies
The first thing you need to do is to install dependencies. I am a newcomer to Arch Linux. I come from Ubuntu. The package names are different between Ubuntu and arch Linux. You need to use a search string like
«arch linux»
in your search engine of choice to find the package names.
If you wanted to search for the package called build-essentials in Arch Linux, the search string you would use is
«Arch linux» build-essentials
The tutorial on installing OpenCV on the raspberry pi lists a series of dependencies. I have created an Arch Linux mapping to the Ubuntu dependencies and have given the equivalent commands.
Note
I am using the image created by the F123 project which as an accessible Arch Linux on the raspberry pi. I installed OpenCV on that image therefore most of my dependencies were met.
Run each of the commands and follow the prompts. If a dependency is already installed, then select not to reinstall it.
Raspbian | Arch Linux |
---|---|
sudo apt-get install build-essential cmake unzip pkg-config | yay -S build-devel yay -S cmake |
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev | yay -S libjpeg yay -S libtiff yay -S libpng |
sudo apt-get install libxvidcore-dev libx264-dev | yay -S xvidcore yay -S libx264 |
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev | yay -S ffmpeg yay -S v4l-utils |
sudo apt-get install libgtk-3-dev | yay -S gtk3 |
sudo apt-get install libcanberra-gtk* | yay -S libcanberra |
sudo apt-get install libatlas-base-dev gfortran | yay -S lapack yay -S gcc-fortran |
sudo apt-get install python3-dev | already done because python development headers are already installed |
Setting up python version 3
I am maximizing my use of python 3 which is what I will be using here. Python3 is already installed therefore, all we need to do now is to create a python virtual environment to keep things isolated.
sudo pip3 install virtualenv virtualenvwrapper
Clean the package cache.
sudo rm -rf ~/get-pip.py ~/.cache/pip
We need to enable some convenience commands to be able to redily invoke our virtual environment. Ensure that you are in your home directory.
cd ~ and then press enter.
Run the following commands to add to your .profile file.
echo -e «\n# virtualenv and virtualenvwrapper» >> ~/.profile
echo «export WORKON_HOME=$HOME/.virtualenvs» >> ~/.profile
echo «export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3» >> ~/.profile
echo «source /usr/bin/virtualenvwrapper.sh» >> ~/.profile
Once the above commands are run, you can verify that the file has been created correctly by examining its contents.
cat .profile
Activate the commands by issuing the following command.
source .profile
Download OpenCV
Ensure that you are in your home folder.
cd ~
Run the following commands to download OpenCV version 4, the latest at the time of this writing to your raspberry pi.
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.0.zip
Expand OpenCV and set up the folders
It is time to expand the zip archives you downloaded.
unzip opencv.zip
unzip opencv_contrib.zip
Rename the folders for easy reference.
mv opencv-4.0.0 opencv
mv opencv_contrib-4.0.0 opencv_contrib
Building OpenCV
Make the virtual environment
Run the following command to make your OpenCV virtual environment.
mkvirtualenv cv -p python3
You can name your virtual environment whatever you like. If you do name it differently, remember to account for that during the rest of this tutorial.
Switch to your virtual environment by executing the following command.
workon cv
The command prompt will change such that the name of your virtual environment will be displayed as a part of the prompt. You can exit the environment by using the following command.
deactivate
Install numpy
You need to install a dependency for OpenCV python.
Ensure that you are in your virtual environment.
workon cv
pip install numpy
The installation of numpy is going to take quite some time. Do not be alarmed.
Generate the build files
It is time to create the build files for OpenCV.
Switch to the opencv folder, create a build folder to hold the build files and then switch to it.
cd ~/opencv
mkdir build
cd build
Run cmake to generate the files. If you are copy pasting the below lines, do not manually try to delete the line breaks and create a single huge command. Copy paste each line and hit enter. The two fulstop characters at the end of the last line tell cmake that it should run.
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 BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SIZEOF_VOID_P=4 \
-D BUILD_opencv_python3=TRUE \
-D BUILD_EXAMPLES=OFF ..
Do inspect the output and ensure that you do not see any significant errors. You may want to enable the logging facility in your terminal emulation program assuming you are running headless on your raspberry pi.
Increase the size of the swap file
The raspberry pi is a memory constrained device. You need to create a swap file to allow for the compile to complete. It is crucial that you do this else the compilation process will not complete.
In Arch Linux, you need to create a swap file first and then activate it. Issue the following commands.
sudo dd if=/dev/zero of=/swp bs=1024 count=4000000
sudo chmod 600 /swp
sudo mkswap /swp
sudo swapon /swp
See below for what these commands mean.
sudo dd if=/dev/zero of=/swp bs=1024 count=4000000
Create a file which will become our swap file. This file must be as large as the swap file we want. I have taken 4GB for safety.
sudo chmod 600 /swp
Assign the right permission to the file we have created.
sudo mkswap /swp
Convert our ordinary file to a swap file.
sudo swapon /swp
Activate the swap file.
Compile and install OpenCV
Ensure that you are in the build folder.
cd ~/opencv/build
Warning, the below command takes several hours to complete. It is the longest part of this procedure. Keep the logging in your terminal emulator active.
make
You can make things go faster by issuing the -j flag with make.
make -j
This utilizes all available CPU cores. You can specify the number of cores you want make to use.
make -j2
The above command will use only two cores. In my experience, running just make is sufficient. I have had the compilation being interrupted if I have used more than one core. Your mileage may vary.
If make completes without errors then run the following commands.
sudo make install
sudo ldconfig
OpenCV is now installed. There are however more steps to follow to ensure that the python bindings work with our virtual environment.
Turn off the swap file
It is crucial that you switch off the swap file else you risk reducing the life of the SD card in the raspberry pi due to the increased write operations that the pi will perform when it swaps memory to the SD card.
sudo swapoff /swp
You can recover space by deleting the swap file.
sudo rm /swp
Linking in the OpenCV binding into our python virtual environment
It is time to create a sim link to the OpenCV library in our python virtual environment.
Issue the following commands.
Note
I am writing this tutorial based on python 3.7. The version of python may change therefore please adjust your steps accordingly.
Run the below commands.
cd ~/.virtualenvs/cv/lib/python3.7/site-packages/
ln -s /usr/local/python/cv2/python-3.7/cv2.cpython-37m-arm-linux-gnueabihf.so cv2.so
Testing your installation
Carry out the following steps to verify if you have installed OpenCV with its python bindings correctly.
workon cv
Ensure that the virtual environment is active. If the above command fails, then do a
source .profile
to ensure that the relevant commands are loaded.
Launch python by issuing the following command
python
Then enter the following text in the interpreter that comes up.
import cv2
If the above commands without an error and your cursor moves to the next line, you can type:
cv2.__version__
You should see the version of OpenCV you have installed. Execute
quit()
to exit python.
Troubleshooting
If the make fails, ensure that your swap file is active and do not issue the -j flag.
If you get unusual errors and the compilation process goes very fast but stops in the middle, you should check the paths to your contrib folder and ensure that all other paths are right.
Build-essential Manjaro GNU/Linux Installation Guide
Manjaro Linux Install Build Essentials – Quick-Start Guide
You are Welcome! The Tutorial shows you Step-by-Step How to Install Build Essentials in Manjaro GNU/Linux.
And Build Essentials for Manjaro is a Suite of Development Tools Software.
The Build Essentials for Manjaro includes the following Packages: autoconf, automake, binutils, bison, fakeroot, file, findutils, flex, gawk, gcc, gettext, grep, groff, gzip, libtool, h4, make, pacman, patch, pkgconf, sed, sudo, sytemd, textinf, util-linux, and which.
1. Terminal Quick Start
Contents
Showing Ads here is the best solution I found for not embarassing somebody about participating in a #%$Foundation^.
«When the Last Tree has been cut down, the Last Fish caught, the Last River poisoned, only then will we realize that One Cannot Eat Money.»
«No usable Computer exists today with completely Open Software and Hardware (as much as some companies want to Market themselves as such).»
Follow Us
The GNU/Linux Free Software Phylosophy
Steve Jobs’ Last Words
«Being a Winner in a Free Computing OS Mission means to adopt a Commercial like Strategy. Transcending Duality in Oneness and so dispensing both Free and Non Free Software. Cause evangelizing Freedom in a Non Free World is like keeping a Trojan Horse. Hallelujah!»
«Using the Money just for buying Stuff and Not Supporting the Free Gift Philosophy is a sign of a Selfish and Narrow Mind.»
What can Save the World from a Blind and Quick Self-destruction.
The Immediate and Humble Mass Conversion to the Spiritual Way!
Because Earth & Nature has been Ravaged without Pity by the Wild and Selfish mass Competition to Win and Shown that U’re someone Better because you got a Lot of fla$hY Power$$$.
«Taking care if somebody is liking, following, or buying is just a serious hidrance on the priceless Way of Creative Freedom.»
Credits
Everlasting Glory to God, Jesus Christ, The Holy Spirit, Ganesha, Shiva, Vishnu, Krisna, Laozi, Buddha, Bodhidharma, Ma Gcig, Hakuin, Ikkyu, Nagarjuna, Tilopa, Naropa, Milarepa, Suhrawardi, St Dismas, St Francesco, St Teresa, St John, St Filippo, Eckehart. All The Holy Divinities, Avatars, Saints, Mystics, and True Spiritual Masters. Because they are in the Eternal Light of Truth & Delight Enlightening a World of Darkness, Nescience, Blindness, Uneasiness and Falsehood!