Introduction to OpenCV. Marvin Smith

Similar documents
OpenCV Introduction. CS 231a Spring April 15th, 2016

OpenCV. OpenCV Tutorials OpenCV User Guide OpenCV API Reference. docs.opencv.org. F. Xabier Albizuri

Introduction to OpenCV

Robot Vision Systems Lecture 3: Methods for Dense Matrices in OpenCV

OpenCV. Rishabh Maheshwari Electronics Club IIT Kanpur

IMAGE PROCESSING AND OPENCV. Sakshi Sinha Harshad Sawhney

Real-time image processing and object recognition for robotics applications. Adrian Stratulat

1. Introduction to the OpenCV library

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV

Multimedia Retrieval Exercise Course 2 Basic of Image Processing by OpenCV

Laboratory of Applied Robotics

OpenCV. Basics. Department of Electrical Engineering and Computer Science

Filtering (I) Agenda. Getting to know images. Image noise. Image filters. Dr. Chang Shu. COMP 4900C Winter 2008

LAB SESSION 1 INTRODUCTION TO OPENCV

Filtering (I) Dr. Chang Shu. COMP 4900C Winter 2008

CS 376b Computer Vision

OpenCV 비디오처리 김성영교수 금오공과대학교 컴퓨터공학과

Computer and Machine Vision

Appendix II. Image processing using the OpenCV library

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Visual Computing in OpenCV Lecture 4: Sparse Matrices

Graphics Overview ECE2893. Lecture 19. ECE2893 Graphics Overview Spring / 15

PART I - A very brief introduction

Visual Computing in OpenCV Lecture 2: Dense Matrices

Image Processing (1) Basic Concepts and Introduction of OpenCV

Robot Vision Systems Lecture 4: Sparse Matrices in OpenCV

ECE 661 HW_4. Bharath Kumar Comandur J R 10/02/2012. In this exercise we develop a Harris Corner Detector to extract interest points (such as

OpenCV introduction. Mašinska vizija, 2017.

ECE 661: Homework #3

Intensive Course on Image Processing Matlab project

Lab 2. Hanz Cuevas Velásquez, Bob Fisher Advanced Vision School of Informatics, University of Edinburgh Week 3, 2018

Pointers and scanf() Steven R. Bagley

Biometrics Technology: Image Processing & Pattern Recognition (by Dr. Dickson Tong)

Chapter 6. Introduction to OpenCV

Image Processing (1) Basic Concepts and Introduction of OpenCV

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. OpenCV

Edge Detection. Dr. Mongkol Ekpanyapong

ECE 661 HW6 Report. Lu Wang 10/28/2012

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

EE795: Computer Vision and Intelligent Systems

ECE 661 HW 1. Chad Aeschliman

Solution Notes. COMP 151: Terms Test

CISC 1600 Lecture 3.1 Introduction to Processing

Name: Math 310 Fall 2012 Toews EXAM 1. The material we have covered so far has been designed to support the following learning goals:

Intro to Multimedia Retrieval Exercise Course 3 Query by Example: Color Histogram Extraction

Professor Terje Haukaas University of British Columbia, Vancouver C++ Programming

C, C++, Fortran: Basics

Computer Vision CSCI-GA Assignment 1.

Lab # 2 - ACS I Part I - DATA COMPRESSION in IMAGE PROCESSING using SVD

libtcod Documentation

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #49. Structures in C -1

CIS 580, Machine Perception, Spring 2014: Assignment 4 Due: Wednesday, April 10th, 10:30am (use turnin)

Eigen Tutorial. CS2240 Interactive Computer Graphics

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Programming and Pictures: Computational Photography and Applications to Math and Physics. GISA 2016 Session 131 Marist School Christopher Michaud

Anno accademico 2006/2007. Davide Migliore

CPSC Fall L01 Final Exam

Image processing. Reading. What is an image? Brian Curless CSE 457 Spring 2017

Image Processing CS 6640 : An Introduction to MATLAB Basics Bo Wang and Avantika Vardhan

RLL Computer Vision Code 1.0 HLL

Landmark based Registration with the Umeyama Method

Image Contour Extraction Method based on Computer Technology Li Huanliang

Comparing Different Visual Motion Detection Algorithms

Image Processing in Python

CS 315 Data Structures Fall Figure 1

Lecture 5 2D Transformation

Answers. Chapter 2. 1) Give the coordinates of the following points:

Homework 3 Eye Detection

OpenCL Implementation and Performance Verification on R-Car H3/AGL

Principles of Programming. Chapter 6: Arrays

Opening OpenCV. Junior Journal. Journal Name. Regular Paper

EXAMINATIONS 2017 TRIMESTER 2

Homework 5: Transformations in geometry

Computer Vision 2 Exercise 0. Introduction to MATLAB ( )

CSCE574 Robotics Spring 2014 Notes on Images in ROS

Image Segmentation Image Thresholds Edge-detection Edge-detection, the 1 st derivative Edge-detection, the 2 nd derivative Horizontal Edges Vertical

Effective Programming in C and UNIX Lab 6 Image Manipulation with BMP Images Due Date: Sunday April 3rd, 2011 by 11:59pm

Homework - 2. Sriram Karthik Badam. September 6, 2012

Broad field that includes low-level operations as well as complex high-level algorithms

CS103L PA4. March 25, 2018

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Designing Applications that See Lecture 4: Matlab Tutorial

Edge Detection. CSE 576 Ali Farhadi. Many slides from Steve Seitz and Larry Zitnick

Computer and Machine Vision

Lecture 4: Image Processing

What is Multigrid? They have been extended to solve a wide variety of other problems, linear and nonlinear.

Image Processing (2) Point Operations and Local Spatial Operations

OpenStax-CNX module: m :Hough Transform * Alice Xie. 2. Software Implementation of the Hough Transform

York University Faculty Science and Engineering Fall 2008

Miscellaneous Stuff That Might Be Important.

Twister: Language Reference Manual

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Variables One More (but not the last) Time with feeling

CSC-140 Assignment 5

EE640 FINAL PROJECT HEADS OR TAILS

Transcription:

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

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

Size 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 - 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.

HELLO WORLD Example Code //Loads image and displays //call by./a.out image.jpg // #include <cv.h> #include <cvaux.h> #include <highgui.h> This program will load and show an image 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 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 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 );

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 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 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

Linear Algebra 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. 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

Singular Value Decomposition 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... Example given: -11x + 2y = 0 2x + 3y = 7 2x - y = 5

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.