Python face_recognition 库人脸识别/匹配教程

face_recognition库的使用 ​ face_recognition库基于dlib的使用,包含dlib的安装,及face_recognition库各个方法的使用 阅读详情
AI摘要

本文详细介绍了如何在Python中使用face_recognition库进行人脸检测,包括单人和多人图片的处理,以及面部特征识别和人脸匹配功能。教程涵盖了安装依赖、基本操作和示例代码,适合初学者入门。

在本教程中,我将解释 Python face_recognition 库的设置和使用。该库可用于使用 Python 检测人脸并识别面部特征。


目标

在本教程中,我将介绍 Python face_recognition 库的一些示例用法:

  • 检测图像中的人脸
  • 在检测到的脸上检测面部特征(如眉毛和鼻子)
  • 检查检测到的人脸是否匹配

这篇文章提供了所有图像和代码片段,以及有关正在发生的事情的分步说明和解释。本教程针对 Windows 10,但 Linux 和 macOS 用户很可能会发现这更容易,因为他们可以跳过一些先决条件。

如果您需要/想要它们,以下是 face_recognition 的一些相关链接:

安装“face_recognition”库

先决条件 (Windows)

要在 Windows 上安装 face_recognition 库,您需要安装以下内容:

  • 制作
  • Visual Studio C++ 构建工具

如果你没有这些,你会得到这样的错误,

CMake must be installed to build the following extensions: _dlib_pybind11

这告诉你没有安装 CMake,或者,

You must use Visual Studio to build a python extension on windows.  If you
are getting this error it means you have not installed Visual C++.  Note
that there are many flavours of Visual Studio, like Visual Studio for C#
development.  You need to install Visual Studio for C++.

这告诉您您需要 Visual Studio C++ 构建工具。

制作

要安装 CMake,请转到cmake.org/download/并下载适合您机器的安装程序。我使用的是 64 位 Windows 10,所以我会得到cmake-<version>-win64-x64.msi. 下载安装文件后,安装它。

在安装 CMake 时,将 CMake 添加到所有用户或当前用户的系统 PATH 环境变量中,以便轻松找到它。

 

安装完成后,打开终端并执行cmake。这应该显示 CMake 的用法。如果没有,请确保您选择了将其添加到 PATH 环境变量的选项。

您需要关闭并重新打开终端/应用程序以更新 PATH 变量,以便cmake识别二进制文件。

Visual Studio C++ 构建工具

与 Linux 不同,操作系统中默认不包含适用于 Windows 的 C++ 编译器。如果我们访问 Python wiki 上的 WindowsCompilers 页面,我们可以看到有关获取独立版本的 Visual C++ 14.2 编译器而无需 Visual Studio 的信息。如果我们访问该wiki 部分的链接,我们将被带到 Microsoft 下载页面。在此下载页面上,您需要下载“Visual Studio 2019 的构建工具”。

当vs_buildtools__<some other stuff>.exe下载完成,运行exe并允许它之前,我们得到下面的屏幕安装的几件事情。当您到达此屏幕时,请进行我的选择:

 

单击“安装”后,等待安装完成并重新启动。

现在安装了 CMake 和所需的构建工具,我们可以继续安装 face_recognition 库。

安装 face_recognition 并验证安装

要安装 face_recognition 库,请在终端中执行以下操作:

python -m pip install face-recognition

这可能需要比平时更长的时间来安装,因为 dlib 需要使用从上面安装的工具来构建。要验证库是否已成功安装,请尝试使用以下命令在 Python 中导入库:

import face_recognition

不应引发任何错误。

安装 PIL

在本教程中,我们还将使用Pillow / PIL 来帮助我们裁剪和绘制图像。这不是使用 face_recognition 库所必需的,但在本教程中需要以证明/显示结果。要安装它,请执行以下操作:

python -m pip install Pillow

要验证库是否已安装,请尝试使用以下命令在 Python 中导入 PIL:

import PIL

不应引发任何错误。

检测图像中的人脸

现在我们已经设置了 face_recognition 库和 PIL,我们现在可以开始检测人脸了。首先,我们将在只有一个人的图像中检测人脸。

 

单人.jpg

首先,我们要从 PIL 导入 face_recognition 和一些助手。

import face_recognition
from PIL import Image, ImageDraw

现在使用face_recognition.load_image_file.

image = face_recognition.load_image_file('single-person.jpg')

image现在以 face_recognition 可以检测人脸的格式包含我们的图像。要识别此图像中人脸的位置,请调用face_recognition.face_locations并传递图像。

face_locations = face_recognition.face_locations(image)

face_locations现在将包含面部位置列表。每个人脸位置都是一个像素位置元组(top, right, bottom, left)- 我们需要记住这一点,以便我们以后使用它。

由于此图像中只有一张脸,因此我们希望此列表中只有一个项目。要检查检测到多少人脸,我们可以获取列表的长度。

amount = len(face_locations)
print(f'There are {amount} face locations')

对于我在上面提供并用于本教程的示例图像,这告诉我检测到一张脸。

为了以后使用这个面的位置,我们可以只从列表中取出第一个元素。

first_face_location = face_locations[0]

要查看其中的内容,您可以调用:

print(first_face_location)

这将打印出如下内容:

(400, 1221, 862, 759)

这些是(top, right, bottom, left)我们将用于创建框和裁剪的像素位置。

识别检测到的人脸

为了识别图像中检测到的人脸的位置,我们将在由 返回的边界上绘制一个红色框face_recognition.face_locations。

首先,我们需要从使用加载的图像创建一个 PIL 图像face_recognition.load_image_file。这样做将允许我们使用 PIL 提供的功能。

img = Image.fromarray(image, 'RGB')

现在我们有了 PIL 图像,我们需要创建一个对象来帮助我们在图像上绘制。在我们这样做之前,我们还将把图像复制到一个新对象中,这样当我们以后裁剪脸部时,它周围就不会再有一个红色框了。

img_with_red_box = img.copy()
img_with_red_box_draw = ImageDraw.Draw(img_with_red_box)

现在我们有一个对象可以帮助我们在图像上绘制,我们将使用之前返回的尺寸绘制一个矩形。

要绘制一个框,我们需要两个点,左上角和右下角作为 x 和 y 坐标。既然我们回来了(top, right, bottom, left),我们就需要做这些(left, top), (right, bottom);基本翻译如下。

img_with_red_box_draw.rectangle(
    [
        (first_face_location[3], first_face_location[0]),
        (first_face_location[1], first_face_location[2])
    ],
    outline="red",
    width=3
)

我们需要(left, top), (right, bottom)得到 (x, y) (x, y) 点。

在该步骤中,我们还设置outline="red"了使框为红色width=3并使框为 3 像素宽。

要查看最终结果,我们调用:

img_with_red_box.show()

这将在默认图像查看器中打开图像。图像应如下所示:

 

裁剪出检测到的人脸

除了绘制一个框外,我们还可以将人脸裁剪成另一幅图像。

使用我们没有绘制的原始图像(因为我们在复制的图像上绘制),我们可以调用img.crop提供之前的尺寸。

img_cropped = img.crop((
    first_face_location[3],  # Left x
    first_face_location[0],  # Top y
    first_face_location[1],  # Right x
    first_face_location[2]   # Bottom y
))

img.crop 返回正在复制的原始图像的副本,因此如果您想对原始图像执行其他操作,则无需事先复制。

img_cropped现在包含一个新的裁剪图像,要显示它,我们可以.show()再次调用。

img_cropped.show()

 

本节的最终代码

import face_recognition
from PIL import Image, ImageDraw

# Detecting the faces
image = face_recognition.load_image_file('single-person.jpg')  # Load the image
face_locations = face_recognition.face_locations(image)  # Detect the face locations
first_face_location = face_locations[0]  # Get the first face

# Convert the face_recognition image to a PIL image
img = Image.fromarray(image, 'RGB')

# Creating the image with red box
img_with_red_box = img.copy()  # Create a copy of the original image so there is not red box in the cropped image later
img_with_red_box_draw = ImageDraw.Draw(img_with_red_box)  # Create an image to draw with
img_with_red_box_draw.rectangle(  # Draw the rectangle on the image
    [
        (first_face_location[3], first_face_location[0]),  # (left, top)
        (first_face_location[1], first_face_location[2])  # (right, bottom)
    ],
    outline="red",  # Make the box red
    width=3  # Make the box 3px in thickness
)
img_with_red_box.show()  # Open the image in the default image viewer

# Creating the cropped image
img_cropped = img.crop((  # Crop the original image
    first_face_location[3],
    first_face_location[0],
    first_face_location[1],
    first_face_location[2]
))
img_cropped.show()  # Open the image in the default image viewer

检测图像中的多张人脸

我们之前看到它face_recognition.face_locations返回一个与人脸位置对应的元组数组。这意味着我们可以使用与上面相同的方法,但循环face_recognition.face_locations绘制和裁剪时的结果。

我将使用以下作为我的形象。它有 5 个可见的面,其中 2 个略微模糊。

 

一群人.jpg

再一次,我们想从 PIL 导入 face_recognition 和一些助手。

import face_recognition
from PIL import Image, ImageDraw

然后使用face_recognition.load_image_file与以前相同的方法加载新图像并检测人脸。

image = face_recognition.load_image_file('group-of-people.jpg')
face_locations = face_recognition.face_locations(image)

如果我们打印出face_locations( print(face_locations)),我们可以看到已经检测到了5张脸。

[
    (511, 1096, 666, 941),
    (526, 368, 655, 239)
    (283, 1262, 390, 1154),
    (168, 1744, 297, 1615),
    (271, 390, 378, 282)
]

由于我们现在有多个面,取第一个没有意义——我们应该遍历它们并在循环中执行我们的操作。

在我们继续之前,我们还应该创建我们将使用的 PIL 图像。

img = Image.fromarray(image, 'RGB')

识别检测到的人脸

像以前一样,我们需要复制原始图像以备后用(可选)并创建一个对象来帮助我们绘制。

img_with_red_box = img.copy()
img_with_red_box_draw = ImageDraw.Draw(img_with_red_box)

现在我们可以循环所有面并创建矩形。

for face_location in face_locations:
    img_with_red_box_draw.rectangle(
        [
            (face_location[3], face_location[0]),
            (face_location[1], face_location[2])
        ],
        outline="red",
        width=3
    )

再一次,看看图像:

img_with_red_box.show()

 

不错诶!

裁剪检测到的人脸

就像绘制许多框一样,我们也可以裁剪所有检测到的人脸。再次使用 for 循环,在每个循环中裁剪图像,然后显示图像。

for face_location in face_locations:
    img_cropped = img.crop((face_location[3], face_location[0], face_location[1], face_location[2]))
    img_cropped.show()

您将在您的机器上在单独的窗口中打开许多图像;在这里,他们都在一起:

  

一群人裁剪的脸 2

 

一群人裁剪的脸 3

 

一群人裁剪的脸 4

 

一群人裁剪的脸 5

我已经为教程缩小了这些图像的尺寸,但您的图像将以您输入的任何分辨率进行裁剪。

本节的最终代码

import face_recognition
from PIL import Image, ImageDraw

# Load image and detect faces
image = face_recognition.load_image_file("group-of-people.jpg")
face_locations = face_recognition.face_locations(image)

# Create the PIL image to copy and crop
img = Image.fromarray(image, 'RGB')

img_with_red_box = img.copy()  # Make a single copy for all the red boxes
img_with_red_box_draw = ImageDraw.Draw(img_with_red_box)  # Get our drawing object again
for face_location in face_locations:  # Loop over all the faces detected this time
    img_with_red_box_draw.rectangle(  # Draw a rectangle for the current face
        [
            (face_location[3], face_location[0]),
            (face_location[1], face_location[2])
        ],
        outline="red",
        width=3
    )
img_with_red_box.show()  # Open the image in the default image viewer

for face_location in face_locations:  # Loop over all the faces detected
    img_cropped = img.crop((  # Crop the current image like we did last time
        face_location[3],
        face_location[0],
        face_location[1],
        face_location[2]
    ))
    img_cropped.show()  # Show the image for the current iteration

识别面部特征

face_recognition 也有一个函数face_recognition.face_landmarks,它的工作原理类似,face_recognition.face_locations但会返回一个包含人脸特征位置的字典列表,而不是检测到的人脸本身的位置。

回到只有一个人的图像,我们可以再次导入所有内容,加载图像并调用face_recognition.face_landmarks.

import face_recognition
from PIL import Image, ImageDraw

image = face_recognition.load_image_file('single-person.jpg')
face_landmarks_list = face_recognition.face_landmarks(image)  # The new call

现在如果我们打印face_landmarks_list,对象看起来会有点不同。

[
    {
        'chin': [(315, 223), (318, 248), (321, 273), (326, 296), (335, 319), (350, 339), (370, 354), (392, 365), (415, 367), (436, 363), (455, 351), (469, 336), (479, 318), (486, 296), (488, 273), (490, 251), (489, 229)],
        'left_eyebrow': [(329, 194), (341, 183), (358, 180), (375, 182), (391, 189)],
        'right_eyebrow': [(434, 189), (448, 184), (461, 182), (474, 184), (483, 194)],
        'nose_bridge': [(411, 209), (411, 223), (412, 238), (412, 253)],
        'nose_tip': [(394, 269), (403, 272), (412, 275), (421, 272), (428, 269)],
        'left_eye': [(349, 215), (360, 208), (373, 207), (384, 216), (372, 218), (359, 219)],
        'right_eye': [(436, 216), (446, 208), (458, 208), (467, 216), (459, 219), (447, 219)],
        'top_lip': [(374, 309), (388, 300), (402, 296), (411, 298), (420, 296), (434, 301), (448, 308), (442, 308), (420, 307), (411, 308), (402, 307), (380, 309)],
        'bottom_lip': [(448, 308), (434, 317), (421, 321), (411, 322), (401, 321), (388, 317), (374, 309), (380, 309), (402, 309), (411, 310), (421, 309), (442, 308)]
    }
]

这里有很多东西。对于每个面部特征(即下巴、左眉、右眉等),相应的列表包含 x 和 y 元组 - 这些 x 和 y 点是图像上的 x 和 y 坐标。

PIL 为.line()我们一直使用的绘图对象提供了一种方法,它采用 x 和 y 点列表,非常适合这种情况。首先,我们需要一个绘图对象。

img = Image.fromarray(image, 'RGB')  # Make a PIL image from the loaded image
img_draw = ImageDraw.Draw(img)  # Create the draw object

在这个例子中,我们不会复制图像,因为这是我们唯一一次使用它

现在我们有了帮助我们绘制的对象,使用上面返回的列表中的第一个字典绘制所有这些线。

face_landmarks = face_landmarks_list[0]  # Get the first dictionary of features
img_draw.line(face_landmarks['chin'])
img_draw.line(face_landmarks['left_eyebrow'])
img_draw.line(face_landmarks['right_eyebrow'])
img_draw.line(face_landmarks['nose_bridge'])
img_draw.line(face_landmarks['nose_tip'])
img_draw.line(face_landmarks['left_eye'])
img_draw.line(face_landmarks['right_eye'])
img_draw.line(face_landmarks['top_lip'])
img_draw.line(face_landmarks['bottom_lip'])

现在我们可以调用.show()我们的图像来查看它:

img_draw.show()

 

本节的最终代码

import face_recognition
from PIL import Image, ImageDraw

# Load the image and detect face landmarks for each face within
image = face_recognition.load_image_file('single-person.jpg')
face_landmarks_list = face_recognition.face_landmarks(image)

# Make a PIL image from the loaded image and then get a drawing object
img = Image.fromarray(image, 'RGB')
img_draw = ImageDraw.Draw(img)

# Draw all the features for the first face
face_landmarks = face_landmarks_list[0]  # Get the first object corresponding to the first face
img_draw.line(face_landmarks['chin'])
img_draw.line(face_landmarks['left_eyebrow'])
img_draw.line(face_landmarks['right_eyebrow'])
img_draw.line(face_landmarks['nose_bridge'])
img_draw.line(face_landmarks['nose_tip'])
img_draw.line(face_landmarks['left_eye'])
img_draw.line(face_landmarks['right_eye'])
img_draw.line(face_landmarks['top_lip'])
img_draw.line(face_landmarks['bottom_lip'])

img_with_face_landmarks.show()  # Show the image for the current iteration

匹配检测到的人脸

face_recognition 库还提供了face_recognition.compare_faces可用于比较检测到的人脸以查看它们是否匹配的功能。

我们将使用此函数的两个参数:

  • known_face_encodings:已知人脸编码列表
  • face_encoding_to_check:要与列表进行比较的单个人脸编码

在本节中,我们将为同一个人获取 2 个面部编码,并检查它们是否在另一张图像中。

以下是两张图片,每张图片中都有一张已知人脸:

 

 

elon-musk-1.jpg elon-musk-2.png

以下是我们将检查 Elon 是否在其中的图像:

 

 

elon-musk-in-group.jpg group-of-people.jpg

获取人脸编码

要获得已知的人脸编码,我们可以使用face_recognition.face_encodings. 此函数获取包含要使用的人脸和图像中人脸位置的图像。

通常,您只会使用一张图像中人脸的一个位置来创建一种编码,但如果您在一张图像中有多个相同的人脸,则可以提供多个位置。

我们需要做的来获得我们已知的人脸编码的过程是:

  1. 加载第一张图片
  2. 检测图像中的人脸以获取人脸位置
  3. 验证只有一个面并选择第一个面
  4. face_recognition.face_encodings使用图像和单人脸位置调用
  5. 对第二个图像重复 1 到 5

我们之前已经完成了步骤 1-3,所以我们可以在这里再次执行:

import face_recognition

# Load image and detect faces
image = face_recognition.load_image_file("elon-musk-1.jpg")
face_locations = face_recognition.face_locations(image)

并验证检测到一张脸:

print(len(face_locations))  # Should be 1

现在我们可以调用face_recognition.face_encodings并提供图像和找到的位置。

face_location = face_locations[0]  # We only want an encoding for the first face. There may be more than one face in images you use so I am leaving this here as a note.
face_encodings = face_recognition.face_encodings(image, [face_location])

该参数known_face_locations是可选的,如果known_face_locations未提供,face_recognition 将在获取人脸编码时自动检测图像中的所有人脸。对于这一部分,我将通过这种方式进行演示,以验证图像中仅检测到一张人脸。

由于我们指定了一个数组known_face_locations,我们知道将只返回一个编码,因此我们可以采用第一个。

elon_musk_knwon_face_encoding_1 = face_encodings[0]

我们现在可以对另一个图像重复这个过程

image = face_recognition.load_image_file("elon-musk-2.png")  # Load the image
face_locations = face_recognition.face_locations(image)  # Get face locations
face_location = face_locations[0]  # Only use the first detected face

face_encodings = face_recognition.face_encodings(image, [face_location])  # Get all face encodings
elon_musk_knwon_face_encoding_2 = face_encodings[0]  # Pull out the one returned face encoding

现在我们有了elon_musk_knwon_face_encoding_1和elon_musk_knwon_face_encoding_2,我们可以看看它们是否存在于我们的另外两个图像中。

检查匹配

要检查图像中的匹配项face_recognition.compare_faces,我们需要已知的人脸编码(我们刚刚在上面获得)和要检查的单个人脸编码。

由于我们正在处理一组图像,我们将不得不循环检测到的人脸——尽管这也适用于图像中只有一个人的情况。

首先,我们需要从要比较的第一张图像中获取所有面部解码。我在上面已经注意到第二个参数 , known_face_locationstoface_recognition.face_encodings是可选的,省略它会自动检测图像中的所有面部并返回图像中每个面部的面部编码;这正是我们想要的,并将删除检测人脸的中间步骤。

image = face_recognition.load_image_file("elon-musk-in-group.jpg")  # Load the image we are comparing
unknwon_face_encodings = face_recognition.face_encodings(image)  # Get face encodings for everyone in the image

现在我们有了组图像中所有人脸的未知人脸编码,我们可以遍历它们并检查是否匹配:

for unknwon_face_encoding in unknwon_face_encodings:
    matches = face_recognition.compare_faces(
        [elon_musk_knwon_face_encoding_1, elon_musk_knwon_face_encoding_2],  # The known face encodings (can be only 1 - less is faster)
        unknwon_face_encoding  # The single unknown face encoding
    )
    print(matches)

如果你运行这个,你会看到类似的东西:

[True, True]
[False, False]
[False, False]
[False, False]

每行是一个比较(存储在 中matches),每个布尔值对应一个已知的人脸编码以及它是否与未知的人脸编码匹配。

从上面的值,我们可以看到组图像中的第一个未知人脸与已知人脸编码都匹配,而其他三个未知人脸与任何一个编码都不匹配。使用多次面部编码可以让您计算出更好的概率,但会降低速度。

如果你在另一个图像上运行这个,一切都会返回 false。

本节的最终代码

import face_recognition


# Load elon-musk-1.jpg and detect faces
image = face_recognition.load_image_file("elon-musk-1.jpg")
face_locations = face_recognition.face_locations(image)

# Get the single face encoding out of elon-musk-1.jpg
face_location = face_locations[0]  # Only use the first detected face
face_encodings = face_recognition.face_encodings(image, [face_location])
elon_musk_knwon_face_encoding_1 = face_encodings[0]  # Pull out the one returned face encoding


# Load elon-musk-2.jpg and detect faces
image = face_recognition.load_image_file("elon-musk-2.png")
face_locations = face_recognition.face_locations(image)

# Get the single face encoding out of elon-musk-2.jpg
face_location = face_locations[0]
face_encodings = face_recognition.face_encodings(image, [face_location])
elon_musk_knwon_face_encoding_2 = face_encodings[0]


# Load the image with unknown to compare
image = face_recognition.load_image_file("elon-musk-in-group.jpg")  # Load the image we are comparing
unknwon_face_encodings = face_recognition.face_encodings(image)

# Loop over each unknwon face encoding to see if the face matches either known encodings
print('Matches for elon-musk-in-group.jpg')
for unknwon_face_encoding in unknwon_face_encodings:
    matches = face_recognition.compare_faces(
        [elon_musk_knwon_face_encoding_1, elon_musk_knwon_face_encoding_2],  # The known face encodings (can be only 1 - less is faster)
        unknwon_face_encoding  # The single unknown face encoding
    )
    print(matches)


# Load the other image with unknown to compare
image = face_recognition.load_image_file("group-of-people.jpg")  # Load the image we are comparing
unknwon_face_encodings = face_recognition.face_encodings(image)

# Loop over each unknwon face encoding to see if the face matches either known encodings
print('Matches for group-of-people.jpg')
for unknwon_face_encoding in unknwon_face_encodings:
    matches = face_recognition.compare_faces(
        [elon_musk_knwon_face_encoding_1, elon_musk_knwon_face_encoding_2],
        unknwon_face_encoding
    )
    print(matches)

其他 PIL 帮助

本教程不关注 PIL,但您可能会发现有用的一个功能是img.save();这将保存一个文件。其用法的一个示例是img.save('my_image.png')将 PIL 图像保存到 my_image.png。

你可以在它的文档中找到更多关于 PIL 的信息,还有很多其他的在线帮助,因为它是一个非常古老的图书馆。

[已解决]win10&Ubuntu中dlib库安装(python3.8) win10&Ubuntu安装dlib报错python3.8,缺少wheel 阅读详情

相关推荐

【人脸识别(三)】:使用face_recognition库实现人脸识别,python实现

目录 前言 安装face_recognition库 人脸检测和人脸轮廓检测 人脸比对 检测视频中的人脸 人脸识别 视频中人脸识别 CNN模型与CUDA加速人脸检测 使用命令窗识别人脸 使用命令窗调整容忍度 使用命令窗显示人脸之间的匹配度/距离 使用命令窗只输出人名 使用命令窗控制CPU核数 小结 前言 人脸识别(二)https://blog.csdn.net/...

qq_39709813的博客 1万+

face_recognition基础接口

face_recognition使用世界上最简单的人脸识别库,在Python或命令行中识别和操作人脸。 使用dlib最先进的人脸识别技术构建而成,并具有深度学习功能。 该模型在Labeled Faces in the Wild基准中的准确率为99.38%。 face_recognition 官方文档:https://pypi.org/project/face_recognition/    1|1查找图片中的面孔    1 2 3 4 5...

haoji007的博客 5093

face_recognition人脸识别

face_recognition人脸识别 face_recognition简介 这是世界上最简单的人脸识别库了。你可以通过Python引用或者命令行的形式使用它,来管理和识别人脸。 该软件包使用dlib中最先进的人脸识别深度学习算法,使得识别准确率在《Labled Faces in the world》测试基准下达到了99.38%。它同时提供了一个叫face_recognition的命令行工具,以...

matafeiyanll的博客 6505

[深度学习] Python人脸识别库face_recognition使用教程

Python人脸识别库face_recognition使用教程 face_recognition号称是世界上最简单的开源人脸识别库,可以通过Python或命令行识别和操作人脸。face_recognition提供了十分完整的技术文档和应用实例,人脸识别初学者建议研究该库上手。face_recognition的官方代码仓库为:face_recognition。face_recognition也有自己的官方中文文档,该文档详情见:face_recognition中文使用说明。 本文所有的代码和大部分测试图像来自

You and Me 4万+

face_recognition(人脸识别)

是一个非常流行的 Python 库,专门用于人脸识别任务。它基于 dlib 库和 HOG(Histogram of Oriented Gradients)特征以及深度学习模型,提供了简单易用的接口来进行人脸检测、面部特征点定位和人脸识别。库由 Adam Geitgey 开发,旨在简化人脸识别任务,使其更加容易上手。

m0_73723097的博客 4272

好玩的人脸识别face_recognition安装+尝试+API详细

face_recognition是一个可玩度很高的人脸识别开源框架,不仅安装方便,运行起来也很轻松。 官网:https://github.com/ageitgey/face_recognition.git 以下我将按标题分享以下我的畅玩经历: 1、安装 cuda和cudnn 机器视觉必备,这个不过多赘述。 anaconda2或3 anaconda在官网即可下载:https:/...

weixin_39002448的博客 1万+

基于Python的人脸识别(Python 3.12+face_recognition库)

在这个教程中,我们将学习如何使用Python和库来加载图像、提取人脸编码,并比较两个人脸是否相似。库是一个强大的工具,它基于dlib的深度学习模型,可以轻松实现人脸检测和识别功能。本教程适合初学者,我们将通过一个简单的项目来了解这个库的基本用法和环境配置。

F2022697486的博客 7392

Python简易的人脸识别库之face_recognition使用详解

随着人工智能和机器学习技术的发展,人脸识别技术在安防、社交媒体、智能家居等领域得到了广泛应用。Python的face_recognition库是一个简单易用的人脸识别库,基于dlib的深度学习模型,能够高效地进行人脸检测和识别。本文将详细介绍face_recognition库,包括其安装方法、主要特性、基本和高级功能,以及实际应用场景,帮助全面了解并掌握该库的使用。

Rocky006的博客 1780

Face_recognition实现人脸识别

本文基于face_recognition库实现图像人脸识别,下面将介绍如何安装face_recognition库,并细述3个常用的人脸识别案例。

鲸落寰宇 3660

Python最短代码实现人脸识别,打造自己专用人脸识别!

对于类似于人脸的对象,你或许需要不少于 6000个分类器,每一个都需要成功匹配(当然,有容错率),才能检测出人脸。但这有一个问题:对于人脸识别,算法从左上角开始计算一个个数据块,不停问“这是张脸吗”。每个数据块有超过 6000个检测,加起来的计算量会达到数百万级别,计算机很可能会让你等得花儿都谢了。在这里还是要推荐下我自己建的Python开发学习群:483546416,群里都是学Python开发的...

qq_41766361的博客 2万+

人脸识别 face_recognition

Github开源人脸识别项目face_recognition,face_recognition是一个强大、简单、易上手的人脸识别开源项目 安装 pip install face_recognition 导入face_recognition模块 import face_recognition load_image_file 加载图像 调用face_recognition.load_image_file()读入图像。输出图像是rgb格式(opencv中是bgr格式) import face_recog

我不是码农的博客~~~ 1275

python实现人脸识别(face_recognition)

本项目是世界上最强大、简洁的人脸识别库,你可以使用Python和命令行工具提取、识别、操作人脸。本项目的人脸识别是基于业内领先的C++开源库dlib中的深度学习模型,用Labeled Faces in the Wild人脸数据集进行测试,有高达99.38%的准确率。但对小孩和亚洲人脸的识别准确率尚待提升。

创作不易,请多支持,将为本站提供更多「有价值的文章」。 1万+

分析方法—temporal receptive field(TRF)

总结来说,时间感受野其实就是一个 filter!课程中的描述—.(使用时间感受野与刺激进行卷积来描述)时间感受野一般是听觉计算中使用的,在视觉中,有另一种分析叫做空间感受野(spatial receptive fields)。回归权重(Regression weights)是指在回归分析中用于估计自变量与因变量之间关系的权重或系数。回归分析是一种统计方法,用于建立自变量与因变量之间的关联模型,并通过拟合数据来估计模型中的参数。在简单线性回归中,只有一个自变量与一个因变量之间的关系被建模。

m0_51474171的博客 1621

Python使用face_recognition库实现人脸识别案例

本项目使用face_recognition库编写一个简单的python程序,实现人脸识别。这个库是基于深度学习技术,希望尽量用最方便最简单的方式实现人脸识别,只要使用一张图片进行训练就能从大量的人脸数据找到验证者对应的身份,准确率达96%。face_recognition是一个人脸识别开源库,是在深度学习框架dlib上做的整合。通过 Python 语言将它封装为一个非常简单就可以实现人脸识别的 API 库,屏蔽了人脸识别的算法细节,大大降低了人脸识别功能的开发难度。 关于face_recogniti....

lyx4949的博客 5120

从标记基因到功能分析:手把手教你人工注释单细胞亚群的完整流程

本文详细介绍了人工注释单细胞亚群的完整流程,从标记基因筛选到功能分析验证,特别针对肿瘤微环境、发育轨迹等复杂场景提供解决方案。通过差异表达分析、多维数据整合和实验验证,帮助研究者准确识别细胞类型,提升单细胞转录组研究的生物学解读深度。

jenkins8butler的博客 256

QT快速配置MSVC2017编译环境(3分钟极简指南)

本文提供了一份3分钟极简指南,帮助开发者快速配置QT的MSVC2017编译环境。通过断网安装、精准勾选组件和配置QT Creator编译器路径等步骤,大幅提升QT开发效率。MSVC2017作为Windows平台高性能C++编译器,特别适合处理大型QT项目,编译速度优势明显。

weixin_30399821的博客 512

python face_recognition实现人脸识别系统

face_recognition是最简单的人脸识别库。它是一个 Python 库,用于进行人脸检测、识别和特征提取。它基于 dlib 库,提供了一个简单易用的接口,可以帮助开发者快速构建人脸识别应用。

m0_61229395的博客 4807

仪表数字图像识别的传统方法

虽然现有很多机器学习算法能够准确地识别数字,但是传统方法对于一些需要离线识别且计算能力有限的下位机设备来说,仍然有非常不错的效果。因此,今天就向大家讲解一下传统的数字识别方法在仪表读数方面的应用。 1.图像预处理技术 1.1 主要流程 图像处理依次需要进行图片预处理、字轮区域定位、字符分割和字符识别等过程。其中图像处理流程如下图所示。 2. 详细过程 2.1 灰度化 为了减小图像原始数据量,本系...

XYZ 4528

从零开始人脸识别:face-recognition库

人脸识别教程 本章利用face-recognition库进行图片、视频端的人脸识别 环境:win10,python3.6,dlib19.8.1,face_recognition1.2.2 第一步:安装dlib19.8.1,face_recognition1.2.2 1.安装dlib19.8.1 安装包链接:https://pypi.org/simple/dlib/ 下载完成之后,c...

LJW的博客 1万+

GB28181协议心跳机制:从标准解读到代码实现的保活策略

本文深入解析GB28181协议中的心跳机制,从标准解读到代码实现,详细介绍了保活策略的核心价值和底层逻辑。通过实战案例和技术要点,帮助开发者优化心跳间隔、超时次数等参数配置,提升安防监控系统的可靠性和性能。文章还提供了代码实现的防坑指南和特殊场景处理建议,适用于各类网络环境下的设备在线状态管理。

weixin_29611239的博客 114

PCL 点云配准-ICP算法(精配准)

ICP(Iterative Closest Point)算法是一种常用的点云精细配准算法。它通过迭代计算将一组点云变换到另一组点云的最佳位置,最终实现精确的对齐。ICP算法在每次迭代中选择与目标点云最接近的点作为对应点,通过计算最小化源点云和目标点云之间的均方误差(MSE)来进行刚性变换(包括平移和旋转)。

纵马踏花向自由 1731

Python face-recognition库,dlib库安装方法(附下载文件)

想要安装face-recognition库需要先安装dlib库,但是常用的pip安装通常都会报错,不能正常安装,这里我先大家介绍我的安装方法,我在python的3.8,3.9,3.10版本都试过,只要找到位置,都是可以成功安装的。

m0_73524121的博客 5318

STM32 USB键盘实现指南

在STM32上实现键盘功能可以通过USB HID(人机接口设备)协议来实现,使STM32设备能被计算机识别为标准键盘。通过上述步骤,您可以在STM32上实现一个功能完整的USB键盘。关键点包括:正确配置USB HID设备实现键盘矩阵扫描处理按键事件并生成HID报告优化按键响应和消抖处理添加额外功能如宏键和LED反馈这个实现可以作为基础,进一步扩展为游戏键盘、宏键盘或特殊输入设备。

suny8的专栏 979

基于 Python 的人脸识别:使用 face_recognition 库实现

本文介绍了如何使用 Python 和库进行人脸识别。我们从最基础的人脸检测、编码提取到人脸匹配,再到如何识别和标记多张人脸。你可以利用这些功能来构建强大的智能人脸识别应用。

小蜗牛的珍贵百宝箱 1941

第4-4课:状态压缩与动态规划

什么是状态压缩 动态规划问题中重要的一环就是确定状态的定义,在大多数情况下,状态中所包含的信息并不多,比如线性规划问题的状态一般表示为 d[i,j](i 表示状态的位置,j 表示状态的阶段),算法实现时可用二维数组保存计算过程中的状态。但是也有一些问题,它的状态中包含的信息很多,比如它的状态可能是一个集合中各个元素的情况,或者是像铺瓷砖问题这样,是某一行的覆盖状态。如果沿用简单的状态表示方法,则可...

oRbIt 的专栏 708

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

python人脸识别库_用python库face_recognition进行人脸识别

1.pip install opencv2.pip installface_recognition3.通过摄像头实时在获取的帧上进行人脸识别(较卡顿)facerecognition.py# -*- coding: UTF-8 -*-import face_recognitionimport cv2import osimport ft2#中文支持,加载微软雅黑字体ft = ft2.put_chin...

weixin_39822629的博客 2147

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

上一篇: OpenCV Java 示例 - 匹配两个图像的关键点
下一篇: Python face_recognition人脸识别库调整人脸识别的容错率和敏感度
allway2
博客等级 码龄16年 6723粉丝 8044原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值