mac安装face_recognition python3
- 安装hrew
# 运行以下命令安装Homebrew,Homebrew默认被安装到/usr/local/Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# 添加环境变量,我装了oh-my-zsh,故将export命令添加到~/.zshrc中
echo 'export PATH=/usr/local/opt/opencv/bin:$PATH' >> ~/.zshrc
- 安装cmake
brew install cmake
brew install boost
brew install boost-python --with-python3
如果是windows的话,需要到cmake官网下载
- 安装X11窗口环境,点击下载
- 安装dlib
pip install dlib
- 安装face_recognition
pip install face_recognition
- 使用示例
# 检测人脸
import face_recognition
import cv2
# 读取图片并识别人脸
img = face_recognition.load_image_file("data/test.jpg")
face_locations = face_recognition.face_locations(img)
print(face_locations)
# 调用opencv函数显示图片
img = cv2.imread("data/test.jpg")
cv2.imshow("base", img)
# 遍历每个人脸,并标注
for (top,right,bottom,left) in face_locations:
start = (left, top)
end = (right, bottom)
color = (55,255,155)
thickness = 3
cv2.rectangle(img, start, end, color, thickness)
# 显示识别结果
cv2.imshow("new", img)
cv2.waitKey(0)
cv2.destroyAllWindows()