面部识别 https://github.com/davisking/dlib
liuyuqi-dellpc dacee998b7 1 | 7 months ago | |
---|---|---|
.devcontainer | 7 months ago | |
.ide | 7 months ago | |
.coding-ci.yml | 7 months ago | |
.dockerignore | 7 months ago | |
.gitpod.Dockerfile | 7 months ago | |
Dockerfile | 7 months ago | |
README.md | 7 months ago | |
docker-compose.debug.yml | 7 months ago | |
docker-compose.yml | 7 months ago | |
main.py | 7 months ago | |
poetry.lock | 7 months ago | |
pyproject.toml | 7 months ago |
面部识别
默认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()