madbob/face-recognition
Composer 安装命令:
composer require madbob/face-recognition
包简介
A wrapper for face_recognition package
README 文档
README
This is a simple PHP wrapper for the popular face-recognition Python package.
On the contrary of other similar packages, this executes the CLI face_detection command and reads the output. This simplifies the deployment phase, as the face-recognition package can be installed in a Python isolated virtual environment (e.g. with pipx, as recommended by Debian) which prevents the Python import of the library but still permits the execution of the application.
Plus, this library is integrated with InterventionImage to provide convenient manipulation of the detected images.
This project has been initially implemented to better display photos of people retrieved from Wikipedia Commons and published on TrendingOnWiki.
Install
# Or your preferred way to install the Python application
pipx install face-recognition
composer require madbob/face-recognition
Example
require "vendor/autoload.php";
use MadBob\FaceRecognition\FaceRecognition;
$master = new FaceRecognition();
$image = $master->loadImage('test1.jpg');
$faces = $image->bboxes();
$image->coverDownFace(1920, 1080)->toJpeg()->save('test2.jpg');
Documentation
First of all, you have to init an instance of MadBob\FaceRecognition\FaceRecognition, which constructor accepts an associative array of parameters.
The accepted parameters are:
| name | usage | default |
|---|---|---|
| exec_path | The path where to find the face_detection executable. By default it is empty, assuming it is already in $PATH | |
| model | The face-recognition model you prefer to use. Read the package's documentation for details | |
| cpus | Number of CPUs to use while reading the images. -1 means "use all in system" | -1 |
| graphic_driver | The driver to be used to handle images with InterventionImage. May be gd or imagick | gd |
$master = new FaceRecognition([
'exec_path' => '/usr/local/bin',
'model' => 'hog',
'cpus' => 2,
'graphic_driver' => 'imagick',
]);
On this instance, you can call two different function: loadImage() or loadFolder(). The first one takes the path of a single image, and returns a single MadBob\FaceRecognition\Image object, while the second parses all images in the given folder and returns an array of the same object type.
$image = $master->loadImage('/path/to/test1.jpg');
$images = $master->loadFolder('/path/to/many/photos/');
A MadBob\FaceRecognition\Image is mostly a a wrapper around an instance of Intervention\Image\Image: on this object you can call all the utility functions provided by InterventionImage (resize, crop, save...), plus a few custom ones.
getPath()returns the path of the original image;hasFaces()returnstrueorfalsedepending if the image contains at least a detected face;bboxes()returns an array of objects, one for each detected face, with attributesx1,x2,y1andy2holding his coordinates. If no faces have been detected, it returns an empty array;coverDownFace($width, $height)returns aIntervention\Image\Imageinstance already cropped and resized to keep the faces found in the image at the center; this can be chained with other InterventioImage functions to save the manipulated image or apply further transformations. If no face has been detected, the image is cropped and resized just at the center (usingcoverDown()function in InterventionImage).
$images = $master->loadFolder('/path/to/many/photos/');
foreach($images as $image) {
echo $image->getPath() . ' : ' . count($image->bboxes() . "\n";
}
License
This code is free software, licensed under the MIT License. See the LICENSE.txt file for more details.
Copyright (C) 2024 Roberto Guido info@madbob.org
madbob/face-recognition 适用场景与选型建议
madbob/face-recognition 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「machine learning」 「face detection」 「face recognition」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 madbob/face-recognition 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 madbob/face-recognition 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 madbob/face-recognition 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
Automatically translate and review your content via Lokalise.
Simple and elegant tools for build web application.
Phwoolcon Finite State Machine
Official PHP integration for Optidash - AI-powered image optimization and processing API. We will drastically speed-up your websites and save you money on bandwidth and storage.
Official Laravel Facade for Optidash - AI-powered image optimization and processing API. We will drastically speed-up your websites and save you money on bandwidth and storage.
统计信息
- 总下载量: 54
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-12