Making PHP See. Confoo Michael Maclean

Similar documents
Image Processing : Introduction

Image processing for gesture recognition: from theory to practice. Michela Goffredo University Roma TRE

Lane Detection in Automotive

Vision Review: Image Processing. Course web page:

Lane Detection in Automotive

Computing for Engineers in Python

Computer Vision Robotics I Prof. Yanco Spring 2015

Color Space 1: RGB Color Space. Color Space 2: HSV. RGB Cube Easy for devices But not perceptual Where do the grays live? Where is hue and saturation?

MATLAB 6.5 Image Processing Toolbox Tutorial

CSE 564: Scientific Visualization

Digital Image Processing. Digital Image Fundamentals II 12 th June, 2017

An Effective Method for Removing Scratches and Restoring Low -Quality QR Code Images

Anna University, Chennai B.E./B.TECH DEGREE EXAMINATION, MAY/JUNE 2013 Seventh Semester

Sampling Rate = Resolution Quantization Level = Color Depth = Bit Depth = Number of Colors

Module All You Ever Need to Know About The Displace Filter

Study guide for Graduate Computer Vision

Android Test Apps documentation

Image Filtering Josef Pelikán & Alexander Wilkie CGG MFF UK Praha

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad

COMPARATIVE PERFORMANCE ANALYSIS OF HAND GESTURE RECOGNITION TECHNIQUES

Image Processing. Adam Finkelstein Princeton University COS 426, Spring 2019

A SURVEY ON HAND GESTURE RECOGNITION

CAP 5415 Computer Vision. Marshall Tappen Fall Lecture 1

Computer and Machine Vision

OPEN CV BASED AUTONOMOUS RC-CAR

Mahdi Amiri. March Sharif University of Technology

Color and More. Color basics

>>> from numpy import random as r >>> I = r.rand(256,256);

Image Processing for feature extraction

>>> from numpy import random as r >>> I = r.rand(256,256);

Carmen Alonso Montes 23rd-27th November 2015

][ R G [ Q] Y =[ a b c. d e f. g h I

CS 484, Fall 2018 Homework Assignment 1: Binary Image Analysis

An Efficient Color Image Segmentation using Edge Detection and Thresholding Methods

Introduction to Image Analysis with

IMAGE ENHANCEMENT. Quality portraits for identification documents.

SYLLABUS CHAPTER - 2 : INTENSITY TRANSFORMATIONS. Some Basic Intensity Transformation Functions, Histogram Processing.

2.0 4 Easy Ways to Delete Background to Transparent with GIMP. 2.1 Using GIMP to Delete Background to Transparent

Midterm Examination CS 534: Computational Photography

Images and Graphics. 4. Images and Graphics - Copyright Denis Hamelin - Ryerson University

Ron Brecher. AstroCATS May 3-4, 2014

Image analysis. CS/CME/BioE/Biophys/BMI 279 Oct. 31 and Nov. 2, 2017 Ron Dror

PRACTICAL IMAGE AND VIDEO PROCESSING USING MATLAB

Counting Sugar Crystals using Image Processing Techniques

Table of contents. Vision industrielle 2002/2003. Local and semi-local smoothing. Linear noise filtering: example. Convolution: introduction

Scrabble Board Automatic Detector for Third Party Applications

8.2 IMAGE PROCESSING VERSUS IMAGE ANALYSIS Image processing: The collection of routines and

Real-Time Face Detection and Tracking for High Resolution Smart Camera System

A Basic Guide to Photoshop Adjustment Layers

An Approach for Reconstructed Color Image Segmentation using Edge Detection and Threshold Methods

The biops Package. August 14, 2007

Computer Graphics. Si Lu. Fall er_graphics.htm 10/02/2015

June 30 th, 2008 Lesson notes taken from professor Hongmei Zhu class.

AUTOMATIC IRAQI CARS NUMBER PLATES EXTRACTION

Traffic Sign Recognition Senior Project Final Report

Various Calibration Functions for Webcams and AIBO under Linux

The Camera Club. David Champion January 2011

ENGG1015 Digital Images

CS/ECE 545 (Digital Image Processing) Midterm Review

Digital image processing. Árpád BARSI BME Dept. Photogrammetry and Geoinformatics

Image Filtering in Spatial domain. Computer Vision Jia-Bin Huang, Virginia Tech

NON UNIFORM BACKGROUND REMOVAL FOR PARTICLE ANALYSIS BASED ON MORPHOLOGICAL STRUCTURING ELEMENT:

Filip Malmberg 1TD396 fall 2018 Today s lecture

CHAPTER 4 LOCATING THE CENTER OF THE OPTIC DISC AND MACULA

CS 376b Computer Vision

Follower Robot Using Android Programming

Number Plate Recognition Using Segmentation

A Study on Image Enhancement and Resolution through fused approach of Guided Filter and high-resolution Filter

Digital Image Processing Programming Exercise 2012 Part 2

Sony PXW-FS7 Guide. October 2016 v4

A New Framework for Color Image Segmentation Using Watershed Algorithm

ImageJ: Introduction to Image Analysis 3 May 2012 Jacqui Ross

IMAGE PROCESSING TECHNIQUE TO COUNT THE NUMBER OF LOGS IN A TIMBER TRUCK

Figure 1. Mr Bean cartoon

Digital Image Processing 3/e

GEOG432: Remote sensing Lab 3 Unsupervised classification

Computer Graphics Fundamentals

CS 4501: Introduction to Computer Vision. Filtering and Edge Detection

Computer Vision. Howie Choset Introduction to Robotics

Automatic Electricity Meter Reading Based on Image Processing

Intelligent agents (TME285) Lecture 4,

Introduction to computer vision. Image Color Conversion. CIE Chromaticity Diagram and Color Gamut. Color Models

High Dynamic Range Photography

Prof. Feng Liu. Fall /02/2018

Acknowledgements. quaere verum

Preprocessing and Segregating Offline Gujarati Handwritten Datasheet for Character Recognition

Colored Rubber Stamp Removal from Document Images

An Evaluation of Automatic License Plate Recognition Vikas Kotagyale, Prof.S.D.Joshi

CS534 Introduction to Computer Vision. Linear Filters. Ahmed Elgammal Dept. of Computer Science Rutgers University

CS231A Final Project: Who Drew It? Style Analysis on DeviantART

Brain Tumor Segmentation of MRI Images Using SVM Classifier Abstract: Keywords: INTRODUCTION RELATED WORK A UGC Recommended Journal

EMGU CV. Prof. Gordon Stein Spring Lawrence Technological University Computer Science Robofest

Colour Profiling Using Multiple Colour Spaces

Sensors and Sensing Cameras and Camera Calibration

Digital Image Processing

PHOTOGRAPHY: MINI-SYMPOSIUM

In order to manage and correct color photos, you need to understand a few

IMAGE ENHANCEMENT IN SPATIAL DOMAIN

KEYWORDS Cell Segmentation, Image Segmentation, Axons, Image Processing, Adaptive Thresholding, Watershed, Matlab, Morphological

2. Color spaces Introduction The RGB color space

Transcription:

Making PHP See Confoo 2011 Michael Maclean mgdm@php.net http://mgdm.net

You want to do what? PHP has many ways to create graphics Cairo, ImageMagick, GraphicsMagick, GD...

You want to do what? There aren't that many ways to process graphics

Introducing OpenCV The Open Computer Vision Library has > 500 algorithms, documentation and sample code for real time computer vision.

Introducing OpenCV Originally developed by Intel, released as open source under the BSD licence

Introducing OpenCV http://opencv.org

Why? Because I Can

Why? I wanted to learn about it, but use a language I was more comfortable with

Why? I thought it might be useful to others

Applications Object recognition This includes face detection!

Applications Gesture tracking (perhaps not that useful in PHP...)

Applications Structure from motion Creating 3D models of objects from 2D inputs

Applications Structure from motion Again, maybe not in PHP, but one day...

Applications Other cool things I've not yet thought of

A Brief Disclaimer It's not my aim for this talk to give a short course on computer vision

A Brief Disclaimer Rather, I'm giving a tour of an interesting bit of software

A Brief Disclaimer (I'm certainly not the best qualified, anyway!)

A Brief Disclaimer I will not explain the theory behind many things (as I might not understand it myself)

A Brief Disclaimer I'm not really a maths geek, so if there are any inaccuracies, point them out

Getting it It's will be on Github very shortly http://github.com/mgdm

Getting it You'll need the OpenCV library, which is in most Linux distributions these days You need PHP 5.3

Getting it I've not done a Windows build yet it's on the TODO Patches are welcome

Installing It's the normal PHP extension build system phpize./configure make make install Add extension=opencv.so to php.ini

Basic usage Everything in the library is under the OpenCV namespace If you're not familiar with namespaces, check http://php.net/namespaces

Basic usage Let's start by loading a test image

Loading and Saving Images $image = OpenCV\Image::load("test.jpg"); $image ->save("test2.jpg"); You now have an Image object The same image has been saved as test2.jpg If that has worked, the library is set up correctly. Congratulations

Basics of OpenCV It treats images as being fundamentally matrices of numbers

Basics of OpenCV So, many of the same operations you'd perform on a matrix can also be performed on an image

Basics of OpenCV This includes things like transposition, adding, multiplying, adding scalars, etc

Basics of OpenCV There is a very large list of these basic operators Not all of which I understand...

Image Processing OpenCV (predictably) has many, many functions that do various things to images These range from the fairly mundane to the very powerful

Smoothing Not very exciting, but a good demonstration a Gaussian blur

Smoothing $dst = $image->smooth( OpenCV\Image::GAUSSIAN, 31, 0, 0, 0); $dst will now contain a slightly fuzzy version of the image

The input

The result

Smoothing, continued Why would you want to do that? Perhaps to remove noise from an image taken in low light

Smoothing, continued Various methods are available, accessible via different parameters to smooth() Median blur Gaussian Bilateral filtering

Image Morphology (Sounds cool, doesn't it?)

Image Morphology These are a class of operators which convolve an image with a kernel The kernel is like a mask, which is scanned across every point in the image It has an anchor point, which represents the pixel being currently transformed

Kernels 0 1 0 1 2 1 0 1 0 For some operations, each number represents the amount of influence that pixel has on the output

Dilation A kernel consisting of a 3x3 square, with an anchor in the centre, is scanned over the image For each point that the anchor goes over, the maximum value covered by the kernel is found

Dilation This maximum value becomes the value of the pixel at that position in the new image The upshot of this is, bright areas get larger

Erosion This is fundamentally the opposite of dilation Instead of the maximum value under the kernel, we look for the minimum Bright areas get smaller

What's the point? Bright areas might be part of the same object, but split into several parts in the image (Shadows, obstructions)

What's the point? These operations will cause these areas to join up, making them easier to identify

Edge detection OpenCV features several algorithms for edge detection You might well have seen these before in GIMP or Photoshop You can use them to get outlines of objects

Sobel The Sobel operator is a way to get a derivative of an image (Maths geeks may point out this is technically incorrect just run with it for now)

Sobel You end up with an image which has bright areas where there is lots of contrast

The result

Canny A more complex algorithm, which takes derivatives in x and y Some more processing results in a far clearer line

The result

And now for something completely different more interesting

Template matching You can use OpenCV to try and locate an image within another image You'd usually do this with a small image of an object, and a larger search image

My test image (It is only 59 pixels wide, excuse the fuzziness)

My other image Thanks to Michaelangelo van Dam for the Creative Commons picture http://www.flickr.com/photos/dragonbe/3411273755/

The result

The result It's not perfect, but it's a start

The result The reason it matches most of the ElePHPants is because the small image is, well, small, and has been re saved as a JPEG

The result Thus, the pixels it is searching with are no longer identical to the originals

Histograms Histograms are a way of fitting values into slots, or bins, as OpenCV calls them They are fundamentally the same as an array, with a count of values, and can be graphed as a bar chart

I'm not going to do anything quite that dull

Histograms OpenCV uses histograms to record a signature of features in an image

Histograms For example, you can use them to record the colours in a section of an image (Stay awake at the back)

Back projection If I convert this image to HSV format, I can get a version of the image which encodes the hue as one channel

Back projection Then I can convert this into a histogram, to get a hash of sorts of the proportion of colours in the image Then, OpenCV will take this histogram and look for it in another image

An aside... This is what an image looks like when it's converted to HSV and saved as if it was still RGB

The code <?php use OpenCV\Image as Image; use OpenCV\Histogram as Histogram; echo "Loading sample\n"; $i = Image::load("elephpant_sample.jpg", Image::LOAD_IMAGE_COLOR); $hsv = $i->convertcolor(image::rgb2hsv); $planes = $hsv->split(); $hist = new Histogram(1, 32, Histogram::TYPE_ARRAY); $hist ->calc($planes[0]); echo "Loading main image\n"; $i2 = Image::load("dragonbe_elephpants.jpg", Image::LOAD_IMAGE_COLOR); $hsv2 = $i2->convertcolor(image::rgb2hsv); $planes2 = $hsv2->split(); $result = $planes2[0]->backproject($hist); $result ->save("bp_output.jpg");

The result

The result As you can see, the result is a binary image showing the places where the histogram matched the colours in the image

The result You could probably get a better match with a better sample

The result You can then go on and do other things with the morphology operators, to find the extents of each match

The result Or you can use that image as a mask for other operations

Other uses for histograms In combination with the edge detection stuff from earlier, you can make a histogram of the edge gradients

Other uses for histograms This means that you can then try and match particular shapes using a histogram This is used by some for gesture recognition

Machine learning In addition to the image processing functions, OpenCV includes some machine learning capability

Machine learning The algorithms are general, and not really specific to computer vision

Machine learning Generally, the algorithms are trained using a large data set, and then tested against another

Machine learning There are two main ways of implementing this Supervised learning, in which the input data is labelled Unsupervised learning, where the data has no labels

Supervised learning In this method, the algorithm knows that the feature it is being trained on is either present or not present

Supervised learning It can then learn that certain characteristics are distinctive among those where the feature is present

Supervised learning For example, you can have a dataset of 10,000 images, in which 8,000 contain faces and 2,000 do not

Unsupervised learning These algorithms are referred to as clustering algorithms They are used to match up similar images, without knowledge of what is within

Training OpenCV comes with tools for training the various algorithms it supplies I'm not going to explain them here

Haar classifier This is a fairly specialized implementation of a learning algorithm

Haar classifier It is used to detect mostly rigid objects Like faces!

Haar classifier OpenCV comes with a pre trained Haar classifier capable of recognising faces within an image

Haar classifier <?php use OpenCV\Image as Image; use OpenCV\Histogram as Histogram; $i = Image::load("sailing.jpg", Image::LOAD_IMAGE_COLOR); $result = $i->haardetectobjects(" haarcascade_frontalface_default.xml"); foreach ($result as $r) { $i->rectangle($r['x'], $r['y'], $r['width'], $r['height']); } $i ->save("sailing_detected.jpg");

The input image

The result

Other features There are other interesting features of the library that I've not implemented yet, but they will be there soon

Inpainting Repairing damage to images for example stripping watermarks filling in texture after the image has been rotated To do this properly, you have to create a mask, and I've not worked out a reasonable API for that

Contour detection OpenCV can use its edge detection algorithms to find the contours of an image These are stored in a sequence, which can be iterated over

Image capture OpenCV can grab images from a camera I will now attempt to demo this...

Thanks for listening Please rate my talk! http://joind.in/2830 Get in touch mgdm@php.net http://mgdm.net @mgdm