Skip to content

Commit b5d01b6

Browse files
clamytoepybites
authored andcommitted
My submission for the PCC31 challenge. (pybites#92)
* Initial commit * Credit whre credit is due * Added OpenCV install instructions for Anaconda * Updated requirements.txt, added export of my Anaconda virtual environment and instructions on how to use it in the README.md
1 parent 26fb203 commit b5d01b6

20 files changed

+33818
-0
lines changed

31/clamytoe/.gitignore

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
local_settings.py
56+
57+
# Flask stuff:
58+
instance/
59+
.webassets-cache
60+
61+
# Scrapy stuff:
62+
.scrapy
63+
64+
# Sphinx documentation
65+
docs/_build/
66+
67+
# PyBuilder
68+
target/
69+
70+
# Jupyter Notebook
71+
.ipynb_checkpoints
72+
73+
# pyenv
74+
.python-version
75+
76+
# celery beat schedule file
77+
celerybeat-schedule
78+
79+
# SageMath parsed files
80+
*.sage.py
81+
82+
# dotenv
83+
.env
84+
85+
# virtualenv
86+
.venv
87+
venv/
88+
ENV/
89+
90+
# Spyder project settings
91+
.spyderproject
92+
.spyproject
93+
94+
# Rope project settings
95+
.ropeproject
96+
97+
# mkdocs documentation
98+
/site
99+
100+
# mypy
101+
.mypy_cache/
102+
103+
# PyCharm
104+
.idea/
105+
106+
# Thunbler
107+
thumbs/

31/clamytoe/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Martin Uribe
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.

31/clamytoe/README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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+
![beach](img/beach.png)
105+
106+
```bash
107+
python thumbler.py samples/mirkin.jpeg
108+
Found 60 faces!
109+
```
110+
> Not all faces detected
111+
![mirkin](img/mirkin.png)
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+
![thumbnails](img/thumbnails.png)
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

31/clamytoe/conda_venv.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: thumbler
2+
channels:
3+
- menpo
4+
- defaults
5+
- https://conda.anaconda.org/menpo
6+
dependencies:
7+
- freetype=2.5.5=2
8+
- jbig=2.1=0
9+
- jpeg=9b=0
10+
- libpng=1.6.27=0
11+
- libtiff=4.0.6=3
12+
- mkl=2017.0.3=0
13+
- numpy=1.13.1=py36_0
14+
- olefile=0.44=py36_0
15+
- openssl=1.0.2l=0
16+
- pillow=4.2.1=py36_0
17+
- pip=9.0.1=py36_1
18+
- python=3.6.2=0
19+
- readline=6.2=2
20+
- setuptools=27.2.0=py36_0
21+
- sqlite=3.13.0=0
22+
- tk=8.5.18=0
23+
- wheel=0.29.0=py36_0
24+
- xz=5.2.2=1
25+
- zlib=1.2.8=3
26+
- opencv3=3.1.0=py36_0
27+
prefix: /home/mohh/anaconda3/envs/thumbler
28+

0 commit comments

Comments
 (0)