人脸检测python_使用Python的传统人脸检测

人脸检测python

Computer vision is an exciting and growing field. There are tons of interesting problems to solve! One of them is face detection: the ability of a computer to recognize that a photograph contains a human face, and tell you where it is located. In this article, you’ll learn about face detection with Python.

计算机视觉是一个令人兴奋且不断发展的领域。 有很多有趣的问题要解决! 其中之一是面部检测:计算机识别照片中包含人脸并告诉您其位置的能力。 在本文中,您将学习使用Python进行面部检测。

To detect any object in an image, it is necessary to understand how images are represented inside a computer, and how that objects differs visually from any other object.

要检测图像中的任何对象,必须了解计算机内图像的表示方式,以及这些对象在视觉上与任何其他对象的区别。

Once that is done, the process of scanning an image and looking for those visual cues needs to be automated and optimized. All these steps come together to form a fast and reliable computer vision algorithm.

一旦完成,扫描图像并寻找那些视觉线索的过程就需要自动化和优化。 所有这些步骤共同构成了一种快速可靠的计算机视觉算法。

In this tutorial you’ll learn:

在本教程中,您将学习:

  • What face detection is
  • How computers understand features in images
  • How to quickly analyze many different features to reach a decision
  • How to use a minimal Python solution for detecting human faces in images
  • 什么是人脸检测
  • 计算机如何理解图像中的功能
  • 如何快速分析许多不同功能以做出决定
  • 如何使用最小的Python解决方案来检测图像中的人脸

Free Bonus: Click here to get the Python Face Detection & OpenCV Examples Mini-Guide that shows you practical code examples of real-world Python computer vision techniques.

免费红利: 单击此处以获得Python人脸检测和OpenCV示例迷你指南 ,该指南向您展示了现实世界中Python计算机视觉技术的实用代码示例。

什么是面部检测? (What Is Face Detection?)

Face detection is a type of computer vision technology that is able to identify people’s faces within digital images. This is very easy for humans, but computers need precise instructions. The images might contain many objects that aren’t human faces, like buildings, cars, animals, and so on.

人脸检测是一种计算机视觉技术,能够识别数字图像中的人脸。 对于人类来说这很容易,但是计算机需要精确的指令。 图像可能包含许多不是人脸的对象,例如建筑物,汽车,动物等。

It is distinct from other computer vision technologies that involve human faces, like facial recognition, analysis, and tracking.

它不同于涉及人脸的其他计算机视觉技术,例如面部识别,分析和跟踪。

Facial recognition involves identifying the face in the image as belonging to person X and not person Y. It is often used for biometric purposes, like unlocking your smartphone.

面部识别涉及将图像中的面部识别为属于人X而不属于人Y。它通常用于生物识别目的,例如解锁智能手机。

Facial analysis tries to understand something about people from their facial features, like determining their age, gender, or the emotion they are displaying.

面部分析试图从人们的面部特征中了解某些事物,例如确定他们的年龄,性别或所表现出的情感。

Facial tracking is mostly present in video analysis and tries to follow a face and its features (eyes, nose, and lips) from frame to frame. The most popular applications are various filters available in mobile apps like Snapchat.

面部跟踪主要出现在视频分析中,并试图从一帧到另一帧跟踪面部及其特征(眼睛,鼻子和嘴唇)。 最受欢迎的应用是Snapchat等移动应用中可用的各种过滤器。

All of these problems have different technological solutions. This tutorial will focus on a traditional solution for the first challenge: face detection.

所有这些问题都有不同的技术解决方案。 本教程将重点关注第一个挑战的传统解决方案:面部检测。

计算机如何“看到”图像? (How Do Computers “See” Images?)

The smallest element of an image is called a pixel, or a picture element. It is basically a dot in the picture. An image contains multiple pixels arranged in rows and columns.

图像的最小元素称为像素或图片元素。 它基本上是图片中的一个点。 图像包含以行和列排列的多个像素。

You will often see the number of rows and columns expressed as the image resolution. For example, an Ultra HD TV has the resolution of 3840×2160, meaning it is 3840 pixels wide and 2160 pixels high.

您通常会看到以图像分辨率表示的行数和列数。 例如,超高清电视的分辨率为3840×2160,这意味着它的宽度为3840像素,高度为2160像素。

But a computer does not understand pixels as dots of color. It only understands numbers. To convert colors to numbers, the computer uses various color models.

但是计算机无法将像素理解为颜色的点。 它只了解数字。 要将颜色转换为数字,计算机使用各种颜色模型。

In color images, pixels are often represented in the RGB color model. RGB stands for Red Green Blue. Each pixel is a mix of those three colors. RGB is great at modeling all the colors humans perceive by combining various amounts of red, green, and blue.

在彩色图像中,像素通常以RGB颜色模型表示。 RGB代表对于Rģ略。 每个像素是这三种颜色的混合。 RGB非常适合通过组合各种数量的红色,绿色和蓝色来模拟人类感知的所有颜色。

Since a computer only understand numbers, every pixel is represented by three numbers, corresponding to the amounts of red, green, and blue present in that pixel. You can learn more about color spaces in Image Segmentation Using Color Spaces in OpenCV + Python.

由于计算机只能理解数字,因此每个像素都由三个数字表示,分别对应于该像素中存在的红色,绿色和蓝色的数量。 您可以在使用OpenCV + Python中的颜色空间的图像分割中了解有关颜色空间的更多信息。

In grayscale (black and white) images, each pixel is a single number, representing the amount of light, or intensity, it carries. In many applications, the range of intensities is from 0 (black) to 255 (white). Everything between 0 and 255 is various shades of gray.

在灰度(黑白)图像中,每个像素都是一个数字,代表其承载的光量或强度。 在许多应用中,强度范围是从0 (黑色)到255 (白色)。 0255之间的所有内容都是各种灰色阴影。

If each grayscale pixel is a number, an image is nothing more than a matrix (or table) of numbers:

如果每个灰度像素都是一个数字,则图像只不过是一个数字矩阵(或表格):

Example of pixel values in a 3x3 grayscale image
Example 3×3 image with pixel values and colors
示例3×3具有像素值和颜色的图像

In color images, there are three such matrices representing the red, green, and blue channels.

在彩色图像中,存在三种表示红色,绿色和蓝色通道的矩阵。

什么是功能? (What Are Features?)

A feature is a piece of information in an image that is relevant to solving a certain problem. It could be something as simple as a single pixel value, or more complex like edges, corners, and shapes. You can combine multiple simple features into a complex feature.

特征是图像中与解决特定问题有关的一条信息。 它可以是简单的单个像素值,也可以是复杂的边缘,角和形状。 您可以将多个简单功能组合为一个复杂功能。

Applying certain operations to an image produces information that could be considered features as well. Computer vision and image processing have a large collection of useful features and feature extracting operations.

将某些操作应用于图像会产生也可以视为特征的信息。 计算机视觉和图像处理具有大量有用的功能和功能提取操作。

Basically, any inherent or derived property of an image could be used as a feature to solve tasks.

基本上,图像的任何固有或派生属性都可以用作解决任务的功能。

制备 (Preparation)

To run the code examples, you need to set up an environment with all the necessary libraries installed. The simplest way is to use conda.

要运行代码示例,您需要设置一个安装了所有必需库的环境。 最简单的方法是使用conda

You will need three libraries:

您将需要三个库:

  1. scikit-image
  2. scikit-learn
  3. opencv
  1. scikit-image
  2. scikit-learn
  3. opencv

To create an environment in conda, run these commands in your shell:

要在conda创建环境,请在您的shell中运行以下命令:

 $ conda create --name face-detection $ conda create --name face-detection pythonpython == 3.
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值