Lab - System Setup

Computer Vision (CSCI 4220U)

Faisal Qureshi

Faculty of Science, UOIT

http://vclab.science.uoit.ca


Objectives

In this course we will use Python with OpenCV. But do read on.

The objective of this lab is for you to setup your computer for computer vision system development.

Some Context

Matlab

In the past the easiest way to experiment with computer vision was through Matlab. Matlab is available for Windows, Linux and OSX. If your system doesn't already come with Matlab or if you don't find Matlab on Landisk then most likely you will not be able to install Matlab. Matlab is a fairly costly software package, and I don't suggest that you buy a license of Matlab for this course.

So if you have Matlab, good; otherwise, don't worry about it for now.

Octave

GNU Octave is an free open-source clone of Matlab. You can get it from here https://www.gnu.org/software/octave/download.html. You may find it useful.

Python

It is now possible to use Python for rapid computer vision system development and experimentation in lieu of a 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 comptuer vision system development. It is easier to setup your system to use Python for computer vision than it sounds. Your best bet is to download Enthought Canopy Python distribution (with academic license). This distribution come pre-loaded with everything that you will need to rapidly develop computer vision systems. Enthought Canopy Python distribution is available for a number of platforms, see https://www.enthought.com/products/canopy/. Another powerful Python distribution is Anaconda.

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.

This Course

In this course we will use Python with OpenCV. For your project, you are free to use any of the above choices.

Installing Python

You can use any of the following approaches to install Python + NumPy + SciPy + OpenCV + Matplotlib + Notebook on your machine.

Don't forget to also install iPython Notebook.

Testing your installation

This program loads an image test.jpg from the current directory and displays it in a window. Press Esc key to dismiss the window. This is how you will be writing python computer vision applications.

hellocv.py

import cv2

im = cv2.imread('test.jpg')
cv2.imshow('Image', im)
print('Press Esc to exit')
cv2.waitKey(0)

Using Python Notebook

The IPython Notebook provides an interactive computational environment that combines code execution with plotting and rich media. In the absence of full-fledged Matlab (or Octave), Python Notebook's is an excellent way to experiment with Python code.

Check out IPython Notebook documentation for information about how to install it on your system. See here.

Tasks

You should complete the following tasks:

  1. Write a python program that can display the image
> python loadimg test.png
Press q to exit
  1. Write a python program that can capture images from your laptop camera:
> python loadcam
Press q to exit
  1. Write a python program that can play a movie
> python loadmov traffic-short.mp4
Press q to exit
  1. Load an image and convert it to grayscale
> python loadimg --gray test.png
Press q to exit
  1. Load an image and display a sub-image. Say the width and height of the input image is \(w\) and \(h\), respectively. Then we can define a sub-image using: left (\(l\)), bottom (\(b\)), right (\(r\)), and top (\(t\)) coordinates. Here, \(0 <= l,r < w\) and \(0 <= b,t < h\). Furthermore, \(l<r\) and \(b<t\).
> python loadimage --crop 10 10 30 20 test.png
Press q to exit
  1. A color image has more than one channels. We often store color images using three (Red-0, Green-1, Blue-2) channels. The following program will select a particular channel from the image.
> python loadimage --channel 0 test.jpg
Press q to exit

Some comments

These programs will use python and opencv to implement the required functionality. I suggest you use argparse for processing commandline arguments. Each program simply shows a window that will show frame(s) from the loaded image, the video or the camera.

Datasets

iPython Notebooks

Check out the following iPython notebooks.

What to submit

Submit loadimg.py, loadcam.py and loadmov.py files via Blackboard.