Introduction to OpenCV

Similar documents
OpenCV. Basics. Department of Electrical Engineering and Computer Science

1. Introduction to the OpenCV library

Introduction to OpenCV. Marvin Smith

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

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

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV

OpenCV. Rishabh Maheshwari Electronics Club IIT Kanpur

Multimedia Retrieval Exercise Course 2 Basic of Image Processing by OpenCV

GeoInt Accelerator Platform to start developing with GPUs GPU access, GPU-accelerated apps and libraries Register to learn more:

Appendix II. Image processing using the OpenCV library

Homework 3 Eye Detection

OpenCV introduction. Mašinska vizija, 2017.

Interaction Technology

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

CSCE574 Robotics Spring 2014 Notes on Images in ROS

Colorado School of Mines. Computer Vision. Professor William Hoff Dept of Electrical Engineering &Computer Science.

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

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

IMAGE PROCESSING AND OPENCV. Sakshi Sinha Harshad Sawhney

Image Processing (1) Basic Concepts and Introduction of OpenCV

Visual Computing in OpenCV Lecture 2: Dense Matrices

ECE661 Computer Vision : HW2

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

ECE 661: Homework #3

ECE 661 HW 1. Chad Aeschliman

How to declare an array in C?

LAB SESSION 1 INTRODUCTION TO OPENCV

PART I - A very brief introduction

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

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

Chapter 6. Introduction to OpenCV

#include <stdlib.h> #include <stdio.h> #include "opencv2/opencv.hpp" #include <vector> #include <cmath> #include <pthread.h> #include <unistd.

CSCI 512 / EENG 512 Computer Vision Spring Lab 6. February 17, 2016

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

Colorado School of Mines. Computer Vision. Professor William Hoff Dept of Electrical Engineering &Computer Science.

Object Move Controlling in Game Implementation Using OpenCV

Laboratory of Applied Robotics

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

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

x = 12 x = 12 1x = 16

1. (10 pts) Order the following three images by how much memory they occupy:

The MatriCs. Reloaded. A linear algebra-specific language for the budding C enthusiast. Short name: MaC Extension:.neo

stanford hci group / cs377s Lecture 8: OpenCV Dan Maynes-Aminzade Designing Applications that See

ECE661 Computer Vision : HW1

Русинович Андрей Сергеевич

Practical Verification for Edge AI use and Effort for Functional Improvement

Robot Vision Systems Lecture 8: Python wrappers in OpenCV

Multimedia Retrieval Exercise Course 10 Bag of Visual Words and Support Vector Machine

Comparing Different Visual Motion Detection Algorithms

An Implementation on Object Move Detection Using OpenCV

Implementation of Hand Detection based Techniques for Human Computer Interaction

Robot Vision Systems Lecture 4: Sparse Matrices in OpenCV

XPM 2D Transformations Week 2, Lecture 3

PieNum Language Reference Manual

Visual Computing in OpenCV Lecture 4: Sparse Matrices

Introduction to Processing

Image Processing (1) Basic Concepts and Introduction of OpenCV

XPM 2D Transformations Week 2, Lecture 3

Assignment 1 - Use OpenCV for camera calibration

Object Oriented Programming using C++

0_PreCNotes17 18.notebook May 16, Chapter 12

Input Nodes. Surface Input. Surface Input Nodal Motion Nodal Displacement Instance Generator Light Flocking

Name: SID: LAB Section: Lab 6 - Part 1: Pixels and Triangle Rasterization

CS 432 Interactive Computer Graphics

Hoang Nguyen Steven Martin ECE 479: Intelligent Robotics II Human Facial Emotion Recognition Using OpenCV and Microsoft Kinect Final Project Report

A hybrid opto-inertial Tracking System Prototype

In this lesson you are going to create a drawing program similar to Windows Paint. 1. Start with a new project and remove the default cat sprite.

Image segmentation via graph cuts with connectivity priors

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Linear transformations Affine transformations Transformations in 3D. Graphics 2009/2010, period 1. Lecture 5: linear and affine transformations

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

CP SC 4040/6040 Computer Graphics Images. Joshua Levine

CMAT Language - Language Reference Manual COMS 4115

OhioState::OpenGLPanel. OpenGL and Windows. Public methods. OpenGLPanel : Forms::Control

A Tutorial on VLFeat

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

MATLAB Tutorial III Variables, Files, Advanced Plotting

Getting started with Java

RLL Computer Vision Code 1.0 HLL

Deep OpenCV. Intel Delta 8 course

Creating a nice GUI. OpenGL and Windows. Note: VS 2003 shown. Create a new Project

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Instruction for IVR interface

Real Time Data Plotting

DH2323 DGI13. Lab 2 Raytracing

tablica: array: dane_liczbowe

ANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013

Intel RealSense Depth Module D400 Series Custom Calibration

libtcod Documentation

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

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

Image processing with OpenCV. Python

Scientific Programming in C X. More features & Fortran interface

CS 101 Randomness. Lecture 21

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

We assume that the user has basic knowledge of C# and is able to create a new C# project.

1 Preview. Dr. Scott Gordon Computer Science Dept. CSUS. Virtual Cameras, Viewing Transformations: CSc-155 Advanced Computer Graphics

How to Accelerate OpenCV Applications with the Zynq-7000 All Programmable SoC using Vivado HLS Video Libraries August 28, 2013

Benchmarking of Vision-Based Prototyping and Testing Tools

The Application Stage. The Game Loop, Resource Management and Renderer Design

Transcription:

Introduction to OpenCV Stefan Holzer, David Joseph Tan Chair for Computer Aided Medical Procedures Technische Universität München Germany

Introduction to OpenCV Where to get OpenCV? <http://opencv.willowgarage.com/wiki/> INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 2

Introduction to OpenCV Where to get OpenCV? <http://docs.opencv.org/trunk/opencv_cheatsheet.pdf> INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 3

Introduction to OpenCV #include and namespace Include These are the most common include files are: cv.h highgui.h #include <opencv/cv.h> #include <opencv/highgui.h> Namespace All OpenCV functions use the namespace: cv using namespace cv; cv::functionname(); INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 4

Images and Matrices How to use them? Images and Matrices are represented by the same type. Rows Columns Mat Type cv::mat image(240, 320, CV_8UC3); Columns 320 Mat Type CV_8UC3 Rows 240 8U Datatype: 8U, 8S 6U, 6S, 32F, 64F C3 Number of Channels: C, C2, C3, C4 Default: C INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan

Images and Matrices How to initialize? Matrix initialized as Identity cv::mat I88 = cv::mat::eye(8, 8, CV_32F); INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 6

Images and Matrices How to initialize? 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Matrix initialized with zeroes cv::mat D88 = cv::mat::zeros(8, 8, CV_32F); INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 7

Images and Matrices How to initialize? Matrix initialized with ones cv::mat D88 = cv::mat::ones(8, 8, CV_32F); INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 8

Images and Matrices How to initialize? Matrix initialized with a constant cv::mat A88(8, 8, CV_32F); A88 = cv::scalar(); cv::mat B88(8, 8, CV_32F, cv::scalar()); cv::mat C88 = cv::mat::ones(8, 8, CV_32F) *.; cv::mat D88 = cv::mat::zeros(8, 8, CV_32F) +.; INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 9

Images and Matrices How to initialize? 0 2 3 4 6 8 9 0 2 3 4 6 7 8 9 20 2 22 24 2 26 27 28 29 30 32 33 34 3 36 37 38 40 4 42 43 44 4 46 48 49 0 2 3 4 6 7 8 9 60 6 62 7 23 3 39 47 63 Matrix initialized with specific values float E88data[] = {0,, 2, 3,..., 63}; cv::mat E88 = cv::mat(8, 8, CV_32F, E88data).clone(); INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 0

Images and Matrices How to access the elements? 0 2 3 4 6 8 9 0 2 3 4 6 7 8 9 20 2 22 24 2 26 27 28 29 30 32 33 34 3 36 37 38 40 4 42 43 44 4 46 48 49 0 2 3 4 6 7 8 9 60 6 62 7 23 3 39 47 63 To access an element: im.at<float>(idx); im.at<float>(row,col); Depends on the Matrix Data Type For example: im.at<float>(26) = ; im.at<float>(3,2) = ; INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan

Images and Matrices How to access the elements? 0 2 3 4 6 8 9 0 2 3 4 6 7 8 9 20 2 22 24 2 26 27 28 29 30 32 33 34 3 36 37 38 40 4 42 43 44 4 46 48 49 0 2 3 4 6 7 8 9 60 6 62 7 23 3 39 47 63 To access a submatrix: im.row(i); im.col(i); im.rowrange(cv::range(r0,rn)); im.colrange(cv::range(c0,cn)); im(cv::range(r0,rn),cv::range(c0,cn)); for rows r 0,..., r n- and for columns c 0,..., c n- For example: im(cv::range(2,),cv::range(,6)); How do you get the 3x3 rotation matrix R and 3x translation matrix T from a 4x4 extrinsic matrix E44? R = E44(cv::Range(0,3),cv::Range(0,3)); T = E44(cv::Range(0,3),cv::Range(3,4)); E44 = R T 0 0 0 Copy by Address How to copy by value?.clone() INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 2

Images and Matrices Scalar Operators and Matrix Operators Scalar Operator cv::mat im2 = im + ; 8 3 Matrix Operator cv::mat mat = mat + mat2; 8 3 cv::mat im2 = im - ; 8 3 cv::mat mat = mat - mat2; 8 3 cv::mat im2 = im * ; 8 40 cv::mat mat = mat * mat2; 8-0 37 3 0 INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 3

Matrices Simple Math Operators Matrix Operator Matrix Transpose mat.t() 2 3 T 4 7 cv::mat mat = mat + mat2; 8 3 4 6 7 8 9 2 8 3 6 9 cv::mat mat = mat - mat2; 8 3-2 3 2-0 Matrix Inverse mat.inv() 2 2-4 cv::mat mat = mat * mat2; 8-0 37 0 0 0 0 3 0 INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 4

Images How to input or output an image? Load Image Read image from disk. cv::imread(filename,0/); Save Image Write image to disk. cv::imwrite(filename,im); 0: read as grayscale image : read as color image Visualize Image Show image in a window. cv::imshow(title,im); Note: if CV_32FC, the gray value range is 0 to. Everything above is white and everything below 0 is black. Waitkey Waits n milliseconds for user input. cv::waitkey(n); If n == -, it waits forever. Note: There must be a waitkey to show the image. INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan

Images Simple Image Operations Convert Color cv::cvtcolor(colorim, grayim, CV_BGR2GRAY); Smoothing cv::gaussianblur(src, dst, ksize, sigma); cv::size(width, height) Gradients cv::sobel(src, dst, ddepth, xorder, yorder); destination image depth e.g. CV_32FC Order of the derivative x Order of the derivative y INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 6

Images Drawing Primitives p cv::line(im,p,p2,color,thickness); cv::point(x,y) p 2 c r cv::circle(im,c,r,color,thickness); CV_RGB(r,g,b) INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 7

User Interface How control a window using keyboard or mouse? Window Create and Destroy Window. cv::namedwindow(windowname) cv::destroywindow(windowname) Keyboard Wait for user to press key. const int key = cv::waitkey(-); If (key == 'a') { // Do Something } Mouse Setup a mouse handler. cv::setmousecallback(windowname, mousehandler, NULL ); void mousehandler(int event, int x, int y, int flags, void *param) { if (event == CV_EVENT_LBUTTONDOWN) // Do Something } INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 8

GUI Elements Trackbar Trackbar int createtrackbar(const string& trackbarname, const string& winname, int* value, int count, TrackbarCallback onchange=0, void* userdata=0); int sigma = 0; cv::createtrackbar("sigma", "image", &sigma, 00); while (true) { cv::mat smoothim; cv::gaussianblur(im, smoothim, cv::size(,), sigma/00.0f); cv::imshow("image", smoothim); cv::waitkey(0); } INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan 9

INTRODUCTION TO OPENCV Stefan Holzer, David Joseph Tan Demo