Digital Image Processing Using Opencv Library

You might also like

Download as odp, pdf, or txt
Download as odp, pdf, or txt
You are on page 1of 22

Digital Audio and Video Processing

I348 - Digital Audio and Video Processing

Digital image processing using OpenCV


library

Margus Ernits
Estonian IT College
1

Short overwiev

Introduction to Image Processing

OpenCV

C++ crash course

Simple programs in C++ and OpenCV

Homework and grading

Digital image processing


Image

processing

Picture as input

Algorithm

Output is a picture, measurement data etc

Algoritm

Picture

Program

Picture
Margus Ernits
3

Digital image processing

Output can be data like size or color of object area

Algoritm

Picture

Program

Area or size or other


attribs

Area of Object

Digital image processing

Output can represent object from picture.

Algoritm

Picture
(speculation)

Algorithm

Object description
(colour, area, contours
etc)
Description

Processing generally

Image processing programs

Receive picture from file, camera, network etc

Digitalized and filtered

Process > Output

Image Source

Digitalizer/filter/converter
Image processing algorithm

Output
6

Modularity

Methods used for image receiving from camera is


not related to image format;

Good image processing programs should able to


process images from different format;

Just use OpenCV or some other library to deal


with formats and cameras.

C++
Test Your C++ knowledge!
Test will be not graded but You will receive some
feedback!

Do not write Your name on test

Find all compile errors in the code given

Find all logic error in the code

Write short summary about Your findings

Pildittlus OpenCV abil

Erinevaid pildittlusteeke on palju


http://www.cs.cmu.edu/~cil/v-source.html

Meie peatume OpenCV teegil


http://en.wikipedia.org/wiki/OpenCV
OpenCV - algselt arendati Intel poolt
Kaitstud BSD litsentsiga.

Ksimus lipilasele Mida annab BSD litsents?


9

Installing OpenCV in Ubuntu 12.04


sudo apt-get update && sudo apt-get upgrade
sudo apt-get install libopencv-dev
sudo apt-get install libopencv-legacy-dev
sudo apt-get install libcv-dev libhighgui-dev
sudo apt-get install libcv2.3 libcvaux2.3

10

Sample program

Install version control system subversion


sudo apt-get install subversion

Checkout tutorial from robot.itcollege.ee


svn co https://robot.itcollege.ee/svn/marcus/digital_image_processing/

Open simple_main.cpp and read the content of file.

11

Compiling OpenCV program

Compiling OpenCV program using pkg-config


g++ -o main.bin main_simple.cpp $(pkg-config
opencv --cflags --libs)

12

#include directives

Open file main.cpp

cv - Main OpenCV functions.

cvaux - Auxiliary (experimental) OpenCV


functions.

cxcore - Data structures and linear algebra


support.

highgui - GUI functions.

13

main.cpp

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

14

main.cpp

Loading the Image


IplImage* img = 0;
img=cvLoadImage(argv[1]);
if(!img){
printf("Could not load image file: %s\n",argv[1]);
exit(0);
}

cvLoadImage() funktsioon pildi laadimiseks


15

CvLoadImage - supported formats

Windows bitmap - BMP, DIB;

JPEG;

Portable Network Graphics - PNG;

Portable image format - PBM, PGM, PPM;

Sun rastergraphics - SR, RAS;

TIFF files - TIFF, TIF.

16

/* Creating the Main Window - cvNamedWindow */


cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
/* mode window */
cvMoveWindow("mainWin", 100, 100);
/* Add Your Code here */
/* Display Image */
cvShowImage("mainWin", img );
/* Ootame klahvivajutust */
cvWaitKey(0);
/* vabastame mlu */
cvReleaseImage(&img );
17

Image Data

// get the image data


height = img->height;
= img->width;

step

= img->widthStep;

ne
ls

channels = img->nChannels;
data

width

height

width

ch
an

= (uchar *)img->imageData;

printf("Processing a %dx%d image with %d


channels\n",height,width,channels);

widthStep; /* HomeWork find out what is widthStep */

18

Accessing picture data points

for rida=0..height-1

for veerg=0...width-1
-

for kanal=0..channels-1

data[rida*step+veerg*channels+kanal]
c
ha
nn
els

width

height
19

Processing power

Needed processing power varies depending on


task

8Bit microcontroller can't be used for image


processing proposes

60 MHz ARM7 is OK for some basic tasks

MMX(2+) vector register capable processor is needed


for real world tasks

20

Questions?

Next Question?

21

Thank You!

...
22

You might also like