No description has been provided for this image

OpenCV + Python setup¶

Faisal Qureshi
Professor
Faculty of Science
Ontario Tech University
Oshawa ON Canada
http://vclab.science.ontariotechu.ca

Copyright information¶

© Faisal Qureshi

License¶

Creative Commons Licence
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Outline¶

  • Python OpenCV programming environmentt
  • Image loading and display
  • Movie loading and display

Python¶

It is now possible to use Python for rapid computer vision system development and experimentation in lieu of a software package, such as Matlab. You will need to install a number of python scientific packages - Numpy, Scipy, Matplotlib, Image, Notebook - plus rely upon OpenCV python bindings to use Python for computur vision system development. It is easier to setup your system to use Python for computer vision than it sounds.

Installation¶

Linux (Preferred)¶

The following steps assumes that you are using Ubuntu linux distribution. To see if you have Python3 installed, use the following command:

Setting up Python3 and pip¶

$ python3 --version

If Python3 is not found, you can install it as follows:

$ sudo apt-get update
$ sudo apt-get install python3

Next you will need pip3 to install the packages needed for this course. You can see if pip3 is already installed by using the following command:

$ command -v pip3

If pip3 is not installed, you can install it using the following command:

$ sudo apt-get install python3-pip

In any case, it is a good idea to upgrade pip3 to the latest version. This can be done using the following command:

$ python3 -m pip install --upgrade pip

Installing Python packages¶

Now that pip3 is installed, you need to install the packages needed for this course. You can do so by using the requirements.txt file available here. You will use the following command to install the packages:

$ pip3 install -r requirements.txt

You are set.

Problem installing from requirements.txt¶

If you have trouble installing packages from requirements.txt file, you can always install packages one by one. For example, the following command will install numpy

$ pip3 install numpy
Aside¶

It is always a good idea to install Python packages in a separate virtual environment. Check out these Python developments notes for more details.

Windows (if you must)¶

Your best bet is to use Anaconda Python Distribution https://www.anaconda.com. Follow the instructions provided here to set up the compute environment as needed.

OSX (if you must)¶

I prefer to use Homebrew package manager for OSX. I use homebrew to install Python3 and pip3. Once these are installed, use pip3 to install the packages that you need to set up the compute environment.

Tasks¶

Assuming that your python+opencv installation completed without any errors, test your installation by completing the exercises in the following Jupyter notebook.

  1. Create a folder lab0
  2. Copy 00-setup-workbook.ipynb to this folder
  3. Within this folder run jupter lab. At this point a browser window should open up pointing to http://localhost:8888/lab URL.
  4. Complete the exercises in 00-setup-workbook.ipynb notebook.
  5. Save the notebook as an HTML and submit.

Other useful software packages¶

SimpleCV¶

You may also want to look at http://simplecv.org/. Although it is quite limited.

C/C++ with OpenCV and VLFeat¶

A time will come when you will find that your programs are too slow. You will be amazed how large images and videos actually are. These are many orders of magnitude larger than text files. At that time Python, Matlab or Octave will not serve your purpose. You will have to rely upon something more efficient, such as C/C++, for example. In order to use C/C++ for computer vision system development, you will need to rely upon existing computer vision and image processing libraries, such as OpenCV or VLFeat. It is best if you set up your system to use one of these libraries. This will especially be useful for your course project.

No description has been provided for this image
In [ ]: