BLOG
Installation et permier programme avec la librairie OpenCV sur Ubuntu 13.10
Qu'est-ce que OpenCV ?
OpenCV (pour Open Computer Vision) est une bibliothèque graphique libre spécialisée dans le traitement d'images en temps réel. La bibliothèque OpenCV met à disposition de nombreuses fonctionnalités très diversifiées permettant de créer des programmes partant des données brutes pour aller jusqu'à la création d'interfaces graphiques basiques.
Installation
Via les dépots
$ sudo apt-get install libcv-dev libcvaux-dev libhighgui-dev
Via les sources
Installation des prés requis
# Système $ sudo apt-get install build-essential cmake pkg-config phyton python-dev python-numpy # Librairie Image I/O libraries: $ sudo apt-get install libjpeg62-dev libtiff4-dev libjasper-dev # Librairie GTK dev $ sudo apt-get install libgtk2.0-dev # Librairie Video I/O $ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev # Librairie video streaming $ sudo apt-get install libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
Compilation de la librairie
$ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.3/OpenCV-2.4.3.tar.bz2/download $ tar -xvf OpenCV-2.4.3.tar.bz2 $ cd ~/opencv $ mkdir build $ cd build $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. $ make $ sudo make install
Et voilà openCV est installé.
Premier programme
Créons notre premier programme pour tester openCV: helloworld.c
#include #include #includeint 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; }
Le Makefile
CFLAGS=-fPIC -g -Wall `pkg-config --cflags opencv` LIBS=`pkg-config --libs opencv` all: gcc $(CFLAGS) helloworld.c -o helloworld $(LIBS) clean: rm -rf helloworld
Y a plus qu'à tester si tout va bien 🙂
$ make $ ./helloworld
Et pour la suite, je vous conseille de faire un petit tour dans les tutauriaux d'openCV :
http://docs.opencv.org/doc/tutorials/tutorials.html
Sources
Le site officiel: opencv.org
Un article en anglais qui m'a servit de base: http://www.raben.com/book/export/html/3
Pour aller plus loin: http://www.geckogeek.fr/tutorial-opencv-isoler-et-traquer-une-couleur.html