Skip to content

Commit

Permalink
Add cropper library and console app
Browse files Browse the repository at this point in the history
  • Loading branch information
ufoym committed Jul 1, 2014
0 parents commit fd28a90
Show file tree
Hide file tree
Showing 10 changed files with 33,705 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
94 changes: 94 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/


# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Icon must ends with two \r.
Icon

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Windows
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Requirements
------------
- Numpy
- OpenCV
- Docopt (Console)


Cropman Console
---------------

Usage:
app-console.py <input-image> <target-width> <target-height> <target-image>

Options:
-h --help Show this screen.
--version Show version.
43 changes: 43 additions & 0 deletions app-console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Cropman Console
~~~~~~~~~~~~~~~
Face-aware image cropper application (console interface).
:copyright: (c) 2014 by Ming YANG.
:license: WTFPL (Do What the Fuck You Want to Public License).
Usage:
app-console.py <input-image> <target-width> <target-height> <target-image>
Options:
-h --help Show this screen.
--version Show version.
"""

from cropman.cropper import Cropper
from docopt import docopt
import cv2

if __name__ == '__main__':
arguments = docopt(__doc__, version='Cropman Console 0.1.0')
input_filename = arguments['<input-image>']
target_filename = arguments['<target-image>']
target_width = int(arguments['<target-width>'])
target_height = int(arguments['<target-height>'])

cropper = Cropper()
input_image = cv2.imread(input_filename)
if input_image is None:
print 'Invalid input image. Please check %s' % input_filename
else:
target_image = cropper.crop(input_image, target_width, target_height)
if target_image is None:
print 'Cropping failed.'
else:
cv2.imwrite(target_filename, target_image)
print '\nDone. \nResult: %s' % target_filename

5 changes: 5 additions & 0 deletions cropman/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-

__author__ = 'Ming YANG'
__email__ = '[email protected]'
__version__ = '0.1.0'
Loading

0 comments on commit fd28a90

Please sign in to comment.