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

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

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

OpenCV. Basics. Department of Electrical Engineering and Computer Science

Laboratory of Applied Robotics

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

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

CS443: Digital Imaging and Multimedia Binary Image Analysis. Spring 2008 Ahmed Elgammal Dept. of Computer Science Rutgers University

1 Background and Introduction 2. 2 Assessment 2

Introduction to OpenCV

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

EE 584 MACHINE VISION

EE795: Computer Vision and Intelligent Systems

Binary Image Processing. Introduction to Computer Vision CSE 152 Lecture 5

Section 7.2 Volume: The Disk Method

FIDUCIAL BASED POSE ESTIMATION ADEWOLE AYOADE ALEX YEARSLEY

IRIS SEGMENTATION OF NON-IDEAL IMAGES

Morphological Image Algorithms

Object Move Controlling in Game Implementation Using OpenCV

OBJECT SORTING IN MANUFACTURING INDUSTRIES USING IMAGE PROCESSING

An Implementation on Object Move Detection Using OpenCV

OpenCV. Rishabh Maheshwari Electronics Club IIT Kanpur

Counting Particles or Cells Using IMAQ Vision

morphology on binary images

CS 184, Fall 1996 Midterm #1 Professor: unknown

C E N T E R A T H O U S T O N S C H O O L of H E A L T H I N F O R M A T I O N S C I E N C E S. Image Operations II

Image Contour Extraction Method based on Computer Technology Li Huanliang

CoE4TN4 Image Processing

Chapter 11 Representation & Description

Your Flowchart Secretary: Real-Time Hand-Written Flowchart Converter

EyeTech. Particle Size Particle Shape Particle concentration Analyzer ANKERSMID

Fundamentals of Programming

Image Processing. Bilkent University. CS554 Computer Vision Pinar Duygulu

EECS490: Digital Image Processing. Lecture #17

Digital Image Processing Fundamentals

Lecture 5 2D Transformation

CS 184, Fall 1996 Midterm #1 Professor: unknown

EXAM SOLUTIONS. Image Processing and Computer Vision Course 2D1421 Monday, 13 th of March 2006,

ECG782: Multidimensional Digital Signal Processing

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

ECG782: Multidimensional Digital Signal Processing

Machine vision. Summary # 6: Shape descriptors

IN5520 Digital Image Analysis. Two old exams. Practical information for any written exam Exam 4300/9305, Fritz Albregtsen

Fig. 1. Input image. Ibw=im2bw(I, 250/255); % threshold value should be between Fig. 2. Thresholded image cercuri-stele.

Requirements for region detection

BCC Rays Ripply Filter

In this lecture. Background. Background. Background. PAM3012 Digital Image Processing for Radiographers

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Image Processing Fundamentals. Nicolas Vazquez Principal Software Engineer National Instruments

Advances in Metrology for Guide Plate Analysis

ECE 172A: Introduction to Intelligent Systems: Machine Vision, Fall Midterm Examination

Intensity Transformation and Spatial Filtering

Boundary descriptors. Representation REPRESENTATION & DESCRIPTION. Descriptors. Moore boundary tracking

Introduction. Computer Vision & Digital Image Processing. Preview. Basic Concepts from Set Theory

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

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

Cartoon Transformation

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV

Lecture 7: Morphological Image Processing

Processing of binary images

Creating a 2D Geometry Model

Automated Particle Size & Shape Analysis System

Geometry: Semester 2 Practice Final Unofficial Worked Out Solutions by Earl Whitney

Algorithm User Guide:

EECS490: Digital Image Processing. Lecture #23

Fundamental of Programming (C)

E0005E - Industrial Image Analysis

BCC Rays Streaky Filter

Types of Edges. Why Edge Detection? Types of Edges. Edge Detection. Gradient. Edge Detection

EE663 Image Processing Histogram Equalization I

Camera Model and Calibration

Practical Image and Video Processing Using MATLAB

A Simple Cigarette Butts Detection System

IMAGE PROCESSING AND OPENCV. Sakshi Sinha Harshad Sawhney

High Points Recognition Method of Scraped Surface Based on Background Subtraction

EE795: Computer Vision and Intelligent Systems

Outline. Introduction System Overview Camera Calibration Marker Tracking Pose Estimation of Markers Conclusion. Media IC & System Lab Po-Chen Wu 2

Calibrated Image Acquisition for Multi-view 3D Reconstruction

Extracting Layers and Recognizing Features for Automatic Map Understanding. Yao-Yi Chiang

Morphological Image Processing

Building Detection. Guillem Pratx LIAMA. 18 August BACKGROUND 2 2. IDEA 2

Comparing Different Visual Motion Detection Algorithms

Morphological Image Processing

CS 376b Computer Vision

Image Processing: Final Exam November 10, :30 10:30

Lecture 6: Segmentation by Point Processing

Tutorial 8. Jun Xu, Teaching Asistant March 30, COMP4134 Biometrics Authentication

Product information. Hi-Tech Electronics Pte Ltd

EECS490: Digital Image Processing. Lecture #19

Edge and local feature detection - 2. Importance of edge detection in computer vision

Identifying and Reading Visual Code Markers

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

Digital Image Processing

CS 563 Advanced Topics in Computer Graphics QSplat. by Matt Maziarz

VC 16/17 TP5 Single Pixel Manipulation

Understanding Tracking and StroMotion of Soccer Ball

Section 10.1 Polar Coordinates

CS534 Introduction to Computer Vision Binary Image Analysis. Ahmed Elgammal Dept. of Computer Science Rutgers University

Ulrik Söderström 21 Feb Representation and description

Schedule for Rest of Semester

Transcription:

Professor William Hoff Dept of Electrical Engineering &Computer Science http://inside.mines.edu/~whoff/ 1

Pose Estimation in OpenCV 2

Pose Estimation of a Known Model Assume we have a known object model, with five fiducial targets Each target is a concentric contrasting circle ; it can easily be recognized by thresholding the image and finding connected components single (calibrated) camera From the 2D-3D point correspondences, we can determine the pose of the model with respect to the camera Let s see how to do this in OpenCV 3

Read and Display An Image #include <iostream> // This includes everything we need #include <opencv2/opencv.hpp> int main(int argc, char* argv[]) { cv::mat imageinput = cv::imread("robot.jpg"); if (imageinput.empty()) { printf("hey! Can't read input file!\n"); system("pause"); } imshow("input image", imageinput); // Wait for xxx ms (0 means wait until a keypress) cv::waitkey(0); } return EXIT_SUCCESS; 4

Useful OpenCV Functions cvtcolor convert a color (BGR) image to grayscale Example // Convert to gray cv::mat imageinputgray; cvtcolor(imageinput,imageinputgray,cv::color_bgr2gray) ); // in older versions, use CV_BGR2GRAY imshow("input grayscale image", imageinputgray); adaptivethreshold do a local adaptive threshold of the image Example // Do adaptive threshold... this compares each pixel to a local // mean of the neighborhood. The result is a binary image, where // dark areas of the original image are now white (1's). cv::mat imagethresh; adaptivethreshold(imageinputgray, imagethresh, // output thresholded image 255, // output value where condition is met cv::adaptive_thresh_gaussian_c, // local neighborhood cv::thresh_binary_inv, // threshold_type - invert 91, // blocksize (any large number) 0); // s constant to subtract from mean imshow("binary image", imagethresh); 5

Useful OpenCV Functions getstructuringelement create structuring element Example // Create a disk-shaped structuring element cv::mat structuringelmt = cv::getstructuringelement(cv::morph_ellipse, cv::size(3,3)); morphologyex do a morphological operation on the image Example // Apply morphological operations to get rid of small (noise) regions cv::mat imageopen; morphologyex(imagethresh, imageopen, cv::morph_open, structuringelmt); cv::mat imageclose; morphologyex(imageopen, imageclose, cv::morph_close, structuringelmt); imshow("binary image after morph", imageclose); 6

Vectors in C++ A vector class is part of the standard library. It is like an array, but its size can change at run time. Example: #include <vector> int main(int argc, char* argv[]) { std::vector<int> myvector; int i = 12, j = 34, k = 56; Allocate the empty vector (need to specify the type) myvector.push_back(i); myvector.push_back(j); myvector.push_back(k); push_back is how you add elements } for (unsigned int c = 0; c < myvector.size(); c++) printf("%d\n", myvector[c]); Prints 12, 34, 56 7

Useful OpenCV Functions findcontours find contours on the boundaries of binary regions OpenCV doesn t have connected component labeling, so we use this It can return two types of contours: Exterior contours surround white regions Holes surround black regions 8

Useful OpenCV Functions findcontours (continued) The RETR_CCOMP option organizes contours into a two-level hierarchy, where the top-level boundaries are external boundaries of the components and the second level boundaries are boundaries of the holes Example // Find contours. std::vector<std::vector<cv::point>> contours; std::vector<cv::vec4i> hierarchy; cv::findcontours( imageclose, // input image (is destroyed) contours, // output vector of contours hierarchy, // hierarchical representation cv::retr_ccomp, // retrieve all contours cv::chain_approx_none); // all pixels of each contours 9

drawcontours Useful OpenCV Functions Draws contour outlines or filled contours. Example cv::mat imagecontours = imageinput.clone(); // copy image cv::drawcontours(imagecontours, contours, -1, // contour id; -1 means draw all cv::scalar(0,255,255), // color 2, // thickness 8); // line type imshow("all contours", imagecontours); 10

#include <iostream> // This includes everything we need #include <opencv2/opencv.hpp> int main(int argc, char* argv[]) { cv::mat imageinput = cv::imread("robot.jpg"); Program (1 of 2) if (imageinput.empty()) { printf("hey! Can't read input file!\n"); system("pause"); } imshow("input image", imageinput); //// Convert to gray //cv::mat imageinputgray; //cvtcolor(imageinput,imageinputgray,cv::color_bgr2gray); //imshow("input grayscale image", imageinputgray); //// Do adaptive threshold... this compares each pixel to a local //// mean of the neighborhood. The result is a binary image, where //// dark areas of the original image are now white (1's). //cv::mat imagethresh; //adaptivethreshold(imageinputgray, // imagethresh, // output thresholded image // 255, // output value where condition met // cv::adaptive_thresh_gaussian_c, // local neighborhood // cv::thresh_binary_inv, // threshold_type - invert // 91, // blocksize (any large number) // 0); // a constant to subtract from mean //imshow("binary image", imagethresh); 11

//// Apply morphological operations to get rid of small (noise) regions //cv::mat structuringelmt = cv::getstructuringelement(cv::morph_ellipse, cv::size(3,3)); //cv::mat imageopen; //morphologyex(imagethresh, imageopen, cv::morph_open, structuringelmt); //cv::mat imageclose; //morphologyex(imageopen, imageclose, cv::morph_close, structuringelmt); //imshow("binary image after morph", imageclose); //// Now find contours. //std::vector<std::vector<cv::point>> contours; //std::vector<cv::vec4i> hierarchy; //cv::findcontours( // imageclose, // input image (is destroyed) // contours, // output vector of contours // hierarchy, // hierarchical representation // cv::retr_ccomp, // retrieve all contours // cv::chain_approx_none); // all pixels of each contours // //// Draw all contours. //cv::mat imagecontours = imageinput.clone(); // copy image //cv::drawcontours(imagecontours, contours, // -1, // contour id; -1 means draw all // cv::scalar(0,255,255), // color // 2, // thickness // 8); // line type //imshow("all contours", imagecontours); Program (2 of 2) // Wait for xxx ms (0 means wait until a keypress) cv::waitkey(0); } return EXIT_SUCCESS; 12

Contours Within Contours We are looking for an exterior contour surrounding a hole Original image // Find only those contours with a child inside. cv::mat imagechildren = imageinput.clone(); for (unsigned int i1 = 0; i1 < contours.size(); i1++) { int i2 = hierarchy[i1][2]; if (i2 < 0) continue; // See if it has child inside Thresholded and inverted cv::drawcontours(imagechildren, contours, i1, // contour id; -1 means draw all cv::scalar(0, 255, 255), // color 2, // thickness 8); // line type } imshow("contours with children", imagechildren); Hole Contours Exterior 13

Finding CCCs The OpenCV function moments computes values of The centroid is given by i,j = 0..3 Check the "circularity" ratio of the outer region, which is the ratio of area to perimeter squared: R = 4*pi*A/P^2 R is 1 for a circle, and pi/4 for a square 14

// Find CCCs. cv::mat imageoutput = imageinput.clone(); for (unsigned int i1 = 0; i1 < contours.size(); i1++) { int i2 = hierarchy[i1][2]; if (i2 < 0)continue; // See if it has a child inside // Compute centroids of inner and outer regions cv::moments mu1 = cv::moments(contours[i1]); cv::point2d x1(mu1.m10 / mu1.m00, mu1.m01 / mu1.m00); cv::moments mu2 = cv::moments(contours[i2]); cv::point2d x2(mu2.m10 / mu2.m00, mu2.m01 / mu2.m00); // Check if centroids coincide const double DPIXEL = 3.0; // max distance between centroids if (norm(x1 - x2) > DPIXEL)continue; // Check the "circularity" ratio of the outer region, which is // the ratio of area to perimeter squared: R = 4*pi*A/P^2. // R is 1 for a circle, and pi/4 for a square. double P1 = arclength(contours[i1], true); double A1 = contourarea(contours[i1]); if (4 * 3.1415*A1 / (P1*P1) < 3.1415 / 4) // Let's say that we want our region to be at least as round as a square. continue; // Looks like a valid CCC. Draw a circle around it. cv::circle(imageoutput, x1, // center 3, // radius cv::scalar(0, 0, 255), // color -1); // negative thickness=filled } imshow("detected CCCs", imageoutput); 15

Solving for Pose The OpenCV function solvepnp finds the pose of an object from 3D-2D point correspondences. PnP stands for Perspective n-point problem. Inputs: A vector of 3D object points A vector of corresponding 2D image points Intrinsic camera parameters Outputs: Rotation vector (axis of rotation, multiplied by angle) Translation vector This is the C++ vector (a dynamic array) Camera matrix K See axis-angle rotation convention, in Lecture 4a 16