ArchLinux 安装 howdy 实现人脸识别验证

安装 howdy

使用 yay 或者其它包管理工具从 aur 安装 howdy

yay -Syu howdy

找到本机用于识别的摄像头

  • 可以通过 vlc 等工具找到本机的前置摄像头

    • 媒体 / Open Capture device / 捕获设备 / Advanced options / 视频捕获设备 中选择对应的设备

    • 点击确定,然后点击播放

    • 重复以上步骤,直到确定前置摄像头的设备位置名称

  • 或者通过命令sudo pacman -S v4l-utils安装v4l-utils,然后使用命令v4l2-ctl --list-devices来找到本机所有的媒体设备,一般来说第一个/dev/video0就是你要找的目标

编辑 howdy 配置文件

对应配置文件 /usr/lib/security/howdy/config.ini,以下有中文注释的地方是我认为比较有用的配置选项

# Howdy config file
# Press CTRL + X to save in the nano editor

[core]
# Print that face detection is being attempted
detection_notice = false

# Do not print anything when a face verification succeeds
no_confirmation = false

# When a user without a known face model tries to use this script, don't
# show an error but fail silently
suppress_unknown = false

# Disable Howdy in remote shells
ignore_ssh = true

# Disable Howdy if lid is closed
ignore_closed_lid = true

# Disable howdy in the PAM
# The howdy command will still function
disabled = false

# Use CNN instead of HOG
# CNN model is much more accurate than the HOG based model, but takes much more
# computational power to run, and is meant to be executed on a GPU to attain reasonable speed.
use_cnn = false

[video]
# The certainty of the detected face belonging to the user of the account
# On a scale from 1 to 10, values above 5 are not recommended
# Lower is better
# 检测的确定性,数值越低准确度越高,但是识别率越低
certainty = 5

# The number of seconds to search before timing out
# 认证超时时间
timeout = 10

# The path of the device to capture frames from
# Should be set automatically by an installer if your distro has one
# 前置摄像头位置
device_path = /dev/video0

# Scale down the video feed to this maximum height
# Speeds up face recognition but can make it less precise
max_height = 320

# Set the camera input profile to this width and height
# The largest profile will be used if set to -1
# Automatically ignored if not a valid profile
frame_width = -1
frame_height = -1

# Because of flashing IR emitters, some frames can be completely unlit
# Skip the frame if the lowest 1/8 of the histogram is above this percentage
# of the total
# The lower this setting is, the more dark frames are ignored
# 在黑暗环境下,值越低准确度越高,识别率越低
dark_threshold = 100

# The recorder to use. Can be either opencv (default), ffmpeg or pyv4l2.
# Switching from the default opencv to ffmpeg can help with grayscale issues.
recording_plugin = opencv

# Video format used by ffmpeg. Options include vfwcap or v4l2.
# FFMPEG only.
device_format = v4l2

# Force the use of Motion JPEG when decoding frames, fixes issues with YUYV
# raw frame decoding.
# OPENCV only.
force_mjpeg = false

# Specify exposure value explicitly. This disables autoexposure.
# Use qv4l2 to determine an appropriate value.
# OPENCV only.
exposure = -1

[snapshots]
# Capture snapshots of failed login attempts and save them to disk with metadata
# Snapshots are saved to the "snapshots" folder
# 设置识别用户失败时拍照保存照片
capture_failed = true

# Do the same as the option above but for successful attempts
# 取消识别用户成功时拍照保存照片
capture_successful = false

[debug]
# Show a short but detailed diagnostic report in console
# Enabling this can cause some UI apps to fail, only enable it to debug
end_report = false

修改完配置文件后,可以使用sudo howdy test命令来检验摄像头是否能够正常工作,如果检测界面能够打开并识别到人脸,这说明摄像头配置成功

这里有可能会出现ModuleNotFoundError: No module named 'cv2'的错误,这是缺少python-opencv这个依赖,可以通过使用sudo pacman -S python-opencv来安装依赖

配置认证选项

想要实现对应功能的人脸识别认证,可以在/etc/pam.d文件夹下修改对应的配置文件,在配置文件的首行加入以下配置:auth sufficient pam_python.so /lib/security/howdy/pam.py(针对 howdy 2.x)

一般来说只需要修改桌面环境相关的配置文件,例如在/etc/pam.d/kde首行加入对应配置可以实现被 kde 管理的多个认证选项,包括登录、解锁等

如果需要精准的控制,例如登录时的人脸识别,可以修改/etc/pam.d/system-local-login配置文件;想要在使用 sudo 时实现人脸识别可以修改/etc/pam.d/sudo配置文件等等

此外,一般来说还需要将/usr/lib/security/howdy文件夹下的文件权限更改为 755 以授权普通用户的执行权限,否则 kde 锁屏解锁等功能可能无法使用:sudo chmod -R 755 /usr/lib/security/howdy

添加人脸识别凭证

使用sudo howdy add命令来添加人脸,可以添加多个凭证信息,以达到更好的识别效果

注意事项

  • 在进行人脸识别时可能会出现警告,临时的解决办法是修改opencv的日志级别,添加一个环境变量OPENCV_LOG_LEVEL=ERROR:可以在/etc/profile文件底部添加export OPENCV_LOG_LEVEL=ERROR或者在/etc/environment文件中添加OPENCV_LOG_LEVEL=ERROR,注意需要重新启动计算机
  • 出现ModuleNotFoundError: No module named 'cv2'的错误,这是缺少python-opencv这个依赖,可以通过使用sudo pacman -S python-opencv来安装依赖
Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐