opensuse安装face_recognition全记录

opensuse安装face_recognition全记录

vikeyfox@20210821@opensuse安装face_recognition全记录

安装所需的python-devel

首先确保安装了对应版本的python-devel, ubuntu可能叫python-dev,在这里我的系统里安装了python-devel,python38-devel,python39-devel这几个包,实际安装过程中需要的是python39-devel. opensuse的命令是sudo zypper install python39-devel

安装cmake boost

使用命令pip install cmake boost

这个可能不是必要的,不过装上也好

安装dlib和face_recognition

安装dlib,命令pip install dlib,等待时间有1到2分钟作用, 这一步有些教程有坑, 要先安装python-devel

vikey@suse:~> pip install dlib
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting dlib
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/f0/a2/ba6163c09fb427990180afd8d625bcecc5555af699c253193c35ffd48c4f/dlib-19.22.1.tar.gz (7.4 MB)
Building wheels for collected packages: dlib
Building wheel for dlib (setup.py) ... done
Created wheel for dlib: filename=dlib-19.22.1-cp39-cp39-linux_x86_64.whl size=4334494 sha256=53ad3ad557bff87d6b99d1e8fc429a1462ef65dd8c6b554641d2b2db0fd50278
Stored in directory: /home/vikey/.cache/pip/wheels/c1/47/3a/c8f63895e31161abcef997bf9dc743fb78fb7fa71aa1899213
Successfully built dlib
Installing collected packages: dlib
Successfully installed dlib-19.22.1

pip install face_recognition等待安装完成即可

vikey@suse:~> pip install face_recognition
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting face_recognition
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/1e/95/f6c9330f54ab07bfa032bf3715c12455a381083125d8880c43cbe76bb3d0/face_recognition-1.3.0-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: Click>=6.0 in ./.local/lib/python3.9/site-packages (from face_recognition) (8.0.1)
Requirement already satisfied: face-recognition-models>=0.3.0 in ./.local/lib/python3.9/site-packages (from face_recognition) (0.3.0)
Requirement already satisfied: numpy in ./.local/lib/python3.9/site-packages (from face_recognition) (1.19.5)
Requirement already satisfied: dlib>=19.7 in ./.local/lib/python3.9/site-packages (from face_recognition) (19.22.1)
Collecting Pillow
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/42/25/59061f5848f509d3f50275c615fc620272d2bf2134d08232e4d79ad06cb0/Pillow-8.3.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (3.0 MB)
Installing collected packages: Pillow, face-recognition
Successfully installed Pillow-8.3.1 face-recognition-1.3.0

最后安装结束实验一下,由于安装的版本对应python3.9, 打开试一下:

vikey@suse:~> python3.9
Python 3.9.6 (default, Aug 09 2021, 11:37:16) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import face_recognition
>>>

模块导入ok

另外需要安装cv2,如果没有的话,执行pip install opencv-python或者pip3.9 install opencv-python,我的python默认版本是3.8所以要再装一次3.9的
下面抄段代码试验摄像头识别

记得把obama.jpg放在python脚本目录下

注意: video_capture = cv2.VideoCapture(2),参数为偶数,0,2,4,6,8是分别是第1,2,3,4,5个摄像头

# -*- coding: utf-8 -*-
import face_recognition
import cv2

video_capture = cv2.VideoCapture(2)

obama_img = face_recognition.load_image_file("obama.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_img)[0]

face_locations = []
face_encodings = []
face_names = []
process_this_frame = True

while True:
    ret, frame = video_capture.read()

    small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

    if process_this_frame:
        face_locations = face_recognition.face_locations(small_frame)
        face_encodings = face_recognition.face_encodings(small_frame, face_locations)

        face_names = []
        for face_encoding in face_encodings:
            match = face_recognition.compare_faces([obama_face_encoding], face_encoding)

            if match[0]:
                name = "Barack"
            else:
                name = "unknown"

            face_names.append(name)

    process_this_frame = not process_this_frame

    for (top, right, bottom, left), name in zip(face_locations, face_names):
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4

        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255),  2)

        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), 2)
        font = cv2.FONT_HERSHEY_DUPLEX
        cv2.putText(frame, name, (left+6, bottom-6), font, 1.0, (255, 255, 255), 1)

    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()
运行后识别成功,实时标记人脸,速度还挺快.

脸不放了, 祝大家玩的愉快.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值