面部识别 https://github.com/davisking/dlib

liuyuqi-dellpc dacee998b7 1 3 months ago
.devcontainer b57d22039d 0 3 months ago
.ide b57d22039d 0 3 months ago
.coding-ci.yml b57d22039d 0 3 months ago
.dockerignore b57d22039d 0 3 months ago
.gitpod.Dockerfile b57d22039d 0 3 months ago
Dockerfile 770eeff0ca 0 3 months ago
README.md dacee998b7 1 3 months ago
docker-compose.debug.yml b57d22039d 0 3 months ago
docker-compose.yml b57d22039d 0 3 months ago
main.py b57d22039d 0 3 months ago
poetry.lock b57d22039d 0 3 months ago
pyproject.toml b57d22039d 0 3 months ago

README.md

dlib

Open in GitHub Codespaces

面部识别

Usage

默认CPU

pip install dlib

import dlib
dlib.DLIB_USE_CUDA   # True 表示可以使用 GPU

模型下载: http://dlib.net/files/mmod_human_face_detector.dat.bz2

import dlib
import cv2
import numpy as np

# 加载 dlib 的人脸检测器
detector = dlib.get_frontal_face_detector()

# 加载输入图像
image = cv2.imread('input_image.jpg')

# 将图像转换为灰度图像
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 使用人脸检测器检测图像中的人脸
faces = detector(gray)

# 遍历检测到的人脸
for face in faces:
    x, y, w, h = face.left(), face.top(), face.width(), face.height()
    
    # 在图像中标记人脸位置
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)

# 显示标记后的图像
cv2.imshow('Detected Faces', image)
cv2.waitKey(0)
cv2.destroyAllWindows()

License

Reference

davisking/dlib