opencv-facecrop
Version:
Npm package to autodetect and crop faces using opencv
84 lines (49 loc) • 3.04 kB
Markdown









This package helps you to auto-detect faces in a picture and crop them out.
[](https://nodei.co/npm/opencv-facecrop/)
**Install from command line:**
`npm install --save opencv-facecrop`
```javascript
const facecrop = require('opencv-facecrop');
facecrop('./image-file.jpg', './dest/output.jpg', "image/jpeg", 0.95, 50);
/* Outputs image with file name output.jpg in 'dest' folder with the face cropped out.
If multiple faces are detected, the files will be automatically renamed to output-1.jpg, output-2.jpg and so on.
*/
```
Original Image:
<img src="https://github.com/arghyadeep-k/resources/raw/master/opencv-facecrop_test-file-1.jpg">
<br><br>
Cropped Image:
<img src="https://github.com/arghyadeep-k/resources/raw/master/opencv-facecrop_test-file-1-output.jpg" width=250px>
Image by <a href="https://pixabay.com/photos/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=919048">Free-Photos</a> from <a href="https://pixabay.com/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=919048">Pixabay</a>
**facecrop(input_filename, output_filename, type, quality, factor)**
- **input_filename**: Input String containing file name with relative/absolute filepath.
- **output_filename**: (Optional) Requires a string value which will contains the output file name.
- **type**: (Optional) Requires String value which will tell the format of the output image.
- **quality**: (Optional) Requires a float value between 0 to 1 which stands for the quality index of the output file compares to the input file. Set 1 for no reduction in quality.
- **factor**: (Optional) Pixels by which the area of cropping of the face should be increased to add more details. Use -ve value to decrease.
- **input_filename**: Mandatory parameter
- **output_filename**: "./output.jpg"
- **type**: 'image/jpeg'
- **quality**: 0.95
- **factor**: 0
OpenCv - Face Crop is published under the Unlicense. For more information, see the accompanying LICENSE file.
<br>
---
<br>
P.S. - This is a pre-release version. More updates with refinements coming soon.