Introduction to OpenCV

Slides:



Advertisements
Similar presentations
WORKCENTER 7755 – Walk-Up Training COPY Cheat Sheets.
Advertisements

Working with Profiles in IX1D v 3 – A Tutorial © 2006 Interpex Limited All rights reserved Version 1.0.
Mobile Development Introduction to Visual Studio Development Rob Miles Department of Computer Science.
Tutorial on Matlab and OpenCV Rui Ma TA of CMPT 414 May 14, 2013 Office hours: Fridays 11:00-12:00, CSIL TA Office 1 (ASB 9838)
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Matlab Tutorial. Session 1 Basics, Filters, Color Space, Derivatives, Pyramids, Optical Flow Gonzalo Vaca-Castano.
An Introduction to C Adam Gleitman – IAP 2014.
Photoshop Lab colorspace A quick and easy 26 step process for enhancing your photos.
Lab6 – Debug Assembly Language Lab
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
Computer Science 1620 C++ - Basics. #include using namespace std; int main() { return 0; } A very basic C++ Program. When writing your first programs,
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
L.
Image Processing.  a typical image is simply a 2D array of color or gray values  i.e., a texture  image processing takes as input an image and outputs.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 3 Variables, Calculations, and Colors Starting Out with Games.
XP Tutorial 7 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Working with Graphics Tutorial 7.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Intel Do-It-Yourself Challenge OpenCV
OPENCV TUTORIAL OpenCV Windows 7 Microsoft Visual C++ Express 2010.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Introduction to Python
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
L. Akshay Masare Piyush Awasthi IMAGE PROCESSING AND OPENCV.
Input, Output, and Processing
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering yahoo. com Spring.
AdeptSight Image Processing Tools Lee Haney January 21, 2010.
Intermediate 2 Software Development Process. Software You should already know that any computer system is made up of hardware and software. The term hardware.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Introduction to Image processing using processing.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Design Studies 20 ‘Show Off’ Project How to make a computer monitor In Google Sketchup By: Liam Jack.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
© Execview Ltd 2015: all rights reserved Execview Scorecard Training/Reference Guide 2013 Key functions guide for Scorecard administrators.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
ENGINEERING 1D04 Tutorial 4. What are we doing today? Focus Functions Scope of Variables Returning Values Objects Graphics library Aliasing Events Mouse.
Sound and more Animations
Reading and Writing Image Files
Development Environment
Graphical Output Basic Images.
MOM! Phineas and Ferb are … Aims:
Pixels, Colors and Shapes
CSC391/691 Intro to OpenCV Dr. Rongzhong Li Fall 2016
Other Kinds of Arrays Chapter 11
Programming with OpenGL Part 2: Complete Programs
Chapter 5 Working with Images
More programming with "Processing"
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Chapter 10 Algorithms.
Animation Translation.
Getting Started With Coding
Presentation transcript:

Introduction to OpenCV Marvin Smith

Introduction OpenCV is an Image Processing library created by Intel and maintained by Willow Garage. Available for C, C++, and Python Newest update is version 2.2 Open Source and free Easy to use and install

Installation Instructions For Mac OS X. Simply install Mac Ports then type sudo port install opencv Do not use synaptic on Linux to install OpenCV. It is version 1.2. For Linux and Windows, follow the installation guide at http://opencv.willowgarage.com/wiki/InstallGuide Linux users can come to me for help. I have built it on Ubuntu dozens of times. I have built it successfully on Windows once. Make sure to read the beginning as it gives you precise commands to install ffmpeg, libavformat-dev, libswscale-dev, and other required libraries. Follow instructions exactly!!!!!

BASIC OPENCV STRUCTURES Point, Point2f - 2D Point Size - 2D size structure Rect - 2D rectangle object RotatedRect - Rect object with angle Mat - image object

Point Math operators, you may use 2D Point Object int x, y; Functions Point operator + Point operator += Point operator - Point operator -= Point operator * Point operator *= bool operator == bool operator != double norm 2D Point Object int x, y; Functions Point.dot(<Point>) - computes dot product Point.inside(<Rect>) - returns true if point is inside

Size RECT 2D Size Structure int width, height; Functions Point.area() - returns (width * height) RECT 2D Rectangle Structure int x, y, width, height; Functions Point.tl() - return top left point Point.br() - return bottom right point

cv::Mat The primary data structure in OpenCV is the Mat object. It stores images and their components. Main items rows, cols - length and width(int) channels - 1: grayscale, 3: BGR depth: CV_<depth>C<num chan> See the manuals for more information

cv::Mat Functions Mat.at<datatype>(row, col)[channel] - returns pointer to image location Mat.channels() - returns the number of channels Mat.clone() - returns a deep copy of the image Mat.create( rows, cols, TYPE) - re-allocates new memory to matrix Mat.cross(<Mat>) - computes cross product of two matricies Mat.depth() - returns data type of matrix Mat.dot(<Mat>) - computes the dot product of two matrices

cv::Mat Functions Iterator Usage Mat(Range(xmin,xmax),Range(ymin,ymax)) - returns sub image Mat.type() - returns the TYPE of a matrix Iterator Usage Mat.begin() - moves Mat iterator to beginning of image Mat.end() - moves Mat iterator to end of image

Image TYPES The TYPE is a very important aspect of OpenCV Represented as CV_<Datatype>C<# Channels> Example Datatypes/ Depths

Pixeltypes PixelTypes shows how the image is represented in data BGR - The default color of imread(). Normal 3 channel color HSV - Hue is color, Saturation is amount, Value is lightness. 3 channels GRAYSCALE - Gray values, Single channel OpenCV requires that images be in BGR or Grayscale in order to be shown or saved. Otherwise, undesirable effects may appear.

This program will load and show an image HELLO WORLD Example Code This program will load and show an image //Loads image and displays //call by ./a.out image.jpg // #include <cv.h> #include <cvaux.h> #include <highgui.h> using namespace cv; int main(int argc, char* argv[ ]){ Mat image = imread(argv[1]); namedWindow(“Sample Window”); imshow(“Sample Window”,image); waitKey(0); return 0; }

Starting Out in OpenCV OpenCV uses the cv namespace. cv::Mat object replaces the original C standard IplImage and CvMat classes. All original functions and classes of the C standard OpenCV components in the Bradski book are still available and current. However you will need to read that book for it. namedWindow is used for viewing images. See my manual for instructions on calling it. In general, default string as input with original image size set. Else, use string as input name and 0 for adjustable size.

Image I/O Examples //Read an image Mat image = imread( <string>, <0 -gray, 1 -BGR>) //Note 1 is default //Write an image imwrite( <string filename> , image ); //Create window for output namedWindow( <window name> ); //Output image to window imshow( <window name> , <image Mat to show> ); //pause program for input key = waitKey( 0 ); OpenCV provides simple and useful ways to read and write images. Note that there are many extra options to these commands which are available on the wiki. waitKey( int x ) has two main features. if x > 0, then waitKey will wait x milliseconds if x = 0, then waitKey will not move until key is pressed

DRAWING STUFF Sometimes it is necessary to draw stuff onto the image. Instead of using complicated functions, why not just call a simple function? Here are some simple examples... void circle(image, Point(x,y),int rad, CV_BGR(b,g,r), int thickness=1) void ellipse(image, RotatedRect box, CV_BGR(b,g,r), int thickness=1) void line(image, Point(x,y), Point(x,y), CV_BGR(b,g,r), int thickness= 1) void rectangle(img, Point(x,y), Point(x,y), CV_BGR(b,g,r), int thickness) NOTE: negative thickness will fill in the rectangle MORE... http://opencv.willowgarage.com/documentation/cpp/core_drawing_functions.html

Drawing stuff

Using the Mouse OpenCV allows you to use the mouse to interact with the screen. Note that this feature is from OpenCV 1.0 and is compatible with Mat objects. This program allows you to draw dots on the image.

USING THE MOUSE

Converting colorspaces cvtColor( image, image, code) Codes CV_<colorspace>2<colorspace> Examples CV_BGR2GRAY CV_BGR2HSV CV_BGR2LUV

Image Normalization normalize(imagein, imageout, low, high, method); Image normalization is the process of stretching the range of an image from [a, b] to [c, d]. This is incredibly important for visualization because if the image is beyond [0,255] it will cause truncation or unsightly effects.

Thresholding threshold( image, image, thresh, maxVal, CODE); CODE - this is the method of thresholding. Different actions will be taken depending on this code.

Edge Detection Sobel Edge Detection Scharr Edge Detection void cv::Sobel(image in, image out, CV_DEPTH, dx, dy); Scharr Edge Detection void cv::Scharr(image in, image out, CV_DEPTH, dx, dy); Laplacian Edge Detection void cv::Laplacian( image in, image out, CV_DEPTH);

Image Smoothing Original Gaussian Blur Median Blur Image smoothing is used to reduce the the sharpness of edges and detail in an image. OpenCV includes most of the commonly used methods. void GaussianBlur(imagein, imageout, Size ksize, sig); Note that there are more options, however this should keep things simple void medianBlur (imagein, imageout, Size ksize); Other functions include generic convolution, separable convolution, dilate, and erode. Original Gaussian Blur Median Blur

STOP! This is not relevent until the last part of the class. Beware!

Linear Algebra Operators given: Mat image; image.inv(); //inverse image.t(); //transpose image.clone(); //creates deep copy image.diag(int d=0) //returns diagonal image.mul(mat, double); //performs elementwise multiplication. image.cross(mat); //performs cross product image.dot(mat); //performs dot product image.eye(); //converts mat to identity matrix OpenCV contains many useful and simple functions for applying linear algebra on images. Most major operators are allowed. operator * performs matrix multiplication, NOT elementwise multiplication.

Singular Value Decomposition Example given: -11x + 2y = 0 2x + 3y = 7 2x - y = 5 Singular Value Decomposition is a vital part of any computer vision based system. Luckily, OpenCV makes this a trivial task. To solve a least-squares problem, simply call the solve command. bool solve(src1, src2, dst, int flags); Usually, src1 is A, src2 is b, and dst is x. Remember flags is method... DECOMP_LU - Fast but cannot solve over- determined systems. DECOMP_SVD - SVD, can solve just about anything Others available, but stick to the basics...

SVD Results Using OpenCV Using GNU Octave

Principle Component Analysis Since you will need to learn this, I will include it. Although you will undoubtably will have to create your own PCA program, OpenCV covers it very nicely. PCA( Mat data, Mat mean, int FLAG, int numcomp=0) FLAG: PCA_DATA_AS_ROW / PCA_DATA_AS_COL numcomp is the k value, 0 means all values retained in general, just pass the vectors into data and the mean will be returned. PCA.project( Mat vector) projects the vector into the built eigenspace and returns the result PCA.backproject( Mat vector) reconstructs the vector from the principle component subspace

Important Tips Remember that images are read from file as 8-bit unsigned integers. In order to do complicated math operations, convert to 32-bit floating point type. Then convert back to write to file. Always remember that rows is your y coordinate and that cols is your x coordinate. Size objects are called X,Y while images are referenced row, col. There are many subtle things that will ruin good code.