Before we dive in body and soul in the vision by computer, let us dwell for a moment on some general considerations, and preparing our equipment.
Framework and scope of this course
Objective
This course is designed to introduce you to the fundamental concepts of computer vision. More specifically, the primary objective is to help you gain some intuition of the treatment of images and video streams, as well as various problems of artificial intelligence that are related to them.
All this is done through the acquisition of knowledge in computer science and signal processing (at the very least, how are represented the digital images and video streams in a computer…) and the basics of several mathematical tools widely used in this area (the manipulation of matrices, the morphology, the geometries discrete, projective and ĂŠpipolaire, some concepts of statistics…).
It is, to summarize, make with you an overview of the computer vision, that you will be able to develop the following in you interesting to a literature that is more specialized in the field.
Public and knowledge required
If from a theoretical point of view, the computer vision is a field that requires usually a culture of science degree, a particular effort of extension has been provided to make this tutorial accessible for readers with a baggage-mathematics pre-baccalaureate. Nevertheless, from time to time, some optional parts of the course, focusing on points that it is interesting to address, but not fundamental, may require a level of knowledge more advanced. These parties, as well as the knowledge required to follow them, you will be systematically reported.
From a technical point of view, so that the explanations are not drowned in a flood of information-essential devices, this tutorial assumes that you know how to program in C, set up your development environment, use your compiler and read the documentation in English. Links to the documentation schedule will be provided when necessary. In regards to your level of programming, the first two parts of the course C de Mathieu Nebra should be sufficient, whereas, however, in this case you have nothing against the fact to discover and acquire, from time to time, of the practices that you do not necessarily the habit.
Jump over to this page for more eyes web articles
Organization
This course is organized in the following way :
-
-
The first part discusses the preliminary concepts fundamental to the understanding of all the rest. Its chapters are written to be read in order.
-
-
The following sections address each a specific problem of computer vision. The first chapter of each part gives the formulation of a lock to be theoretical (for example : “detect moving objects on a video “, ” recognize an object in an image “, …) as well as a first naive approach to attempt to lift the latter, and the following chapters discuss various alternative approaches, to often improve the results, or to address the problem from a different angle. A priori, these parties can be read in any order.
Whenever possible, the various concepts discussed will be presented in the following way :
-
-
Formulation of the concept in the form of a lock technical or theoretical,
-
-
-
Resolution from a theoretical point of view,
-
-
-
Implementation of the solution,
-
-
Application exercises.
Presentation of OpenCV
OpenCV (Open Source Computer Vision) is a library offering a set of more than 2500 algorithms of computer vision, accessible through APIS for the languages C, C++, and Python. It is distributed under a BSD license (free) for Windows platforms, GNU/Linux, Android and MacOS.
Originally written in C 10 years ago by researchers at Intel, OpenCV is now developed, maintained, documented, and used by a community of over 40 000 active members. This is the reference library for computer vision, as well as in the world of research as that of the industry.
In order to better introduce its range and what it can do, let’s take a look at the main modules that are accessible through its API C.
-
-
core : the core functionality.
This library allows you to manipulate the basic structures, operations on matrices, draw on images, save and load data in XML files…
-
-
-
imgproc : image processing.
We enter the heart of the matter. The structures and functions of this module relate to the transformations of images, filtering, edge detection, points of interest…
-
-
-
features2d : descriptors.
This module mostly concerns the extraction of descriptors according to two common approaches (SURF and StarDetector), which we’ll cover when we look at the characterization of images.
-
-
-
objdetect : detection of objects.
This library allows to make the recognition of objects in an image using the algorithm Adaboost (Viola & Jones, 2001). We will return when we discuss learning and recognition of shapes.
-
-
-
video : processing a video stream.
These functions are used to segment and track moving objects in a video.
-
-
-
highgui : input-output and user interface.
OpenCV includes its own library high-level to open, save, and display images and video streams. It also contains a number of functions for performing graphical interfaces are very simple, but widely sufficient to test our programs.
-
-
calib3d : calibration, estimation of pose and stereovision.
This module contains functions used to reconstruct a 3D scene from images acquired with multiple cameras simultaneously.
In regards to the documentation, you’ll find everything you’ll need on this page. Note that the C API is stable. This means that it is very unlikely that anything is changed or removed in versions 2.x OpenCV, and this is the reason why I chose to use this API in this course, rather than the C++ interface, which is a little less mature.
Install and configure OpenCV
Installation
Under Windows
Under windows, the installation method depends on the environment you use to develop. Please visit this page.
If you use Microsoft Visual Studio, you have any interest in using the installer executable, as it contains the libraries compiled specifically for your IDE.
If you are using another IDE (Code::Blocks, Eclipse, etc), you might need to download the package OpenCV-2.X.Y-win-src.zip and that you build the libraries of OpenCV with CMake, by simply following the instructions of this page, which shows you how to make a video, in addition to detailed explanations.
Under GNU/Linux, Unix
Under Unix and Linux, OpenCV 2 is necessarily in the repositories of your distribution, whatever it is, version 2.
Under Ubuntu, you can simply type the following command in a terminal :
sudo apt-get install libcv-dev libcvaux-dev libhighgui-dev
Under Archlinux, it will be :
pacman -S opencv
Under The Fedora :
yum install opencv
However, if you want to compile OpenCV yourself, to get a more recent version than that of your deposits (even if it won’t make any difference to follow this tutorial), you can go on this page, and follow the directions step by step.
Under MacOS
Under MacOS, you have two options, the simple and the complicated.
By visiting this page, you will find an installer (.dmg) all ready for OpenCV 2.0 or OpenCV 1.1, which will fix everything for you. I remind you that in our case, since we are going to use the C API, OpenCV 2.0 will suffice very largely to follow this tutorial (even the 1.1 version is enough, for all of you to confess).
If you hold still to remain at the forefront, you can compile OpenCV with CMake for your machine by following the instructions on this page.
Configuration of your environment
With the large number of possibilities that you have after the environment that you use for work, it would not be relevant to you describe in detail the procedure to follow for each of them. On the other hand, here are a few reminders simple, that, subject to the fact that you know how to use your IDE, should be enough to point you in the right direction.
The generation of C programs is done in two steps : the compilation of the code and the edition of the links. To be able to use a third party library, your compiler needs to know where it can find the header files of OpenCV and the linker (linker) needs to know in which libraries are the symbols of the functions that it uses.
The configuration of your environment is neither more nor less, to tell the compiler where to find the headers, and the linker where the libraries.
Under Windows
The header files are in the sub-directory include
of the folder where OpenCV is installed. It is thus necessary to add the path of this directory in the compiler settings.
For libraries, these are in the sub-directory libs
of the same folder. It will therefore be necessary, depending on your IDE, specify the path to this sub-directory, or give the names of the files .lib (or .dll) that it contains, in the options of the linker.
If you use Microsoft Visual Studio, you can find detailed information for your IDE on this page of the documentation.
If you’re using Code::Blocks, you can follow these instructions which will show you how to configure your IDE to use opencv with pkg-config.
Under GNU/Linux and Unix
Under GNU/Linux and Unix, the header files and libraries are installed in standard locations. OpenCV is used and configured, therefore, on these BONES, strictly in the same way as all the other libraries.
If you’re using Code::Blocks, you can configure the package by following the instructions on this page.
If you compile your file manually, here is an example of compiling a program (helloworld.(c) with opencv in console :
# compilation gcc -c helloworld.c -Wall `pkg-config opencv --cflags` # Êdition des liens gcc helloworld.o -o helloworld `pkg-config opencv --libs`
If you are using CMake (the solution I prefer, personally), here is a sample file CMakeLists.txt minimalist for the same program :
# Ajustez en fonction de votre version de CMake
cmake_minimum_required (VERSION 2.8)
# Nom du projet
project (hello)
find_package (OpenCV REQUIRED)
# ExÊcutable "hello", compilÊ à  partir du fichier helloworld.c
add_executable (hello helloworld.c)
# Hello sera linkÊ avec les bibliothèques d'OpenCV
target_link_libraries (hello ${OpenCV_LIBS})
Test your installation
To test your installation and your configuration, try compiling the following program (do not launch it or seek to understand it for the moment, we will see this in the next chapter) :
#include <stdio.h>
#include <stdlib.h>
#include <opencv/highgui.h>
int main (int argc, char* argv[])
{
IplImage* img = NULL;
const char* window_title = "Hello, OpenCV!";
if (argc < 2)
{
fprintf (stderr, "usage: %s IMAGE\n", argv[0]);
return EXIT_FAILURE;
}
img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
if (img == NULL)
{
fprintf (stderr, "couldn't open image file: %s\n", argv[1]);
return EXIT_FAILURE;
}
cvNamedWindow (window_title, CV_WINDOW_AUTOSIZE);
cvShowImage (window_title, img);
cvWaitKey(0);
cvDestroyAllWindows();
cvReleaseImage(&img);
return EXIT_SUCCESS;
}
If your compiler doesn’t send you roses, you’ve won!