https://github.com/boldare/xsolve-face-validator-bundle
Open-source Symfony3 bundle for validating faces on pictures
https://github.com/boldare/xsolve-face-validator-bundle
Last synced: about 1 year ago
JSON representation
Open-source Symfony3 bundle for validating faces on pictures
- Host: GitHub
- URL: https://github.com/boldare/xsolve-face-validator-bundle
- Owner: boldare
- License: mit
- Created: 2017-09-01T07:10:20.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-19T15:56:23.000Z (over 8 years ago)
- Last Synced: 2025-04-06T21:08:38.075Z (about 1 year ago)
- Language: PHP
- Homepage: https://xsolve.software/blog/face-detection-open-source-symfony3/
- Size: 113 KB
- Stars: 17
- Watchers: 51
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
----------
# XSolve Face Validator Bundle
[](https://travis-ci.org/xsolve-pl/xsolve-face-validator-bundle)
[](https://scrutinizer-ci.com/g/xsolve-pl/xsolve-face-validator-bundle/?branch=master)
============================
Table of contents
=================
* [Introduction](#introduction)
* [License](#license)
* [Getting started](#getting-started)
* [Usage](#usage)
Introduction
=================
This Symfony3 bundle allows to validate whether an image (for instance uploaded by a user of your app) contains person's face.
Internally it uses MS Azure Face API so in order to use it you need an account in MS Azure. In free plan the API allows
to make 30 000 requests per month and 20 per minute so it should be enough to be useful for low traffic apps.
All the following features are configurable on the constraint level and can be easily enabled/disabled:
* requiring certain face size (ratio to the image size)
* disallowing an image when the face is covered
* requiring the hair to be visible (the image must not be cut)
* allowing the face to be rotated in any of the 3 axes to given level
* disallowing to wear glasses
* disallowing to wear sunglasses
* disallowing any makeup
* requiring an image not to be blurred over given level (low/medium/high)
* requiring an image not to contain noises over given level (low/medium/high)
Licence
=================
This library is under the MIT license. See the complete license in [LICENSE](LICENSE) file.
Getting started
=================
Add the bundle to your Symfony3 project using [Composer](https://getcomposer.org/):
```bash
$ composer require xsolve-pl/face-validator-bundle
```
You'll need also to register the bundle in your kernel:
```php
createFormBuilder($user)
->add('profilePicture', FileType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// ...
}
// ...
}
}
```
the image will be validated whether it contains a face. The way the face is being validated is customizable, all the possible
options with their default values are shown on the example below:
```php
// src/AppBundle/Entity/User.php
use Symfony\Component\Validator\Constraints as Assert;
use XSolve\FaceValidatorBundle\Validator\Constraints as XSolveAssert;
class User
{
/**
* @var Symfony\Component\HttpFoundation\File\UploadedFile
* @Assert\Image()
* @XSolveAssert\Face(
* minFaceRatio = 0.15,
* allowCoveringFace = true,
* maxFaceRotation = 20.0,
* allowGlasses = true,
* allowSunglasses = true,
* allowMakeup = true,
* allowNoHair = true,
* maxBlurLevel = high,
* maxNoiseLevel = high,
* noFaceMessage = 'Face is not visible.',
* faceTooSmallMessage = 'Face is too small.',
* faceCoveredMessage = 'Face cannot be covered.',
* hairCoveredMessage = 'Hair cannot be covered.',
* tooMuchRotatedMessage = 'Face is too much rotated.',
* glassesMessage = 'There should be no glasses in the picture.',
* sunglassesMessage = 'There should be no sunglasses in the picture.',
* makeupMessage = 'The person should not be wearing any makeup.',
* blurredMessage = 'The picture is too blurred.',
* noiseMessage = 'The picture is too noisy.'
* )
*/
public $profilePicture;
}
```
Note that you can omit any (or even all) of the options listed above, then the defaults will be used.
For blur and noise levels the possible options are:
* low
* medium
* high
It's also possible, just like with any other Symfony validator, to use it directly against given value (either file path or an instance of \SplFileInfo).
```php
// src/AppBundle/Controller/ImageController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class ImageController extends Controller
{
public function validateAction(Request $request)
{
/* @var $validator ValidatorInterface */
$validator = $this->get('validator');
$constraintViolations = $validator->validate(
'/path/to/your/image/file.png',
new Face([
// you can pass the options mentioned before to the validation constraint
])
);
}
}
```