Detect the position of a face in an image.

Overview

Face Detector PHP

GD 를 이용해 이미지의 얼굴 위치를 식별합니다.

  • mauricesvay/php-facedetection 프로젝트를 기반으로 만들었습니다.
  • js 로 포팅하며 개선한 사항들을 적용하여 error_reporting = E_ALL safe 하게 php 코드를 새로 작성했습니다.
  • 라이센스가 GPL-2.0 인 이유는 원본의 라이센스를 유지해야하기 때문입니다.
  • 이미지 크기에 따라 인식률에 큰 차이가 생깁니다. 알고리즘의 원리를 이해하지 못해서 크기 외의 인식률 개선 작업을 하지 못했습니다. 테스트에 사용된 이미지들은 대부분 281px 일 때의 결과가 가장 좋기 때문에 기본값이 281 입니다.
  • 자원소모가 심한편이기 때문에 썸네일 정렬 용도로 사용하려면, 실시간 적용 보다는 업로드시 검출하여 direction 값을 함께 저장하는것이 좋습니다.
$ php composer.phar require "crucifyer/facedetector-php" "dev-main"
$detector = new \Xeno\Image\FaceDetector(imagefile or gdresource or imagebinary);
$face = $detector->FaceDetect();
['x' => int, 'y' => int, 'w' => int]

$faces = $detector->FaceDetect(true);
[
	['x' => int, 'y' => int, 'w' => int],
	['x' => int, 'y' => int, 'w' => int],
	['x' => int, 'y' => int, 'w' => int],
	['x' => int, 'y' => int, 'w' => int],
	['x' => int, 'y' => int, 'w' => int],
]

FaceDetector::FaceDetect([multiplue bool], [resSize int])
  • gif, jpeg, png 이미지 파일, gd 리소스, 이미지 바이너리가 가능합니다.

multiple

  • multiple 값을 true 로 주면 얼굴위치를 최대 10개까지 더 찾아서 배열로 반환합니다.
  • true 대신 숫자를 입력할 수 있고, 2~50으로 제한됩니다.
  • 여러 얼굴 인식률이 특히 안좋아서 이미지 크기를 바꿔도 모든 얼굴을 인식하지 못할 확률이 높습니다.

resSize

  • 원본 이미지를 그대로 사용하지 않고 이미지 크기를 줄여서 사용합니다. 가로,세로 중 작은쪽 기준으로 줄이며, 기본값은 281 입니다.
$face = $detector->FaceDetect();
$size = $detector->getImageSize();
$direction = \Xeno\Image\FaceDetector::AlignDirection($size['width'], $size['height'], $face['x'], $face['y'], $face['w']);
  • 얼굴쪽으로 정렬을 하기 위한 방향을 반환합니다.
  • 가로가 길면 left, center, right, 세로가 길면 top, middle, bottom 중 얼굴이 감지된 위치를 반환합니다.
  • 약 30% 이상 치우쳤는지로 판단합니다.
$faces = \Xeno\Image\FaceDetector::FilterSmallFaces($faces);
  • 가장 큰 것 대비 60% 이상 작은것을 걸러냅니다.
$detector = new \Xeno\Image\FaceDetector(imagefile or gdresource or imagebinary);
$direction = $detector->getDirection();
  • 방향 인식까지의 과정을 자동화 합니다. 여러 얼굴을 인식하면 중앙정렬 합니다.
$detector = new \Xeno\Image\FaceDetector(imagefile or gdresource or imagebinary);
[gd resource or boolean] = $detector->cropThumbnail(size, [direction], [file], [type]);
  • 크롭된 썸네일을 반환합니다. size 보다 원본이 작아도 키워서 맞추지 않고, 비율대로 자르기만 합니다.

direction

  • 생략하면 getDirection 을 해서 채웁니다.

file

  • 생략하면 gd resource 를 반환합니다.

type

  • gif, jpg, png, png8 을 지원하고 생략하면 file 의 확장자로 판별합니다.
  • png8 은 gif 와 같은 방식인 indexed colors 라서 용량이 작고 화질이 안좋습니다.

전반적인 예제가 tests/example.php 에 들어있습니다. autoload.php 위치를 수정하고 콘솔에서 테스트하세요.

js project: https://github.com/crucifyer/facedetector-js

You might also like...
CloudFlare Image Resizing plugin for WordPress.

Cloudflare Image Resizing plugin for WordPress The current Cloudflare plugin for WordPress does not replace URL's automatically for you to use the Ima

🐋📦✂️📋📦 Docker image of packagist mirror

Docker for Packagist Mirror This project allows you to easily create and update a mirror of the packagist having as dependency only the docker. It is

Docker image that provides static analysis tools for PHP

Static Analysis Tools for PHP Docker image providing static analysis tools for PHP. The list of available tools and the installer are actually managed

Smd thumbnail - Multiple image thumbnails of arbitrary dimensions

smd_thumbnail Download | Packagist If you’re bored of one Textpattern thumbnail per image and don’t fancy using an auto-resizing script or relying on

Tom image grid - Plugin for Textpattern CMS : An optionnal grid display for images tab

tom_image_grid tom_image_grid is a plugin for Textpattern CMS. It allows a more compact display (as a grid) of the images list. The plugin adds two bu

Docker-magento - Docker image for Magento 1.6 to 1.9

Docker image for Magento 1.x This repo creates a Docker image for Magento 1.x. Please note The primary goal of this repo is to create Docker images fo

Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates
Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates

Magento 2 Image Resizer Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates Installation $ composer require

Simple, image-based, mathematical captcha, with increasing levels of difficulty
Simple, image-based, mathematical captcha, with increasing levels of difficulty

simple-captcha Simple, image-based, mathematical captcha, with increasing levels of difficulty version 1.1.0 see also: ModelView a simple, fast, power

YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file, move it to a new directory, and returns the new source for the image.

NO LONGER MAINTAINED!!! Image Cache v. 1.0.0 Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file,

PHP client for Microsoft Azure Face API.

Microsoft Azure Face API PHP client A PHP library that utilizes Azure Face REST API. Requirements PHP = 7.4 Installation composer require darmen/php-

This is mini project for online test with Face Camera detection and Anti Cheating
This is mini project for online test with Face Camera detection and Anti Cheating

Online Test Script With Face Detection + Anti Cheating This is mini project that you can use this to make your own online test. This project include F

In Laravel, we commonly face the problem of adding repetitive filtering code, this package will address this problem.

Filterable In Laravel, we commonly face the problem of adding repetitive filtering code, sorting and search as well this package will address this pro

Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image

Laravel ImageUp The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization. Install

A Laravel Gravatar package for retrieving gravatar image URLs or checking the existance of an image.

Gravatar for Laravel 5.x, 6, 7 and 8 Installation First, pull in the package through Composer via the command line: composer require creativeorange/gr

This plugin adds a new image style for the Core Image block.
This plugin adds a new image style for the Core Image block.

This plugin adds a new image style for the Core Image block. Introduction How to use? Go to Gutenberg Editor and add a image block. e.g. Add new image

WordPress plugin renames image filenames to be more SEO friendly, based on the post's data and image metadata.

=== Automatic image Rename === Contributors: wpsunshine Tags: image, images, SEO, rename, optimization Requires at least: 5.0 Tested up to: 6.2.2 Stab

Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

Motto: "Every business should have a detection script to detect mobile readers." About Mobile Detect is a lightweight PHP class for detecting mobile d

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

DeviceDetector Code Status Description The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv

Owner
Song Hyo Jin
Song Hyo Jin
WordPress plugin renames image filenames to be more SEO friendly, based on the post's data and image metadata.

=== Automatic image Rename === Contributors: wpsunshine Tags: image, images, SEO, rename, optimization Requires at least: 5.0 Tested up to: 6.2.2 Stab

null 8 Jun 11, 2023
Library for PHP 7.4+ to detect Browsers and Devices

This library requires PHP 7.4+. Also a PSR-3 compatible logger and a PSR-16 compatible cache are required. In

Thomas Müller 37 Oct 2, 2022
Rules to detect game engines and other technologies based on Steam depot file lists

SteamDB File Detection Rule Sets This is a set of scripts that are used by SteamDB to make educated guesses about the engine(s) & technology used to b

Steam Database 103 Dec 14, 2022
Detect flaws in your architecture, before they drag you down into the depths of dependency hell ...

Detect flaws in your architecture before they drag you down into the depths of dependency hell ... What it does System Requirements Installation Phive

Michael Haeuslmann 507 Dec 27, 2022
Library allows to detect emoji, remove emoji, encode emoji and decode emoji in string.

It allows to detect emoji, remove emoji, encode emoji and decode emoji in string. Installation composer require anisimov/emoji How to use Encode and

Aleksey Anisimov 9 Nov 8, 2022
Helps detect the user's browser and platform at the PHP level via the user agent

cbschuld/browser.php Helps detect the user's browser and platform at the PHP level via the user agent Installation You can add this library as a local

Chris Schuld 574 Dec 16, 2022
Tool to detect assumptions

PHP Assumptions Setup $ composer require --dev rskuipers/php-assumptions Introduction PHP Assumptions is the result of a proof of concept inspired by

Rick Kuipers 153 Dec 8, 2022
Mobile detect change theme and redirect based on device type. Magento 2 module.

Magento 2 Mobile Detect Theme Change Magento 2 Mobile detect system can be used to load different themes base on the client device (desktop, tablet, m

EAdesign 27 Jul 5, 2022
The main scope of this extension is to help phpstan to detect the type of object after the Assert\Assertion validation.

PHPStan beberlei/assert extension PHPStan beberlei/assert Description The main scope of this extension is to help phpstan to detect the type of object

PHPStan 33 Jan 2, 2023
Banana detect adblock :Detects ad blockers (AdBlock, ublock, ...)

banana detect adblock :Detects ad blockers (AdBlock, ublock, ...)

banana 24 Dec 28, 2022