Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV

Similar documents
Multimedia Retrieval Exercise Course 2 Basic of Image Processing by OpenCV

OpenCV. Basics. Department of Electrical Engineering and Computer Science

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

1. Introduction to the OpenCV library

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

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

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

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

Computer and Machine Vision

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

Linked List using a Sentinel

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Program Organization and Comments

Intro to Multimedia Retrieval Exercise Course 4 Query by Example: Similarity Computation

Exercise 1.1 Hello world

CS 315 Data Structures Fall Figure 1

Visual Computing in OpenCV Lecture 2: Dense Matrices

CSCE574 Robotics Spring 2014 Notes on Images in ROS

CMPS 221 Sample Final

Programmazione. Prof. Marco Bertini

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

CS 376b Computer Vision

Introduction to OpenCV

Image Steganalysis Image Steganography

Check the Desktop development with C++ in the install options. You may want to take 15 minutes to try the Hello World C++ tutorial:

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

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

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

C++ Namespaces, Exceptions

C++ For Science and Engineering Lecture 12

CMSC 202 Midterm Exam 1 Fall 2015

CSE 333. Lecture 10 - references, const, classes. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington

Introduction to OpenCV. Marvin Smith

Lab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables

ECE 661 HW 1. Chad Aeschliman

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

RLL Computer Vision Code 1.0 HLL

Week 3: Pointers (Part 2)

UEE1303(1070) S12: Object-Oriented Programming Constant Pointer and Class

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

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

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

CS103L PA4. March 25, 2018

Week 5: Files and Streams

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Arrays. Week 4. Assylbek Jumagaliyev

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

Representation of image data

OpenCV. Rishabh Maheshwari Electronics Club IIT Kanpur

Physics 234: Computational Physics

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Image Processing (1) Basic Concepts and Introduction of OpenCV

ECE 661: Homework #3

Intermediate Programming, Spring 2017*

Programación de Computadores. Cesar Julio Bustacara M. Departamento de Ingeniería de Sistemas Facultad de Ingeniería Pontificia Universidad Javeriana

UEE1302 (1102) F10 Introduction to Computers and Programming (I)

IMAGE PROCESSING AND OPENCV. Sakshi Sinha Harshad Sawhney

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board.

CS2141 Software Development using C/C++ C++ Basics

tablica: array: dane_liczbowe

Lab: Supplying Inputs to Programs

Interaction Technology

WARM UP LESSONS BARE BASICS

Call-by-Type Functions in C++ Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #5

My First Command-Line Program

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 9. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University

Problem Solving: Storyboards for User Interaction

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8

Lecture on pointers, references, and arrays and vectors

Introduction to C++ (Extensions to C)

Image Processing (1) Basic Concepts and Introduction of OpenCV

Praktikum: 4. Content of today s lecture. Content of today s lecture. Manfred Grove Houxiang Zhang. Program introduction. Program introduction

CS242 COMPUTER PROGRAMMING

File IO and command line input CSE 2451

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Programming Language. Functions. Eng. Anis Nazer First Semester

Introduction to C++ Systems Programming

ECE 462 Fall 2011, Third Exam

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

Program template-smart-pointers-again.cc

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

CE221 Programming in C++ Part 1 Introduction

Chapter 10 - Notes Applications of Arrays

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

C++ basics Getting started with, and Data Types.

CS24 Week 3 Lecture 1

First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio

Pointers and scanf() Steven R. Bagley

Informatik I (D-ITET) Übungsstunde 9, Hossein Shafagh

Manfred Grove Houxiang Zhang

Topic 8: Lazy Evaluation

CSE 100: STREAM I/O, BITWISE OPERATIONS, BIT STREAM I/O

Computer Programming : C++

Lecture 5 Files and Streams

Chapter 9: Pointers Co C pyr py igh i t gh Pear ea so s n n E ducat ca io i n, n Inc. n c.

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Recursion. Contents. Steven Zeil. November 25, Recursion 2. 2 Example: Compressing a Picture 4. 3 Example: Calculator 5

Here, type declares the base type of the array, which is the type of each element in the array size defines how many elements the array will hold

Program template-smart-pointers.cc

Transcription:

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV Kimiaki Shirahama, D.E. Research Group for Pattern Recognition Institute for Vision and Graphics University of Siegen, Germany

Last lesson s Program Read an image and show it in a dialog #include "stdafx.h // This is a head file specific to my project #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> int main(int argc, const char* argv[]){ cv::mat img = cv::imread("c:\\opencv\\sources\\samples\\data\\happyfish.jpg", 1); cv::namedwindow("img", cv::window_autosize); cv::imshow("img", img); cv::waitkey(0); cv::destroyallwindows(); return 0; } Please change the image filename depending on your environment.

Overview of Today s Lesson 1. cv::mat - Structure of cv::mat - Printing out the Header Information - How are pixel values stored with cv::mat - Printing out Pixel Values - Shallow and deep copies 2. Useful functions in highgui

OpenCV Information Useful web page: http://opencv.org/documentation.html (Especially, http://docs.opencv.org/3.1.0/) opencv2/ core.hpp: Basic data structure and functions in OpenCV imgproc.hpp: Functions for image processing and analysis imgcodecs.hpp: Functions for loading and writing image files videoio.hpp: Functions for loading and writing video files highgui.hpp: Functions for creating and managing GUIs (highgui.hpp includes core.hpp, imgcodecs.hpp and videoio.hpp) ml.hpp: Functions for machine learning methods dnn.hpp: Functions for deep learning methods etc.

cv::mat Container for storing an image - Data header - cols: Image width - rows: Image height - dims: Number of dimensions (An image has 2 dimensions corresponding to the row and column) - channels: Number of channels used to represent a pixel (3 channels for an RGB image, 1 channel for a gray-scale image) - depth: Data type used to represent one channel (A usual image where the R/G/B value of a pixel range from 0 to 255. This means one channel is represented by 8-bit unsigned char (integers) ) - Memory (RAM) cv::mat cols:259 rows: 194 channels: 3 Actual data (pixel values)

Printing out the Header Information Please add to the last lesson s code some sentences to show image s width, height, dimensionality, channels and depth. cout << ">> Width: " << img.cols << ", height:" << img.rows << ", dims:" << img.dims << endl; cout << ">> Depth:" << img.depth() << "(=" << CV_8U << "), channels:" << img.channels() << endl; 1. Please refer to http://docs.opencv.org/3.1.0/d3/d63/classcv_1_1mat.html for how to access each piece of information. 2. To output texts to a terminal, cout in C++ is more convenient than printf because the former can automatically recognise the variable types. #include <iostream> using namespace std; // If this is missing, cout has to be written as std::cout 3. In Visual C++, a terminal will quickly disappear after reaching the end of a program. To keep the terminal appearing, one simple approach is as follows: int a = 0; cin >> a; // Wait until some value is input into a

cv::mat in More Detail 3-channel color image Memory (RAM) cv::mat cols:259 rows: 194 channels: 3 Actual data (pixel values) B G R B G R Each pixel with three channels is represented by three values (the order is BGR) For 8-bit depth images, it is recommended to access one pixel ( B G R ) using cv::vec3b. - Get the values of the pixel (x, y) cv::vec3b p = img.at<cv::vec3b>(y, x); Then, B, G and R values of (x, y) are p[0], p[1] and p[2], respectively. - Get the pointer to the yth row cv::vec3b *row = img.ptr<cv::vec3b>(y); Then, B, G and R values of (x, y) are row[x][0], row[x][1] and row[x][2], respectively. For another depth image, refer to http://docs.opencv.org/3.1.0/dc/d84/group core basic.html

For Your Information Gray-scale image Memory (RAM) cv::mat cols:256 rows: 256 channels: 1 Actual data (pixel values) V V Each pixel has only one channel value ( V ) For 8-bit depth images, it is recommended to access one pixel using uchar. - Get the values of the pixel (x, y) uchar p = img.at<uchar>(y, x); - Get the pointer to the yth row uchar *row = img.ptr<uchar>(y); Then, the value of (x, y) are row[x].

Printing out Pixel Values Please add to the last lesson s code sentences to show the values of each pixel cout << "##### Using at #####" << endl; for (int y = 0; y < img.rows; y++) { for (int x = 0; x < img.cols; x++) { cv::vec3b p = img.at<cv::vec3b>(y, x); if ( (y == 0 y == img.rows - 1) && (x < 5 x > img.cols - 5) ) printf("(%d,%d): %u, %u, %u\n", x, y, p[0], p[1], p[2]); } } cout << "##### Using ptr #####" << endl; for (int y = 0; y < img.rows; y++) { cv::vec3b *row = img.ptr<cv::vec3b>(y); for (int x = 0; x < img.cols; x++) { if ((y == 0 y == img.rows - 1) && (x < 5 x > img.cols - 5)) printf("(%d,%d): %u, %u, %u\n", x, y, row[x][0], row[x][1], row[x][2]); } } NOTE: Variable type recognition of cout does not work for elements (unsigned char) of Vec3b. Use printf to show pixel values.

Shallow and Deep Copies - Shallow copy: Only the header is copied - Deep copy: Both of the header and actual data are copied cv::mat img created by imread cols:259 rows: 194 channels: 3 cols:259 rows: 194 channels: 3 cv::mat img2 created by img2 = img or cv::mat img2(img) Actual data (pixel values) Copied actual data cv::mat img3 created by cv::mat::clone() or cv::mat::copyto() cols:259 rows: 194 channels: 3

Useful Functions in highgui 1. void cv::namedwindow(const String &winname, int flags=window_autosize) The first variable specifies the name of the window where an image is shown. 2. void cv::imshow(const String &winname, InputArray mat) Using the first variable, you can specify which window is used to show an image (mat) 3. void cv::destroyallwindows(), void cv::destroywindow(const String &winname) Release the memory used for the window 4. int cv::waitkey (int delay=0) The function is used to wait for some key input or delay milliseconds. The return value represents which key is pressed. For more detail, refer to http://docs.opencv.org/3.1.0/d7/dfc/group highgui.html