How To Train A Face Recognition In Python And Opencv



Similar documents
A secure face tracking system

Introduction to OpenCV for Tegra. Shalini Gupta, Nvidia

Additional details >>> HERE <<<

International Journal of Advanced Information in Arts, Science & Management Vol.2, No.2, December 2014

Affdex SDK for Windows!

Automatic License Plate Recognition using Python and OpenCV

C# and Other Languages

Benchmarking the LBPH Face Recognition Algorithm with OpenCV and Python

Android and OpenCV Tutorial

ST 810, Advanced computing

Mobile Development with Qt

Analysis Programs DPDAK and DAWN

Rapid Game Development Using Cocos2D-JS

Copyright 2014, SafeNet, Inc. All rights reserved.

TEGRA X1 DEVELOPER TOOLS SEBASTIEN DOMINE, SR. DIRECTOR SW ENGINEERING

Processing Large Amounts of Images on Hadoop with OpenCV

Computer Vision. License Plate Recognition Klaas Dijkstra - Jaap van de Loosdrecht

LOCAL SURFACE PATCH BASED TIME ATTENDANCE SYSTEM USING FACE.

Computer Vision Technology. Dave Bolme and Steve O Hara

Rapid Access Cloud: Se1ng up a Proxy Host

Navigation Aid And Label Reading With Voice Communication For Visually Impaired People

Android Ros Application

sudo add-apt-repository ppa:ubuntu-sdk-team/ppa sudo apt update && sudo apt install ubuntu-sdk

KIVY - A Framework for Natural User Interfaces

Introducing the Adafruit Bluefruit LE Sniffer

Embedded Based Web Server for CMS and Automation System

CS 40 Computing for the Web

In: Proceedings of RECPAD th Portuguese Conference on Pattern Recognition June 27th- 28th, 2002 Aveiro, Portugal

Main Bullet #1 Main Bullet #2 Main Bullet #3

Availability of the Program A free version is available of each (see individual programs for links).

Splunk for.net Developers

Raspberry Pi Android Projects. Raspberry Pi Android Projects. Gökhan Kurt. Create exciting projects by connecting Raspberry Pi to your Android phone

Illumination, Expression and Occlusion Invariant Pose-Adaptive Face Recognition System for Real- Time Applications

:Introducing Star-P. The Open Platform for Parallel Application Development. Yoel Jacobsen E&M Computing LTD

Develop a Hello World project in Android Studio Capture, process, store, and display an image. Other sensors on Android phones

DIY Device Cloud Documentation

Template-based Eye and Mouth Detection for 3D Video Conferencing

Collaborative Open Market to Place Objects at your Service

Native code in Android Quad Detection

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

Web Services for Management Perl Library VMware ESX Server 3.5, VMware ESX Server 3i version 3.5, and VMware VirtualCenter 2.5

Exercise 0. Although Python(x,y) comes already with a great variety of scientic Python packages, we might have to install additional dependencies:

Apache Thrift and Ruby

QML and JavaScript for Native App Development

INTRODUCTION TO JAVA PROGRAMMING LANGUAGE

Final Year Project Interim Report

Android: How To. Thanks. Aman Nijhawan

GR Framework / MODBUS on Raspberry Pi

The Most Popular UI/Apps Framework For IVI on Linux

Cassandra Installation over Ubuntu 1. Installing VMware player:

Crosswalk: build world class hybrid mobile apps

KonyOne Server Installer - Linux Release Notes

Bob Rathbone Computer Consultancy

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

How To Program With Adaptive Vision Studio

Tutorial on Client-Server Communications

A Real Time Driver s Eye Tracking Design Proposal for Detection of Fatigue Drowsiness

Camera Sensor Driver Development And Integration

PaperlessPrinter. Version 3.0. User s Manual

Instruction Manual. Applied Vision is available for download online at:

Beyond THE Blinky LED: Voice recognition, Face recognition and cloud connectivity for IOT Edge devices

IE Class Web Design Curriculum

KonyOne Server Prerequisites _ MS SQL Server

OpenCV on Android Platforms

Automatic Network Bandwidth Control Application for Linux-based Internet Connections

Mobile Labs Plugin for IBM Urban Code Deploy

BSc in Computer Engineering, University of Cyprus

Android, Bluetooth and MIAC

Using Real Time Computer Vision Algorithms in Automatic Attendance Management Systems

Web-based Hybrid Mobile Apps: State of the Practice and Research Opportunities

APPLICATION NOTE. Getting Started with pylon and OpenCV

ROBOTRACKER A SYSTEM FOR TRACKING MULTIPLE ROBOTS IN REAL TIME. by Alex Sirota, alex@elbrus.com

How To Develop Android On Your Computer Or Tablet Or Phone

Research and Design of Universal and Open Software Development Platform for Digital Home

Net/FSE Installation Guide v1.0.1, 1/21/2008

Full version is >>> HERE <<<

Rebuild Perfume With Python and PyPI

Network Analysis with ArcGIS for Server

Generate Android App

CS1112 Spring 2014 Project 4. Objectives. 3 Pixelation for Identity Protection. due Thursday, 3/27, at 11pm

An Energy-Based Vehicle Tracking System using Principal Component Analysis and Unsupervised ART Network

Automated Attendance Management System using Face Recognition

Tool - 1: Health Center

Introduction to Android Programming (CS5248 Fall 2015)

CPSC 226 Lab Nine Fall 2015

Lazy OpenCV installation and use with Visual Studio

What We Learned From Porting 50+ Cloud Apps to Tizen. Dima Malenko, Vlad Pavlov, rollapp Inc.

globus online Integrating with Globus Online Steve Tuecke Computation Institute University of Chicago and Argonne National Laboratory

Monitis Project Proposals for AUA. September 2014, Yerevan, Armenia

research: technical implemenation

Transcription:

TRAINING DETECTORS AND RECOGNIZERS IN PYTHON AND OPENCV Sept. 9, 2014 ISMAR 2014 Joseph Howse

GOALS Build apps that learn from p h o to s & f r o m real-time camera input. D e te c t & recognize the faces of humans & cats.

GETTING STARTED

TERMINOLOGY This tutorial covers detection and recognition not to be confused with tracking. Detect Find the location of some type of object in an image. I detect that this region of the image is a human face. Recognize Determine the subtype or the unique identity of a detected object. I recognize that this human face is a male face. I recognize that this human face is Joe Howse s face. Track Determine whether the same detected object is present in consecutive images and, if so, how it moved. I tracked this face in images 1 and 2; it moved from here to there.

WHY OPENCV? Mid-level API Developer chooses algorithms and types of I/O Library provides (semi-)optimized implementations Multi-lingual C++, C, Python, Java Cross-platform Windows, Mac, Linux, BSD, ios, Android Well supported on ARM Linux I have used it on Raspberry Pi (Raspbian) and Odroid U3 (Lubuntu). (Semi-)optimized TBB (x86, amd64, ARM), CUDA, OpenCL, Tegra 3+ Some functions are optimized; others are not.

SETUP

PROJECT FILES Angora Blue My set of demo applications for face detection and recognition https://bitbucket.org/joe_howse/angora-blue https://bitbucket.org/joe_howse/angora-blue/downloads Three databases of images 1. VOC2007 dataset 10,000 annotated images of diverse subjects 2. Caltech Faces 1999 450 images of upright, frontal human faces 3. Microsoft Cat Dataset 2008 10,000 annotated images of cat faces in various orientations A download script for the databases is in Angora Blue: cascade_training/download_datasets.sh

DEPENDENCIES Python 2.7 A multi-paradigm scripting language NumPy 1.8 A math library for fast array operations with Pythonic syntax OpenCV 2.4 A computer vision library with lots of algorithms and I/O features OpenCV Python treats images as NumPy arrays. WxPython 2.8, 2.9, or 3.0 A GUI library, wrapping native GUI libraries on each platform

WINDOWS Download and run the following binary installers (either 32-bit or 64-bit, depending on your needs): Python 2.7 https://www.python.org/download NumPy 1.8 http://sourceforge.net/projects/numpy/files/numpy/1.8.1 OpenCV 2.4 http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.9 or build from source for options such as Kinect support WxPython 3.0 http://www.wxpython.org/download.php

MAC Use the MacPorts package manager. http://www.macports.org/install.php Optionally, configure MacPorts to use my OpenCV repository, which adds Kinect support. http://nummist.com/opencv/ports.tar.gz $ sudo port install python27 python_select py27-numpy $ sudo port select python python27 $ sudo port install opencv +python27 +tbb or other variants, such as the following: $ sudo port install opencv +python27 +tbb +openni $ sudo port install opencv +python27 +tbb +openni_sensorkinect $ sudo port install wxpython-3.0

UBUNTU, DEBIAN, RASPBIAN, ETC. $ sudo apt-get install python-opencv or build from source for options such as Kinect support. Example: http://nummist.com/opencv/install_opencv_debian_wheezy.sh $ sudo apt-get install python-wxgtk2.8

WORKING WITH IMAGES, CAMERAS, AND GUIS

BASIC IMAGE I/O IN OPENCV Read image from camera: cameraid = 0 # Default camera capture = cv2.videocapture(cameraid) didsucceed, image = capture.read() The captured image is always in BGR (not RGB or gray) format. For optimized RGB or gray capture, use low-level camera libraries instead. I like this Python wrapper for Video for Linux 2 (v4l2): https://github.com/gebart/python-v4l2capture/blob/master/capture_picture.py Read image from file: image = cv2.imread('input.png') Write image to file: cv2.imwrite('output.png, image)

OPENCV IMAGES IN WX GUIS Run OpenCV stuff on background thread; wx on main thread threading.thread class and wx.callafter function Demo: InteractiveRecognizer.py init, _runcapturelook, and _onclosewindow methods Convert images from numpy.array to wx.staticbitmap wx.bitmapfrombuffer function but this function is buggy on Raspberry Pi Fall back to wx.imagefrombuffer and wx.bitmapfromimage functions Demo: utils.py wxbitmapfromcvimage function

DETECTING FACES

AVAILABLE DETECTION MODELS OpenCV supports several types of detectors, including these two: 1. Haar cascade relatively reliable Detects light-to-dark edges, corners, and lines at multiple scales http://docs.opencv.org/trunk/doc/py_tutorials/py_objdetect/ py_face_detection/py_face_detection.html#basics 2. Local binary pattern (LBP) relatively fast Detects light-to-dark gradients at multiple scales http://docs.opencv.org/modules/contrib/doc/facerec/ facerec_tutorial.html#local-binary-patterns-histograms Both types use data stored in XML files. Neither type can detect rotated or flipped objects.

USING A PRE-TRAINED DETECTOR OpenCV comes with XML files for many pre-trained detectors Human face frontal, profile, eyes, eyeglasses, nose, mouth Human body upper, lower, whole Other silverware, Russian license plates Basic usage: detector = cv2.cascadeclassifier('haarcascade_eye.xml') detectedobjects = detector.detectmultiscale(image) for x, y, width, height in detectedobjects: # Do something for each object detectmultiscale has important optional arguments: http://docs.opencv.org/modules/objdetect/doc/ cascade_classification.html#cascadeclassifier-detectmultiscale Demo: InteractiveRecognizer.py: init and _detectandrecognize methods InteractiveHumanFaceRecognizer.py

TRAINING A CUSTOM DETECTOR OpenCV provides a pair of command line tools to generate XML files for Haar or LBP detectors 1. opencv_createsamples or opencv_createsamples.exe 2. opencv_traincascade or opencv_traincascade.exe http://docs.opencv.org/doc/user_guide/ug_traincascade.html Among other parameters, they require text files listing negative and positive training images (e.g. non-faces and faces). Demo: cascade_training/train.sh or cascade_training/train.bat The resulting XML file is used in InteractiveCatFaceRecognizer.py.

NEGATIVE TRAINING IMAGES Gather 1000s of images that do not contain faces. List the image paths in a text file. Demo: cascade_training/ negative_description.txt Preprocessing: 1. Convert to grayscale cv2.cvtcolor 2. Equalize (adjust contrast) cv2.equalizehist Demo: cascade_training/ describe.py describenegativehelper function

POSITIVE TRAINING IMAGES Gather 1000s of images containing faces. List the image paths and face coordinates in a text file. Demo: cascade_training/ positive_description.txt Preprocessing: 1. Convert to grayscale cv2.cvtcolor 2. Straighten cv2.getrotationmatrix2d cv2.warpaffine 3. Crop numpy.array slicing crop = image[y:y+h, x:x+w] 4. Equalize (adjust contrast) cv2.equalizehist Demo: cascade_training/ describe.py preprocesscatface function

PREPROCESSING: REFERENCE POINTS To straighten & crop, we need reference points. A person places them manually for each image! The Cat Dataset defines 8 reference points. We use points 4 & 9 to compute face size and 1 & 2 to compute face rotation and center.

PREPROCESSING: CONVERT TO GRAY, STRAIGHTEN, CROP, EQUALIZE Before Can I haz atan2? After

PREPROCESSING: CONVERT TO GRAY, STRAIGHTEN, CROP, EQUALIZE Before After My ears mock your rectangle.

RECOGNIZING FACES

AVAILABLE RECOGNITION MODELS OpenCV supports three types of recognizers: 1. Eigenfaces relatively reliable Recognizes differences from the average face http://docs.opencv.org/trunk/modules/contrib/doc/facerec/ facerec_tutorial.html#eigenfaces 2. Fisherfaces also relatively reliable Also recognizes differences from the average face http://docs.opencv.org/trunk/modules/contrib/doc/facerec/ facerec_tutorial.html#fisherfaces 3. Local binary pattern histograms (LBPH) relatively fast Detects light-to-dark gradients at multiple scales Can learn new faces one-by-one in real time http://docs.opencv.org/modules/contrib/doc/facerec/ facerec_tutorial.html#local-binary-patterns-histograms All types use data stored in XML files. None of the types can detect rotated or flipped objects.

TRAINING AND USING A RECOGNIZER 1. Create a recognizer: recognizer = cv2.createlbphfacerecognizer() # or Fisher or Eigen 2. Train a recognizer: trainingimages = [joe0, joe1, sam0, sam1] traininglabels = numpy.array([0, 0, 1, 1]) recognizer.train(trainingimages, traininglabels) 3. Get a recognition result: testlabel, distance = recognizer.predict(testimage) 4. Update an LBPH recognizer with more training images: # Only LBPH supports updates. recognizer.update(moretrainingimages, moretraininglabels) 5. Save and re-load a recognizer recognizer.save('peopleiknow.xml') recognizer.load('peopleiknow.xml') Demo: InteractiveRecognizer.py init, _detectandrecognize, _updatemodel, _onclosewindow methods

FURTHER READING

MY BOOKS Howse, J. OpenCV Computer Vision with Python. Packt Publishing, 2013. A brief introduction to OpenCV with Python Includes integration with NumPy, SciPy, OpenNI, & SensorKinect Howse, J. Android Application Programming with OpenCV. Packt Publishing, 2013. A brief introduction to OpenCV with Android Howse, J. OpenCV for Secret Agents. Packt Publishing, forthcoming. Intermediate to advanced OpenCV projects using Python, Raspberry Pi, Android, & other gadgets Analyze images of real estate, cats, gestures, cars, heartbeats, & more. Preorder & early access: http://cdn1.cf.packtpub.com/opencv-for-secret-agents/book

OTHER BOOKS Baggio, D. L. et al. Mastering OpenCV with Practical Computer Vision Projects. Packt Publishing, 2012. Intermediate to advanced OpenCV projects using C++ Includes advanced chapters on human face detection, tracking, and recognition Laganière, R. OpenCV 2 Computer Vision Application Programming Cookbook. Packt Publishing, 2011. Concise code samples in C++ for many popular algorithms

PAPER Zhang, W., Sun, J., and Tang, X. Cat Head Detection - How to Effectively Exploit Shape and Texture Features, Proc. of European Conf. Computer Vision, vol. 4, pp. 802-816, 2008. http://research.microsoft.com/pubs/80582/eccv_cat_proc.pdf

WEBSITES Python 2.7 docs https://docs.python.org/2 NumPy docs http://docs.scipy.org/doc/numpy/reference OpenCV docs http://docs.opencv.org WxPython docs http://wiki.wxpython.org Support site for my books http://nummist.com/opencv Abid Rahman K. s OpenCV Python blog http://opencvpython.blogspot.com KittyDar: A cat detector in JavaScript http://harthur.github.io/kittydar

DISCUSSION Let us reflect on what we have learned.