|
| 1 | +# Thumbler |
| 2 | +> Proof of concept script that extracts faces as thumbnails from an image. |
| 3 | +
|
| 4 | +[![GitHub issues][issues-image]][issues-url] |
| 5 | +[![GitHub forks][fork-image]][fork-url] |
| 6 | +[![GitHub Stars][stars-image]][stars-url] |
| 7 | +[![License][license-image]][license-url] |
| 8 | +[![Twitter][twitter-image]][twitter-url] |
| 9 | + |
| 10 | +## Installation |
| 11 | +The most difficult thing to install was [OpenCV3](https://github.com/opencv/opencv.git). I've included an additional [document](opencv/OpenCV.md) on what I had to go through to get it working, hopefully it'll be of some use. I've also included a sample script so that you can test your installation. Both can be found in the *opencv* folder. |
| 12 | + |
| 13 | +> DISCLAIMER: Now I must admit that I am using [Anaconda](https://www.continuum.io/) so the only hurdle I had with this was installing [OpenCV](https://github.com/opencv/opencv.git). Everything else was already installed. So the following has not been verified to work. |
| 14 | +
|
| 15 | +### Anaconda |
| 16 | +> UPDATE: Recently I discovered an easier way to install OpenCV3 under Anaconda. If you are not using Anaconda, my write-up on OpenCV should be of some use. If you are using Anaconda, do the following: |
| 17 | +
|
| 18 | +If you just want to install it quickly use my Anaconda environment export: |
| 19 | + |
| 20 | +```bash |
| 21 | +conda env create -f conda_venv.yml |
| 22 | +``` |
| 23 | + |
| 24 | +Otherwise, if you want to build it by hand, do the following: |
| 25 | + |
| 26 | +This command will tell you how to install OpenCV3: |
| 27 | +```bash |
| 28 | +anaconda show menpo/opencv3 |
| 29 | +Using Anaconda API: https://api.anaconda.org |
| 30 | +Name: opencv3 |
| 31 | +Summary: |
| 32 | +Access: public |
| 33 | +Package Types: conda |
| 34 | +Versions: |
| 35 | + + 3.1.0 |
| 36 | + + 3.2.0 |
| 37 | + |
| 38 | +To install this package with conda run: |
| 39 | + conda install --channel https://conda.anaconda.org/menpo opencv3 |
| 40 | +``` |
| 41 | +Running that command will install it for you, but before you do that, I would recommend adding that channel to your list of channels. |
| 42 | + |
| 43 | +```bash |
| 44 | +conda config --append channels https://conda.anaconda.org/menpo |
| 45 | +``` |
| 46 | +Now that you have that channel installed, all you have to do is create a new virtual environment with the modules that you need: |
| 47 | + |
| 48 | +```bash |
| 49 | +conda create --name thumbler python=3.6.2 opencv3 pillow |
| 50 | +``` |
| 51 | +That command will create a new virtual environment called thumbler with Python 3.6.2 as the interpreter and install OpenCV3 and Pillow into it. |
| 52 | + |
| 53 | +If done correctly, all of these packages will be installed as dependencies for those: |
| 54 | + |
| 55 | +```bash |
| 56 | +conda list |
| 57 | +# packages in environment at /home/mohh/anaconda3/envs/thumbler: |
| 58 | +# |
| 59 | +freetype 2.5.5 2 |
| 60 | +jbig 2.1 0 |
| 61 | +jpeg 9b 0 |
| 62 | +libpng 1.6.27 0 |
| 63 | +libtiff 4.0.6 3 |
| 64 | +mkl 2017.0.3 0 |
| 65 | +numpy 1.13.1 py36_0 |
| 66 | +olefile 0.44 py36_0 |
| 67 | +opencv3 3.1.0 py36_0 menpo |
| 68 | +openssl 1.0.2l 0 |
| 69 | +pillow 4.2.1 py36_0 |
| 70 | +pip 9.0.1 py36_1 |
| 71 | +python 3.6.2 0 |
| 72 | +readline 6.2 2 |
| 73 | +setuptools 27.2.0 py36_0 |
| 74 | +sqlite 3.13.0 0 |
| 75 | +tk 8.5.18 0 |
| 76 | +wheel 0.29.0 py36_0 |
| 77 | +xz 5.2.2 1 |
| 78 | +zlib 1.2.8 3 |
| 79 | +``` |
| 80 | + |
| 81 | +### Normal Install |
| 82 | +The usual will get you almost there: |
| 83 | + |
| 84 | +```bash |
| 85 | +cd [Your Projects Directory] |
| 86 | +git clone https://github.com/clamytoe/Thumbler.git |
| 87 | +cd Thumbler |
| 88 | +python3.6 -m venv venv |
| 89 | +source venv/bin/activate |
| 90 | +pip install -r requirements |
| 91 | +``` |
| 92 | +After this step, make sure to follow my instructions on installing OpenCV. |
| 93 | + |
| 94 | +## Usage Example |
| 95 | +The script is really simple to use. Initially I was going to put in the option to just scan a directory full of images and have it extract the faces, but since the HAAR profile that I'm using is only for frontal images, it's really picky. The size of the image seems to play a part on its results as well. |
| 96 | + |
| 97 | +I've included some sample images that worked pretty good and also a few where some faces are not detected, just so that you can get a feel for how it works. I had to tweak the *scaleFactor* settings in some cases in order to NOT detect phantom faces. |
| 98 | + |
| 99 | +```bash |
| 100 | +python thumbler.py samples/beach.jpeg |
| 101 | +Found 12 faces! |
| 102 | +``` |
| 103 | +> All faces detected |
| 104 | + |
| 105 | + |
| 106 | +```bash |
| 107 | +python thumbler.py samples/mirkin.jpeg |
| 108 | +Found 60 faces! |
| 109 | +``` |
| 110 | +> Not all faces detected |
| 111 | + |
| 112 | + |
| 113 | +## Saved Thumbnails |
| 114 | +By default I'm having the extracted thumbnails saved into the Thumbler directory under **thumbs**. In that directory, a new directory is created for each image, based on the name of the image itself. So for the last two runs, my thumbs folder would look like this: |
| 115 | + |
| 116 | +```bash |
| 117 | +thumbs |
| 118 | +├── beach |
| 119 | +│ ├── face_0.jpg |
| 120 | +│ ├── face_10.jpg |
| 121 | +│ ├── face_11.jpg |
| 122 | +│ ├── face_1.jpg |
| 123 | +│ ├── face_2.jpg |
| 124 | +│ ├── face_3.jpg |
| 125 | +│ ├── face_4.jpg |
| 126 | +│ ├── face_5.jpg |
| 127 | +│ ├── face_6.jpg |
| 128 | +│ ├── face_7.jpg |
| 129 | +│ ├── face_8.jpg |
| 130 | +│ └── face_9.jpg |
| 131 | +└── mirkin |
| 132 | + ├── face_0.jpg |
| 133 | + ├── face_10.jpg |
| 134 | + ├── face_11.jpg |
| 135 | + ├── face_12.jpg |
| 136 | + ├── face_13.jpg |
| 137 | + ├── face_14.jpg |
| 138 | + ├── face_15.jpg |
| 139 | + ├── face_16.jpg |
| 140 | + ├── face_17.jpg |
| 141 | + ├── face_18.jpg |
| 142 | + ├── face_19.jpg |
| 143 | + ... |
| 144 | + |
| 145 | +2 directories, 72 files |
| 146 | +``` |
| 147 | + |
| 148 | +Here's a sample of the beach thumbnails: |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | +## Credit |
| 153 | +Most of the credit for this goes to [Real Python](https://realpython.com) for their [Face Recognition with Python, in under 25 lines of code](https://realpython.com/blog/python/face-recognition-with-python/) blog post! |
| 154 | + |
| 155 | +## Release History |
| 156 | +* 0.0.1 |
| 157 | + * Proof of concept |
| 158 | + |
| 159 | +## Meta |
| 160 | + |
| 161 | +Martin Uribe – [@mohhinder](https://twitter.com/mohhinder) – [email protected] |
| 162 | + |
| 163 | +Distributed under the MIT license. See ``LICENSE`` for more information. |
| 164 | + |
| 165 | +[https://github.com/clamytoe/Thumbler](https://github.com/clamytoe/Thumbler) |
| 166 | + |
| 167 | +[issues-image]:https://img.shields.io/github/issues/clamytoe/Thumbler.svg |
| 168 | +[issues-url]:https://github.com/clamytoe/Thumbler/issues |
| 169 | +[fork-image]:https://img.shields.io/github/forks/clamytoe/Thumbler.svg |
| 170 | +[fork-url]:https://github.com/clamytoe/Thumbler/network |
| 171 | +[stars-image]:https://img.shields.io/github/stars/clamytoe/Thumbler.svg |
| 172 | +[stars-url]:https://github.com/clamytoe/Thumbler/stargazers |
| 173 | +[license-image]:https://img.shields.io/badge/license-MIT-blue.svg |
| 174 | +[license-url]:https://raw.githubusercontent.com/clamytoe/Thumbler/master/LICENSE |
| 175 | +[twitter-image]:https://img.shields.io/twitter/url/https/github.com/clamytoe/Thumbler.svg?style=social |
| 176 | +[twitter-url]:https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D |
0 commit comments