OpenCV. Rishabh Maheshwari Electronics Club IIT Kanpur

Similar documents
IMAGE PROCESSING AND OPENCV. Sakshi Sinha Harshad Sawhney

Multimedia Retrieval Exercise Course 2 Basic of Image Processing by OpenCV

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

ECE 661 HW 1. Chad Aeschliman

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

Introduction to OpenCV. Marvin Smith

1. Introduction to the OpenCV library

ArduCAM USB Camera C/C++ SDK

Introduction to OpenCV

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

Autonomous Golf Cart Vision Using HSV Image Processing and Commercial Webcam

ECE661 Computer Vision : HW1

ECE661 Computer Vision : HW2

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

Laboratory of Applied Robotics

ECE 3331, Dr. Hebert, Summer-3, 2016 HW 11 Hardcopy HW due Tues 07/19 Program due Sunday 07/17. Problem 1. Section 10.6, Exercise 3.

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV

LAB SESSION 1 INTRODUCTION TO OPENCV

libtcod Documentation

webcam Reference Manual

ArduCAM USB Camera SDK

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

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

Real-Time Hand Gesture Detection and Recognition Using Simple Heuristic Rules

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

Problem 1. Multiple Choice (choose only one answer)

Image Processing (1) Basic Concepts and Introduction of OpenCV

Physical Color. Color Theory - Center for Graphics and Geometric Computing, Technion 2

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

CS103L PA4. March 25, 2018

Visible Color. 700 (red) 580 (yellow) 520 (green)

Iteration in Programming

Design Programming DECO2011

Augmented Feedback for Childhood Apraxia of Speech Design Specification Document

CSIT 691 Independent Project. Video indexing

OptimiData. JPEG2000 Software Development Kit for C/C++ Reference Manual. Version 1.6. from

CP SC 4040/6040 Computer Graphics Images. Joshua Levine

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

CpSc 101, Fall 2015 Lab7: Image File Creation

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

SDK-S User Manual K-21-A ( ) 1 Copyright 2013 B&W Tek, Inc.

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

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

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

Introduction to C. Sami Ilvonen Petri Nikunen. Oct 6 8, CSC IT Center for Science Ltd, Espoo. int **b1, **b2;

Color, Edge and Texture

Autonomous Rubik's Cube Solver Using Image Processing

CSE/EE-576, Final Project

ECE264 Fall 2013 Exam 3, November 20, 2013

slide 1 gaius Game Trees

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

ASPRS LiDAR SPRS Data Exchan LiDAR Data Exchange Format Standard LAS ge Format Standard LAS IIT Kanp IIT Kan ur

OpenCV Tutorial. Part II Loading Images and Using Histograms. 29 November Gavin S Page

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Structure from Motion Library

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

MCS 2514 Fall 2012 Programming Assignment 3 Image Processing Pointers, Class & Dynamic Data Due: Nov 25, 11:59 pm.

An Implementation on Object Move Detection Using OpenCV

Programming projects. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer

Example 1: Color-to-Grayscale Image Processing

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

ECE 190 Final Exam. Practice exam

blur Melissa Kaufman-Gomez Team Leader Timothy Goodwin System Architect Dexter Callender Language Guru Daniel Hong Test Wizard

CP SC 4040/6040 Computer Graphics Images. Joshua Levine

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

Computer and Machine Vision

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Chapter 6. Introduction to OpenCV

Creating, Compiling and Executing

Type Conversion. and. Statements

n Group of statements that are executed repeatedly while some condition remains true

Unit 3 Decision making, Looping and Arrays

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)

4 4 4 RGB LED Cube kit Instruction Manual

CS 315 Data Structures Fall Figure 1

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Assignment 1 - Use OpenCV for camera calibration

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Biomedical Image Analysis. Mathematical Morphology

Maximizing Face Detection Performance

ICS(II),Fall 2017 Performance Lab: Code Optimization Assigned: Nov 20 Due: Dec 3, 11:59PM

Optical Verification of Mouse Event Accuracy

Grasping Known Objects with Aldebaran Nao

Binary representation and data

Miscellaneous Stuff That Might Be Important.

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

: Principles of Imperative Computation Victor Adamchik. Practice Exam - I

DECISION MAKING STATEMENTS

ArduCAM USB Camera SDK

Common File Formats. Need a standard to store images Raster data Photos Synthetic renderings. Vector Graphic Illustrations Fonts

This is not yellow. Image Files - Center for Graphics and Geometric Computing, Technion 2

CHAPTER 4 SEMANTIC REGION-BASED IMAGE RETRIEVAL (SRBIR)

DC54 DATA STRUCTURES DEC 2014

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

This is CS50. Harvard University Fall Quiz 0 Answer Key

Anonymizer SDK. Developer's Guide. Version 5.x. Eyedea Recognition, s.r.o.

Solution for Data Structure

Transcription:

OpenCV Rishabh Maheshwari Electronics Club IIT Kanpur

Installing OpenCV Download and Install OpenCV 2.1:- http://sourceforge.net/projects/opencvlibrary/fi les/opencv-win/2.1/ Download and install Dev C++ or any other Compiler and include OpenCV libraries in it:- http://opencv.willowgarage.com/wiki/devcpp

Image Its important to know how an image is stored in C language. To start with, we first need to know types of images.

Binary Image Each Pixel has either 1 (White) or 0 (Black) Depth =1 (bit) Number of Channels = 1 (by the way, what is pixel??) 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0

Grayscale Each Pixel has a value from 0 to 255. 0 : black and 1 : White Between 0 and 255 are shades of b&w. Depth=8 (bits) Number of Channels =1

Grayscale Image

RGB Image Each Pixel stores 3 values :- R : 0-255 G: 0-255 B : 0-255 Depth=8 (bits) Number of Channels = 3

RGB image

HSV image Each pixel stores 3 values :- H ( hue ) : 0-180 S (saturation) : 0-255 V (value) : 0-255 Depth = 8 (bits) Number of Channels = 3 Note : Hue in general is from 0-360, but as hue is 8 bits in OpenCV, it is shrinked to 180

Starting with OpenCV OpenCV is simply a library for C language developed for Image Processing. You can start using its functions by including #include "cv.h" #include "highgui.h"

Image as a struct An image is stored as a structure IplImage with following elements :- int height int width int nchannels int depth char *imagedata int widthstep.. So on Height Width

Initialising pointer to a image (structure) :- IplImage* input Load image to the pointer [0=gray;1=colored] input=cvloadimage("apple.jpg",1) Note :The image apple.jpg must be in same folder where you save your C program

cvnamedwindow("ii",1) Creates a window named ii 1 = Coloured 0 = Grayscale

cvshowimage("ii",input) Shows image pointed by input, in the window named ii

Create an Image To create an image you need to specify its :- Size ( height and width) Depth Number of Channels output=cvcreateimage(cvgetsize(input),ipl_depth_8u,3)

cvwaitkey( a number ) If 0 or negative number is given as input:- Waits indefinitely till key press and returns the ASCII value of the key pressed If positive number is given as input :- Waits for corresponding milliseconds.

Command Function cvdestroywindow("ii") Destroys window named ii cvreleaseimage( &input ) Releases image pointer input from memory output=cvcloneimage(input) Copies image from input to output cvcvtcolor( input, output, conversion type) Conv. type : CV_BGR2GRAY,CV_BGR2HSV Saves input image in output pointer in other color space cvsaveimage("output.jpg",output) cvdilate(input, output, NULL, iterations) cverode(input,erode,null,iterations); Note : here NULL is a structural element Saves image pointed by output naming it output Dilates an image for given number of iterations and saves it in output Erodes an image for given number of iterations and saves it in output

cvthreshold(input, output, threshold, maxvalue, thresholdtype) Threshhold types:- CV_THRESH_BINARY max value if more than threshold, else 0 CV_THRESH_BINARY_INV 0 if more than threshold, else max value CV_THRESH_TRUNC threshhold if more than threshold, else no change CV_THRESH_TOZERO no change if more than threshold else 0 CV_THRESH_TOZERO_INV 0 if morethan threshold, else no change

imagedata An image s data is stored as a character array whose first element is pointed by :- Input->imageData ( char pointer ) 6 0 15 86 255 46 82 widthstep Number of array elements in 1 row is stored in :- input->widthstep

Accessing (i,j) pixel of an image Grayscale uchar *pinput = (uchar*)input->imagedata; int c = pinput[i*input->widthstep + j]; i (0,0) j (i,j)

3 channel image (BGR):- uchar *pinput = (uchar*)input->imagedata; int b= pinput[i*input->widthstep + j*input->nchannels+0]; int g= pinput[i*input->widthstep + j*input->nchannels+1]; int r= pinput[i*input->widthstep + j*input->nchannels+2]; i (0,0) j B G R B G R (i,j)

Video pointer CvCapture* capture - is a video pointer. To take video from camera :- CvCapture *capture=cvcreatecameracapture(0); Note : Here 0 - Default & 1 - External To take video from a saved video file :- CvCapture* capture=cvcreatefilecapture("trial.avi" );

Taking image from Camera CvCapture *capture=cvcreatecameracapture(0); for(int i=0;i<100000000;i++); if(capture!=null) IplImage *frame=cvqueryframe(capture); Note : Here for loop is used to compensate time of initialization of camera in Windows

Playing video CvCapture *capture=cvcreatecameracapture(0); IplImage *frame; if(capture!=null){ } frame=cvqueryframe(capture ); while(1){ cvshowimage( Video",frame); frame=cvqueryframe(capture); c=cvwaitkey(1);// frame rate if(c>0&&c<255) } break;

Mouse Pointer Information void my_mouse_callback( int event, int x, int y, int flags, void* param ){ uchar *pimage = (uchar*)image->imagedata; int r=pimage[y*image->widthstep + x*image->nchannels+2]; int g=pimage[y*image->widthstep + x*image->nchannels+1]; int b=pimage[y*image->widthstep + x*image->nchannels+0]; printf( " x=%d y=%d r=%d g=%d b=%d\n",x,,y,,r,g,b); } main(){.. cvnamedwindow("image",1); cvsetmousecallback("image", my_mouse_callback, NULL); cvshowimage("image",image); } Note : cvsetmousecallback is set for a NamedWindow and not for an image

IP Problem Statements In general, all IP problem Statements have to discard one color and accept another in output image. Input Image ` Output Binary Image If( color pixel value > threshhold) output pixel=255; else output pixel =0; Note : In general, HSV format is highly useful to distinguish RGB colors ( Why? )