├── example ├── .gitignore └── index.js ├── .gitignore ├── .github └── FUNDING.yml ├── lib ├── browser-mock.js └── index.js ├── DOCUMENTATION.md ├── LICENSE ├── package.json ├── CONTRIBUTING.md └── README.md /example/.gitignore: -------------------------------------------------------------------------------- 1 | example.jpg 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules 6 | *.env 7 | .DS_Store 8 | package-lock.json 9 | .bloggify/* 10 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ionicabizau 2 | patreon: ionicabizau 3 | open_collective: ionicabizau 4 | custom: https://www.buymeacoffee.com/h96wwchmy -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const FaceDetectify = require("../lib"); 4 | 5 | FaceDetectify.fromFile(`${__dirname}/example.jpg`).then(res => { 6 | console.log(res) 7 | // => { data: [ { total: 1, width: 39, height: 39, x: 1038, y: 0 } ] } 8 | }).catch(console.error) 9 | -------------------------------------------------------------------------------- /lib/browser-mock.js: -------------------------------------------------------------------------------- 1 | const noop = require("noop6") 2 | 3 | // Mock browser globals used by tracking.js 4 | global.window = { 5 | URL: "" 6 | , requestAnimationFrame: noop 7 | , cancelAnimationFrame: noop 8 | , navigator: { 9 | getUserMedia: noop 10 | } 11 | } 12 | 13 | global.navigator = window.navigator 14 | global.tracking = window.tracking = {}; 15 | -------------------------------------------------------------------------------- /DOCUMENTATION.md: -------------------------------------------------------------------------------- 1 | ## Documentation 2 | 3 | You can see below the API reference of this module. 4 | 5 | ### `fromBuffer(buffer, width, height, cb)` 6 | Process a buffer. 7 | 8 | #### Params 9 | 10 | - **Buffer** `buffer`: The image buffer. 11 | - **Number** `width`: The width. 12 | - **Number** `height`: The height. 13 | - **Function** `cb`: The callback function. 14 | 15 | #### Return 16 | - **EvenEmitter** The `ObjectTracker` instance created by `tracking`. 17 | 18 | ### `fromFile(filePath)` 19 | Process a file. 20 | 21 | #### Params 22 | 23 | - **String** `filePath`: The file path to the image. 24 | 25 | #### Return 26 | - **Promise** A promise resolving with the following object: - `data` (Array): An array of objects representing the positions of the faces in the image: 27 | - `total` (Number) 28 | - `width` (Number) 29 | - `height` (Number) 30 | - `x` (Number) 31 | - `y` (Number) 32 | 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018-25 Ionică Bizău (https://ionicabizau.net) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "face-detectify", 3 | "description": "Detect faces in images. Without native modules. It uses tracking.js.", 4 | "keywords": [ 5 | "face", 6 | "detectify", 7 | "detect", 8 | "faces", 9 | "in", 10 | "images", 11 | "without", 12 | "native", 13 | "modules" 14 | ], 15 | "license": "MIT", 16 | "version": "1.0.3", 17 | "main": "lib/index.js", 18 | "scripts": { 19 | "test": "echo \"Error: no test specified\" && exit 1" 20 | }, 21 | "author": "Ionică Bizău (https://ionicabizau.net)", 22 | "homepage": "https://github.com/IonicaBizau/face-detectify#readme", 23 | "files": [ 24 | "bin/", 25 | "app/", 26 | "lib/", 27 | "dist/", 28 | "src/", 29 | "scripts/", 30 | "resources/", 31 | "menu/", 32 | "cli.js", 33 | "index.js", 34 | "index.d.ts", 35 | "package-lock.json", 36 | "bloggify.js", 37 | "bloggify.json", 38 | "bloggify/" 39 | ], 40 | "repository": { 41 | "type": "git", 42 | "url": "git+ssh://git@github.com/IonicaBizau/face-detectify.git" 43 | }, 44 | "bugs": { 45 | "url": "https://github.com/IonicaBizau/face-detectify/issues" 46 | }, 47 | "dependencies": { 48 | "noop6": "^1.0.7", 49 | "tilda": "^4.4.12", 50 | "tracking": "^1.1.3", 51 | "get-pixels": "^3.3.0" 52 | }, 53 | "blah": { 54 | "h_img": "https://i.imgur.com/o7pVHIv.png" 55 | } 56 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # 🌟 Contributing 2 | 3 | Want to contribute to this project? Great! Please read these quick steps to streamline the process and avoid unnecessary tasks. ✨ 4 | 5 | ## 💬 Discuss Changes 6 | Start by opening an issue in the repository using the [bug tracker][1]. Describe your proposed contribution or the bug you've found. If relevant, include platform info and screenshots. 🖼️ 7 | 8 | Wait for feedback before proceeding unless the fix is straightforward, like a typo. 📝 9 | 10 | ## 🔧 Fixing Issues 11 | 12 | Fork the project and create a branch for your fix, naming it `some-great-feature` or `some-issue-fix`. Commit changes while following the [code style][2]. If the project has tests, add one. ✅ 13 | 14 | If a `package.json` or `bower.json` exists, add yourself to the `contributors` array; create it if it doesn't. 🙌 15 | 16 | ```json 17 | { 18 | "contributors": [ 19 | "Your Name (http://your.website)" 20 | ] 21 | } 22 | ``` 23 | 24 | ## 📬 Creating a Pull Request 25 | Open a pull request and reference the initial issue (e.g., *fixes #*). Provide a clear title and consider adding visual aids for clarity. 📊 26 | 27 | ## ⏳ Wait for Feedback 28 | Your contributions will be reviewed. If feedback is given, update your branch as needed, and the pull request will auto-update. 🔄 29 | 30 | ## 🎉 Everyone Is Happy! 31 | Your contributions will be merged, and everyone will appreciate your effort! 😄❤️ 32 | 33 | Thanks! 🤩 34 | 35 | [1]: /issues 36 | [2]: https://github.com/IonicaBizau/code-style -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Mock the Browser API 4 | require("./browser-mock") 5 | require("tracking") 6 | require("tracking/build/data/face") 7 | 8 | const getpixels = require("get-pixels") 9 | 10 | class FaceDetectify { 11 | /** 12 | * fromBuffer 13 | * Process a buffer. 14 | * 15 | * @name fromBuffer 16 | * @function 17 | * @static 18 | * @param {Buffer} buffer The image buffer. 19 | * @param {Number} width The width. 20 | * @param {Number} height The height. 21 | * @param {Function} cb The callback function. 22 | * @return {EvenEmitter} The `ObjectTracker` instance created by `tracking`. 23 | */ 24 | static fromBuffer (buffer, width, height, cb) { 25 | const tracker = new tracking.ObjectTracker("face"); 26 | cb && tracker.on("track", cb) 27 | tracker.track(buffer, width, height) 28 | return tracker 29 | } 30 | 31 | /** 32 | * fromFile 33 | * Process a file. 34 | * 35 | * @name fromFile 36 | * @function 37 | * @static 38 | * @param {String} filePath The file path to the image. 39 | * @returns {Promise} A promise resolving with the following object: 40 | * - `data` (Array): An array of objects representing the positions of the faces in the image: 41 | * - `total` (Number) 42 | * - `width` (Number) 43 | * - `height` (Number) 44 | * - `x` (Number) 45 | * - `y` (Number) 46 | */ 47 | static fromFile (filePath) { 48 | return new Promise((res, rej) => { 49 | getpixels(filePath, (err, data) => { 50 | if (err) { return rej(err) } 51 | FaceDetectify.fromBuffer(data.data, data.shape[0], data.shape[1], res) 52 | }) 53 | }) 54 | } 55 | } 56 | 57 | module.exports = FaceDetectify 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | [![face-detectify](https://i.imgur.com/o7pVHIv.png)](#) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | # face-detectify 23 | 24 | [![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/face-detectify.svg)](https://www.npmjs.com/package/face-detectify) [![Downloads](https://img.shields.io/npm/dt/face-detectify.svg)](https://www.npmjs.com/package/face-detectify) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github) 25 | 26 | Buy Me A Coffee 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | > Detect faces in images. Without native modules. It uses tracking.js. 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ## :cloud: Installation 53 | 54 | ```sh 55 | # Using npm 56 | npm install --save face-detectify 57 | 58 | # Using yarn 59 | yarn add face-detectify 60 | ``` 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | ## :clipboard: Example 75 | 76 | 77 | 78 | ```js 79 | const FaceDetectify = require("face-detectify"); 80 | 81 | FaceDetectify.fromFile(`${__dirname}/example.jpg`).then(res => { 82 | console.log(res) 83 | // => { data: [ { total: 1, width: 39, height: 39, x: 1038, y: 0 } ] } 84 | }).catch(console.error) 85 | ``` 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | ## :question: Get Help 99 | 100 | There are few ways to get help: 101 | 102 | 103 | 104 | 1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question. 105 | 2. For bug reports and feature requests, open issues. :bug: 106 | 3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket: 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | ## :memo: Documentation 115 | 116 | 117 | ### `fromBuffer(buffer, width, height, cb)` 118 | Process a buffer. 119 | 120 | #### Params 121 | 122 | - **Buffer** `buffer`: The image buffer. 123 | - **Number** `width`: The width. 124 | - **Number** `height`: The height. 125 | - **Function** `cb`: The callback function. 126 | 127 | #### Return 128 | - **EvenEmitter** The `ObjectTracker` instance created by `tracking`. 129 | 130 | ### `fromFile(filePath)` 131 | Process a file. 132 | 133 | #### Params 134 | 135 | - **String** `filePath`: The file path to the image. 136 | 137 | #### Return 138 | - **Promise** A promise resolving with the following object: - `data` (Array): An array of objects representing the positions of the faces in the image: 139 | - `total` (Number) 140 | - `width` (Number) 141 | - `height` (Number) 142 | - `x` (Number) 143 | - `y` (Number) 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | ## :yum: How to contribute 159 | Have an idea? Found a bug? See [how to contribute][contributing]. 160 | 161 | 162 | ## :sparkling_heart: Support my projects 163 | I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, 164 | this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it). 165 | 166 | However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it: 167 | 168 | 169 | - Starring and sharing the projects you like :rocket: 170 | - [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book: 171 | - [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea: 172 | - [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone). 173 | - **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6` 174 | 175 | ![](https://i.imgur.com/z6OQI95.png) 176 | 177 | 178 | Thanks! :heart: 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | ## :dizzy: Where is this library used? 196 | If you are using this library in one of your projects, add it in this list. :sparkles: 197 | 198 | - `smartcrop-tracking-cli` 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | ## :scroll: License 211 | 212 | [MIT][license] © [Ionică Bizău][website] 213 | 214 | 215 | 216 | 217 | 218 | 219 | [license]: /LICENSE 220 | [website]: https://ionicabizau.net 221 | [contributing]: /CONTRIBUTING.md 222 | [docs]: /DOCUMENTATION.md 223 | [badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg 224 | [badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg 225 | [badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg 226 | [badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg 227 | [patreon]: https://www.patreon.com/ionicabizau 228 | [amazon]: http://amzn.eu/hRo9sIZ 229 | [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW 230 | --------------------------------------------------------------------------------