How to Build Your First Amazon Alexa Skill

Original Source: https://www.sitepoint.com/amazon-alexa-skill/?utm_source=rss

How to Build Your First Amazon Alexa Skill

Out of the box, Alexa supports a number of built-in skills, such as adding items to your shopping list or requesting a song. However, developers can build new custom skills by using the Alexa Skill Kit (ASK).

The ASK, a collection of APIs and tools, handles the hard work related to voice interfaces, including speech recognition, text-to-speech encoding, and natural language processing. ASK helps developers build skills quickly and easily.

In short, the sole reason that Alexa can understand a user’s voice commands is that it has skills defined. Every Alexa skill is a piece of software designed to understand voice commands. Also, each Alexa skill has its own logic defined that creates an appropriate response for the voice command. To give you an idea of some existing Alexa skills, they include:

ordering pizza at Domino’s Pizza
calling for an Uber
telling you your horoscope

So as said, we can develop our own custom skills fitted to our need with the Alexa Skill Kit, a collection of APIs and tools designed for this purpose. The ASK includes tools like speech recognition, text-to-speech encoding, and natural language processing. The kit should get any developer started quickly with developing their own custom skill.

In this article, you’ll learn how to create a basic “get a fact” Alexa skill. In short, we can ask Alexa to present us with a random cat fact. The complete code for completing our task can be found on GitHub. Before we get started, let’s make sure we understand the Alexa skill terminology.

Mastering Alexa Skill Terminology

First, let’s learn how a user can interact with a custom skill. This will be important for understanding the different concepts related to skills.

In order to activate a particular skill, the user has to call Alexa and ask to open a skill. For example: “Alexa, open cat fact”. By doing this, we’re calling the invocation name of the skill. Basically, the invocation name can be seem as the name of the application.

Now that we’ve started the right skill, we have access to the voice intents/commands the skill understands. As we want to keep things simple, we define a “Get Cat Fact” intent. However, we need to provide sample sentences to trigger the intent. An intent can be triggered by many example sentences, also called utterances. For example, a user might say “Give a fact”. Therefore, we define the following example sentences:

“Tell a fact”
“Give a cat fact”
“Give a fact”

It’s even possible to combine the invocation name with an intent like this: “Alexa, ask Cat Fact to give a fact”.

Now that we know the difference between an invocation name and intent, let’s move on to creating your first Alexa skill.

Creating an Amazon Developer Account

To get started, we need an Amazon Developer Account. If you have one, you can skip this section.

Signing up for an Amazon Developer account is a three-step process. Amazon requires some personal information, accepting the terms of service, and providing a payment method. The advantage of signing up for an Amazon Developer account is that you get access to a plethora of other Amazon services. Once the signup has been successfully completed, you’ll see the Amazon Developer dashboard.

Log yourself in to the dashboard and click on the Developer Console button in the top-right corner.

Open Developer Console

Next up, we want to open the Alexa Skills Kit.

Open Alexa Skills Kit

If you were unable to open the Alexa Skills Kit, use this link.

In the following section, we’ll create our actual skill.

Creating Our First Custom Alexa Skill

Okay, we’re set to create our first custom Alexa skill. Click the blue button Create Skill to open up the menu for creating a new skill.

Create Skill Button

Firstly, it will prompt us for the name of our skill. As you already know, we want random cat facts and therefore call the skill custom cat fact (we can’t use cat fact as that’s a built-in skill for Alexa devices). Next, it prompts us to pick a model for your skill. We can choose between some predefined models or go for a custom model that gives us full flexibility. As we don’t want to be dealing with code we don’t need, we go for the Custom option.

Note: If you choose a predefined skill, you get a list of interaction models and example sentences (utterances). However, even the custom skill is equipped with the most basic intents like Cancel, Help, NavigateHome, and Stop.

Pick Skill name

Next, we need to pick a way to host our skill. Again, we don’t want to overcomplicate things and pick the Alexa-Hosted (Node.js) option. This means we don’t have to run a back end ourselves that requires some effort to make it “Alexa compliant”. It means you have to format the response according to the Amazon Alexa standards for a device to understand this. The Alexa-hosted option will:

host skills in your account up to the AWS Free Tier limits and get you started with a Node.js template. You will gain access to an AWS Lambda endpoint, 5 GB of media storage with 15 GB of monthly data transfer, and a table for session persistence.

Pick host method

Okay, now that all settings are in place, you can click the Create Skill button in the top-right corner of the screen. This button will generate the actual skill in our Amazon Developer account.

Modifying Your First Alexa Skill

Now if you navigate to the Alexa Developer Console, you’ll find your skill listed there. Click the edit button to start modifying the skill.

Modify Alexa Skill

Next, Amazon will display the build tab for the Cat Fact skill. On the left-hand side, you’ll find a list of intents that are defined for the skill. As said before, by default the Alexa Skills Kit generates a Cancel, Stop, Help, and NavigateHome intent. The first three are helpful for a user that wants to quit the skill or doesn’t know how to use it. The last one, NavigateHome, is only used for complex skills that involve multiple steps.

Interaction model

Step 1: Verify Invocation Name

First of all, let’s verify if the invocation name for the skill is correct. The name should say “custom cat fact”.

In case you change the name, make sure to hit the Save Model button on top of the page.

Invocation name

The post How to Build Your First Amazon Alexa Skill appeared first on SitePoint.

Introducing the Book of Branding, a guide for startups and beyond

Original Source: http://feedproxy.google.com/~r/abduzeedo/~3/W0_vfGyo5WU/introducing-book-branding-guide-startups-and-beyond

Introducing the Book of Branding, a guide for startups and beyond
Introducing the Book of Branding, a guide for startups and beyond

AoiroStudioNov 12, 2019

It’s always inspiring to see our friends, from the industry, creating and making cool stuff to inspire others. It’s a reward that we will never take for granted and we will will always be supporting. We are featuring the book release of our dear friend Radim Malinic and his Book of Branding. For short, it’s an essential guide to the startup toolkit — a guide designed for entrepreneurs, founders, designers, brand creators and anyone seeking to decode the complicated world of brand identity design. With the industry shift to product design and interface design, some designers nowadays forgot the little notion of graphic design like branding for example. This is right fitted time for Radim’s new endeavour and we took the liberty to share a sneak peek. Give it a look!

Book of Branding aims to show designers how to get the information you need to understand the project and make it the best it can be; as well as providing those on the client-side with advice on how to get the best out of the creatives you’re working with.

Book of Branding – Sneak Peek

Introducing the Book of Branding, a guide for startups and beyondIntroducing the Book of Branding, a guide for startups and beyondIntroducing the Book of Branding, a guide for startups and beyondIntroducing the Book of Branding, a guide for startups and beyondIntroducing the Book of Branding, a guide for startups and beyondIntroducing the Book of Branding, a guide for startups and beyondIntroducing the Book of Branding, a guide for startups and beyondIntroducing the Book of Branding, a guide for startups and beyondIntroducing the Book of Branding, a guide for startups and beyondBook of Branding by Radim Malinic

Brand Nu book titles are available from online stores and high street book retailers in the UK and worldwide.

November Universe by Brand Nu
Amazon
Book depository
Foyles
Waterstones
Blackwell Books
Wordery
About Radim Malinic

Radim Malinic is a creative director and designer living and working in South West London. He is the founder of Brand Nu®, an award-winning branding and creative studio working across a broad spectrum of clients. From individuals and emerging startups all the way to multinational corporates, Brand Nu combines visually rich design, creativity and strategy in its work for the big brands of the future.

At the break of the new millennium, Malinic moved to the UK to explore the expansive music scene, only to find even an even greater interest in art and graphic design. Since then his eclectic interests have seen him working with some of the biggest brands, companies and bands in the world. Clients include Harry Potter Platform 9 3/4, 007 Store, Coca Cola, Google, Adobe Systems, WWF and USAID, among many others.

Brandnu.co.uk
Bookofideas.co.uk


8 Bad Graphic Design Mistakes You DON’T Want To Make

Original Source: http://feedproxy.google.com/~r/Designrfix/~3/46q9EHrMTQk/bad-graphic-design

Nothing stands out more than a glaring design fail. A company’s success can rise and fall on the visual branding done by its hired graphic designers. In a fast-paced business world, one mistake can make an entire campaign implode.  Companies want to have faith their graphic designers know how to prevent a crisis. If you want […]

The post 8 Bad Graphic Design Mistakes You DON’T Want To Make appeared first on designrfix.com.

Epic phone deal includes a FREE Nintendo Switch or 4K TV!

Original Source: http://feedproxy.google.com/~r/CreativeBloq/~3/c7TM-WFdoZk/epic-phone-deal-includes-a-free-nintendo-switch-or-4k-tv

Who wants a free Nintendo Switch games console or Toshiba 4K HDR TV, as well as a new phone? Yes, you really can get all of this with EE's stunning deal, which just goes to show that the best Black Friday deals are already appearing. 

The phones you can get are the Samsung Galaxy A80, A70 or A40 or a Huawei P30 Lite, Huawei P30 Pro or Huawei P smart. Sign up for one of these right now through EE and you could be enjoying a nice new shiny games console or a super-sharp pixel perfect screen in your living room very soon. 

These deals offer some of the best phones around, some of them even made it our best camera phones post. With prices starting from as little as £28 a month these deals are not to be missed. They all include 10GB of data and there's no upfront cost on selected phones.

To help you make the right choice quickly and easily we have broken down these must-see Samsung and Huawei deals. Find the one for you below.

Huawei phone deals + free Nintendo Switch or 4K TV
Samsung phone deals + free Nintendo Switch or 4K TV

Not quite what you're after? Check out some more smartphone deals below. 

Read more:

Amazon Black Friday: when to get the best dealsThe best laptop deals in 2019How do you use your mobile phone at work?

40+ Tools to Supercharge Your Instagram Account

Original Source: https://www.hongkiat.com/blog/instagram-tools-mobile-apps/

With 1 billion monthly active users and 50% daily active users, Instagram is more than a popular social media platform: it’s a powerful marketing platform for every brand worldwide — big…

Visit hongkiat.com for full content.

Exciting New Tools for Designers, November 2019

Original Source: https://www.webdesignerdepot.com/2019/11/exciting-new-tools-for-designers-november-2019/

You’re sure to find some tools and resources that will help you save time as we enter what is often one of the most hectic seasons of the year. Here’s what’s new for designers this month.

Screen Size Map

Screen Size Map is a tool to showcase popular screen sizes and will even auto-detect yours. Map sizes by device type, usage, size, and popularity. This can really come in handy when thinking about viewports or breakpoints in design projects. You might also be surprised to see what screen sizes are the most (or least) popular.

Lordicon

Lordicon is a collection of free and premium animated icons in GIF and JSON formats. Each icon has a fun line style and can be customized to match your color palette. You can also adjust size, stroke width, and animation player type — automatic, hover, click, or morph. Every icon is scalable and compatible with all major browsers. This is a fun animated icon kit for projects built on the Lottie engine.

Free Bootstrap Templates and Themes

Free Bootstrap Templates and Themes is a library of free (and premium!) design elements to jumpstart projects using Designmodo’s Startup App. These tools are great starters that you can use as is, or edit in the app to create landing pages, SaaS, admin pages, presentations, and e-commerce websites.

Inspect This Snake

Inspect This Snake is a fun goodie by Matthew Rayfield. Go ahead click it and play around. You might even learn something about how he put it all together.

FYI: Free Resources for Freelancers

FYI: Free Resources for Freelancers is a collection of tools to connect all the apps for sharing and storing information. It works as a Chrome extension and allows you to connect all your free tools for better workflows. “With FYI every document you’ve created and that’s been shared with you will be accessible in just a few clicks. Your documents will be automatically organized so you won’t be checking each app and account to find what you’re looking for. They’ll all be in one place.”

Spectrum

Spectrum is Adobe’s design system and the company recently released these components and tools to the public. You can even use the Spectrum CSS, which is open source, in conjunction with the guidelines from Adobe. Even if you don’t plan to use it, this is a neat look into the design system and how Adobe thinks about the look and feel of its products. (And while it doesn’t look all that detailed at first glance, the system is rather extensive.)

Dashdash

Dashdash is a spreadsheet tool that allows you to access business data and APIs, send emails, and more with a traditional spreadsheet online. You don’t need to code to design tools and information. Plus, it integrates with other tools to make your work easier.

Can You Draw a Perfect Circle?

Can You Draw a Perfect Circle? is a browser-based game that you might find yourself obsessing over. (I really wanted to draw a perfect circle, but it never happens.)

Open Doodles

Open Doodles is an animated collection of hand-drawn illustrations for projects in SVG, PNG, and GIF formats. Use the generator to change the colors and styles to create a semi-custom pack.

Claro

Claro is a nifty to-do app that’s open to invites. It features a simple design that’s supposed to be distraction free so that you focus on things you need to get done, not the design of the tool.

Tartan Patterns

Tartan Patterns is a collection of more than 5,000 repeating SVG and PNG images. (Seems like the perfect pattern for fall.) Everything is grouped by name in alphabetical order. Warning: It is easy to get lost in looking at all the patterns.

Blocke: Social Web UI Kit

Blocke: Social Web UI Kit is a set of 30 components designed for social feeds. The freebie is a preview for a bigger set if you like what you see.

CursorOS

CursorOS is a Figma-read (Sketch coming soon) collection of original macOS cursors that you can use in design systems, projects, user flows, UI kits, prototypes, and more.

Tutorial: Designing Accessible Color Systems

Designing Accessible Color Systems is a look at how Stripe has worked to improve color contrast and accessibility in its design projects. The lesson is reflective of recent changes to the brand’s color palette to make it more accessible. It’s a good lesson in modern color theory.

Izmir Hover Effects

Izmir Hover Effects is a mini CSS library that helps you create customer effects. Load the library to your project, add the element markup and style classes, and you are ready to go.

8b

8b is a website builder based on Google AMP. Use it to create modern designs on a fast, responsive template. It’s free to build on and includes plenty of templates for quick builds. You can also link a domain and every site includes SSL/HTTPS.

Hexometer

Hexometer uses artificial intelligence to scan over 2,800 data points on your website to make sure your digital assets are in pristine condition. It will also give you tips and tricks on how to improve your website hygiene.

FontPairings.ByPeople

FontPairings.ByPeople allows you to pop pairs of fonts onto the screen with just a click to see how they look on different website theme templates. Swap headings and text elements and mix and match pairs to find a typography palette that appeals to you.

Antique Cherry

Antique Cherry is a lovely novelty script with nice lines and great curves. It’s available for personal and non-profit use and includes a full character set.

Glitch Esports

Glitch Esports combines two trending elements, glitching design and esports in a single typeface. Try it for a fun display option.

Grifter Bold

Grifter Bold is a round versatile font in all caps and lowercase that can work great for display options. (Only the bold version is free.) It includes a full character and number set with some extra glyphs.

Les Paul

Les Paul is a fun novelty display font with lots of options to create interesting combinations of text elements. All of the characters are uppercase and there is a small fee for commercial use.

Recursive

Recursive is a variable font in beta that will soon be added to the Google Fonts collection. It includes a sans and mono option and is a five-axis variable font. Use predefined styles or adjust proportion, monospace, weight, slant, and italic to take full advantage of the variable font technology. Everything is in one font file.

Salveation Serif

Salveation Serif is a nice display, uppercase font with fun lines and a vintage feel. The font includes letters, numerals, and unlimited punctuation.

Source

p img {display:inline-block; margin-right:10px;}
.alignleft {float:left;}
p.showcase {clear:both;}
body#browserfriendly p, body#podcast p, div#emailbody p{margin:0;}

The Best jQuery Plugins & Effects That Are Still Useful in 2019

Original Source: http://feedproxy.google.com/~r/1stwebdesigner/~3/2O6PzBMEYFE/

If you’re coding with JavaScript, jQuery should be one of the first things you install. The lightweight JavaScript library optimizes and simplifies core features like Ajax handling, animation, event handling, and HTML document transversal – in other words, it makes working with JavaScript a lot easier.

Many developers have released plugins built on the jQuery framework for free. These can add key features and effects to your website, including autocomplete, file upload, or image zooming.

Ready to install cool effects and awesome jQuery plugins? Here are some of the best libraries you’re sure to love.

Your Web Designer Toolbox
Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets


DOWNLOAD NOW

fancybox

Example of fancybox

This lightbox plugin can display various types of media in a beautiful darkened popup. Besides images and videos, it also accepts custom content like Google Maps and can resize to fit them. Plus, it’s easily extensible with a little CSS and JavaScript knowledge. It’s free to use in open source projects, or commercially with a license.

jQuery File Upload

Example of jQuery File Upload

If you need to add file upload functionality to your site, this little widget has everything. You can upload any type of file with unlimited file size, and even drop them right into the browser.

fullPage.js

Example of fullPage.js

Looking for a quick and easy way to create a one-page, scrolling, full-screen website? All the tutorials are here to help you get this library set up and working, with in-depth explanations for every option. Open source projects can use it for free.

Tiny Slider

Example of Tiny Slider

This library may be called Tiny Slider, but it includes dozens of demos, each with its own unique functionality. Fixed widget, vertical, even lazy loading sliders; test out each demo until you find the one you want.

Select2

Example of Select2

Is the default HTML select box not doing it for you? Select2 implements an easily customizable, extremely extensible dropdown select box including pages and pages of helpful documentation.

Ajax AutoComplete for jQuery

Example of Ajax AutoComplete for jQuery

If you need to add an autocompleting text box to your website, this lightweight file is the way to go. It takes up practically no space, yet provides advanced autocomplete functionality.

Flotcharts

Example of Flotcharts

This is more than just a simple chart plugin. While it’s easy to use thanks to the API documentation, it also comes with advanced functionality like real-time plotting and beautiful aesthetics.

pickadate.js

Example of pickadate.js

Responsive and customizable, pickadate.js makes creating a date or time selection box as easy as installing this lightweight plugin. Check out the API documentation to customize it even further.

jQuery Zoom

Example of jQuery Zoom

Image zooming is no longer a hassle with this jQuery plugin. Install the files and assign it to an image, then hover or click to zoom in. It’s easy as that.

SortableJS

Example of SortableJS

Sortable lists made easy. Drag and drop to reorder lists you define, with features like cloning, multi-list, or image grids included. For a simple concept, this is a pretty complex library.

jQuery Knob

Example of jQuery Knob

Compatible with mouse, keyboard, and mobile controls, these draggable dials will work on almost any platform. There are all kinds of dials built in that turn and count in various ways.

iCheck

Example of iCheck

Light, accessible, and supported on most devices and browsers, iCheck is perfect if you need to implement checkboxes or radio buttons. It comes with 6 beautiful skins built in which you can easily customize with CSS.

DataTables

Example of DataTables

Tables are never easy to deal with, but DataTables makes it a total breeze. Just load it up and put in a single function, and you’ll instantly generate a table on your site. Then you can add pages, search, sorting, and more. Plus, it supports both themes and extensions.

Save Time with jQuery Plugins

With web development, there’s no reason to reinvent the wheel. These jQuery plugins and effects have already done all the work for you. All you need to do is paste some code in, and you’ll be able to enhance your site with shiny new features.

Most of these plugins are totally free to use. Implement them into your sites and extend them for your own designs, and shave off what could have been days of programming work.


How to Apply Instagram Filters on Web Images

Original Source: https://www.hongkiat.com/blog/instagram-filters-on-web-images/

Many love using Instagram and the filters that come with the app, to make their photos more interesting and beautiful. So far though, the use of these filters are restricted to use inside the app….

Visit hongkiat.com for full content.

11 Portable Batteries for Your MacBook — Best of

Original Source: https://www.hongkiat.com/blog/macbook-portable-battery/

If you love working in a cafe or library — like me — or a co-working space with fewer power outlets, you require extra juice for your MacBook. Why? Although MacBook Pro promises “10…

Visit hongkiat.com for full content.

Face Detection and Recognition with Keras

Original Source: https://www.sitepoint.com/keras-face-detection-recognition/?utm_source=rss

Face Detection and Recognition with Keras

If you’re a regular user of Google Photos, you may have noticed how the application automatically extracts and groups faces of people from the photos that you back up to the cloud.

Face Recognition in the Google Photos web applicationFace Recognition in the Google Photos web application

A photo application such as Google’s achieves this through the detection of faces of humans (and pets too!) in your photos and by then grouping similar faces together. Detection and then classification of faces in images is a common task in deep learning with neural networks.

In the first step of this tutorial, we’ll use a pre-trained MTCNN model in Keras to detect faces in images. Once we’ve extracted the faces from an image, we’ll compute a similarity score between these faces to find if they belong to the same person.

Prerequisites

Before you start with detecting and recognizing faces, you need to set up your development environment. First, you need to “read” images through Python before doing any processing on them. We’ll use the plotting library matplotlib to read and manipulate images. Install the latest version through the installer pip:

pip3 install matplotlib

To use any implementation of a CNN algorithm, you need to install keras. Download and install the latest version using the command below:

pip3 install keras

The algorithm that we’ll use for face detection is MTCNN (Multi-Task Convoluted Neural Networks), based on the paper Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks (Zhang et al., 2016). An implementation of the MTCNN algorithm for TensorFlow in Python3.4 is available as a package. Run the following command to install the package through pip:

pip3 install mtcnn

To compare faces after extracting them from images, we’ll use the VGGFace2 algorithm developed by the Visual Geometry Group at the University of Oxford. A TensorFlow-based Keras implementation of the VGG algorithm is available as a package for you to install:

pip3 install keras_vggface

While you may feel the need to build and train your own model, you’d need a huge training dataset and vast processing power. Since this tutorial focuses on the utility of these models, it uses existing, trained models by experts in the field.

Now that you’ve successfully installed the prerequisites, let’s jump right into the tutorial!

Step 1: Face Detection with the MTCNN Model

The objectives in this step are as follows:

retrieve images hosted externally to a local server
read images through matplotlib’s imread() function
detect and explore faces through the MTCNN algorithm
extract faces from an image.

1.1 Store External Images

You may often be doing an analysis from images hosted on external servers. For this example, we’ll use two images of Lee Iacocca, the father of the Mustang, hosted on the BBC and The Detroit News sites.

To temporarily store the images locally for our analysis, we’ll retrieve each from its URL and write it to a local file. Let’s define a function store_image for this purpose:

import urllib.request

def store_image(url, local_file_name):
with urllib.request.urlopen(url) as resource:
with open(local_file_name, ‘wb’) as f:
f.write(resource.read())

You can now simply call the function with the URL and the local file in which you’d like to store the image:

store_image(‘https://ichef.bbci.co.uk/news/320/cpsprodpb/5944/production/_107725822_55fd57ad-c509-4335-a7d2-bcc86e32be72.jpg’,
‘iacocca_1.jpg’)
store_image(‘https://www.gannett-cdn.com/presto/2019/07/03/PDTN/205798e7-9555-4245-99e1-fd300c50ce85-AP_080910055617.jpg?width=540&height=&fit=bounds&auto=webp’,
‘iacocca_2.jpg’)

After successfully retrieving the images, let’s detect faces in them.

1.2 Detect Faces in an Image

For this purpose, we’ll make two imports — matplotlib for reading images, and mtcnn for detecting faces within the images:

from matplotlib import pyplot as plt
from mtcnn.mtcnn import MTCNN

Use the imread() function to read an image:

image = plt.imread(‘iacocca_1.jpg’)

Next, initialize an MTCNN() object into the detector variable and use the .detect_faces() method to detect the faces in an image. Let’s see what it returns:

detector = MTCNN()

faces = detector.detect_faces(image)
for face in faces:
print(face)

For every face, a Python dictionary is returned, which contains three keys. The box key contains the boundary of the face within the image. It has four values: x- and y- coordinates of the top left vertex, width, and height of the rectangle containing the face. The other keys are confidence and keypoints. The keypoints key contains a dictionary containing the features of a face that were detected, along with their coordinates:

{‘box’: [160, 40, 35, 44], ‘confidence’: 0.9999798536300659, ‘keypoints’: {‘left_eye’: (172, 57), ‘right_eye’: (188, 57), ‘nose’: (182, 64), ‘mouth_left’: (173, 73), ‘mouth_right’: (187, 73)}}

1.3 Highlight Faces in an Image

Now that we’ve successfully detected a face, let’s draw a rectangle over it to highlight the face within the image to verify if the detection was correct.

To draw a rectangle, import the Rectangle object from matplotlib.patches:

from matplotlib.patches import Rectangle

Let’s define a function highlight_faces to first display the image and then draw rectangles over faces that were detected. First, read the image through imread() and plot it through imshow(). For each face that was detected, draw a rectangle using the Rectangle() class.

Finally, display the image and the rectangles using the .show() method. If you’re using Jupyter notebooks, you may use the %matplotlib inline magic command to show plots inline:

def highlight_faces(image_path, faces):
# display image
image = plt.imread(image_path)
plt.imshow(image)

ax = plt.gca()

# for each face, draw a rectangle based on coordinates
for face in faces:
x, y, width, height = face[‘box’]
face_border = Rectangle((x, y), width, height,
fill=False, color=’red’)
ax.add_patch(face_border)
plt.show()

Let’s now display the image and the detected face using the highlight_faces() function:

highlight_faces(‘iacocca_1.jpg’, faces)

Detected face in an image of Lee IacoccaDetected face in an image of Lee Iacocca. Source: BBC

Let’s display the second image and the face(s) detected in it:

image = plt.imread(‘iacocca_2.jpg’)
faces = detector.detect_faces(image)

highlight_faces(‘iacocca_2.jpg’, faces)

The Detroit NewsThe Detroit News

In these two images, you can see that the MTCNN algorithm correctly detects faces. Let’s now extract this face from the image to perform further analysis on it.

1.4 Extract Face for Further Analysis

At this point, you know the coordinates of the faces from the detector. Extracting the faces is a fairly easy task using list indices. However, the VGGFace2 algorithm that we use needs the faces to be resized to 224 x 224 pixels. We’ll use the PIL library to resize the images.

The function extract_face_from_image() extracts all faces from an image:

from numpy import asarray
from PIL import Image

def extract_face_from_image(image_path, required_size=(224, 224)):
# load image and detect faces
image = plt.imread(image_path)
detector = MTCNN()
faces = detector.detect_faces(image)

face_images = []

for face in faces:
# extract the bounding box from the requested face
x1, y1, width, height = face[‘box’]
x2, y2 = x1 + width, y1 + height

# extract the face
face_boundary = image[y1:y2, x1:x2]

# resize pixels to the model size
face_image = Image.fromarray(face_boundary)
face_image = face_image.resize(required_size)
face_array = asarray(face_image)
face_images.append(face_array)

return face_images

extracted_face = extract_face_from_image(‘iacocca_1.jpg’)

# Display the first face from the extracted faces
plt.imshow(extracted_face[0])
plt.show()

Here is how the extracted face looks from the first image.

Extracted and resized face from first imageExtracted and resized face from first image

The post Face Detection and Recognition with Keras appeared first on SitePoint.