What Do I Need?
- [tool]Any Dedicated or Virtual Server[/tool]
- [tool]Ubuntu[/tool]
- [tool]OpenCV[/tool]
- [tool]Terminal[/tool]
What is OpenCV?
OpenCV is one of the most exciting releases of 2020. Originally launched in 1999, it’s a library of programming functions mainly aimed at real-time computer vision. The library is cross-platform and free for any use, academic, research, and commercial.
- [stepName]Install OpenCV 4 Dependencies[/stepName][step]
- [howToDirection]Make sure that your Ubuntu install is up to date:
sudo apt-get upgrade
sudo apt-get update
- [howToDirection]Make sure that your Ubuntu install is up to date:
[/howToDirection]
- [howToDirection]Install developer tools:
sudo apt-get install build-essential cmake unzip pkg-config
[stepImage]
[/stepImage]
- [howToDirection]Install developer tools:
[/howToDirection]
- [howToDirection]Next, install the required image and video input, output, I/O, libraries. These libraries enable the loading of images from disk as well as reading video files:
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
[stepImage]
[/stepImage]
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
[stepImage]
[/stepImage]
sudo apt-get install libxvidcore-dev libx264-dev
[stepImage]
[/stepImage]
- [howToDirection]Next, install the required image and video input, output, I/O, libraries. These libraries enable the loading of images from disk as well as reading video files:
[/howToDirection]
- [howToDirection]We have to install GTK for our graphical user interface backend:
sudo apt-get install libgtk-3-dev
[stepImage]
[/stepImage]
- [howToDirection]We have to install GTK for our graphical user interface backend:
[/howToDirection]
- [howToDirection]This is followed by installing two packages that contain the mathematical optimizations for OpenCV:
sudo apt-get install libatlas-base-dev gfortran
[stepImage]
[/stepImage]
- [howToDirection]This is followed by installing two packages that contain the mathematical optimizations for OpenCV:
[/howToDirection]
- [howToDirection]And finally, let’s install the necessary Python 3 development headers:
sudo apt-get install python3-dev
[stepImage]
[/stepImage]
- [howToDirection]And finally, let’s install the necessary Python 3 development headers:
[/howToDirection]
[/step]
- [stepName]Download OpenCV 4[/stepName][step]
- [howToDirection]With the prerequisites now installed we can move on to downloading and installing OpenCV 4:
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip
[stepImage]
[/stepImage]
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.0.zip
[stepImage]
[/stepImage]
- [howToDirection]With the prerequisites now installed we can move on to downloading and installing OpenCV 4:
[/howToDirection]
- [howToDirection]Now, let’s unzip the compressed folders that we’ve just downloaded:
unzip opencv.zip
unzip opencv_contrib.zip
- [howToDirection]Now, let’s unzip the compressed folders that we’ve just downloaded:
[/howToDirection]
- [howToDirection]It’s also recommended to rename the uncompressed directories:
mv opencv-4.0.0 opencv
mv opencv_contrib-4.0.0 opencv_contrib
- [howToDirection]It’s also recommended to rename the uncompressed directories:
[/howToDirection]
[/step]
- [stepName]Install Pip[/stepName][step]
Now we’re going to install an awesome package management system, called Pip. It’s used to install and manage software packages in Python.
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
[stepImage]
[/step]
- [stepName]Install OpenCV using Pip[/stepName][step]
Normally it’d be recommended to install OpenCV on Ubuntu into a virtual environment with Pip; however, for this demonstration, we’re keeping it ‘simple stupid’:
sudo pip install opencv-contrib-python
[stepImage]
[/step]
Next Steps
If you’re working in a research or production environment I recommend installing OpenCV into a virtual environment. Doing this offers huge benefits; for example, the ability to develop and run multiple projects on your system with isolated packages, many with version dependencies, without having to compromise your system integrity. It’s also super flexible, allowing you to add and remove virtual environments freely, at your own discretion. Bottom line, virtual environments are the best practice for Python development.
In order to create and manage Python virtual environments you’ll need to install virtualenv and virtualenvwrapper:
        sudo pip install virtualenv virtualenvwrapper
        sudo rm -rf ~/get-pip.py ~/.cache/pip
Conclusion
Computer vision is potentially one of the most important research and development areas of the twenty-first century. The applications are untold and practically cover all facets of society, from document scanning and object tracking to facial recognition and surveillance. OpenCV includes deep learning algorithms that make recognizing the world around you quick and efficient.
If you’re interested in learning to apply facial or vehicle number plate recognition to video streams, building a complete deep learning pipeline for image classification, or simply want to experiment with your Raspberry Pi to create an autonomous camera monitoring system, you’ll need to learn OpenCV.
Learning this bleed-edge technology used to be very hard to get into. The documentation was tough to navigate and largely arcane. Plus, most of the books required a near doctorate level understanding of math. Now, that’s no longer necessary. It’s become infinitely easier over the years; more recently, with incredible resources like PyImageSearch and OpenCV readily available online, including large cooperative and helpful communities.
- Want suggestions about Best dedicated servers hosting? Click here and read more.
