diff --git a/adaptive_threshold/__init__.py b/adaptive_threshold/__init__.py new file mode 100755 index 0000000..f69e6da --- /dev/null +++ b/adaptive_threshold/__init__.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +"""This programm converts an image into an adaptiveThreshold one. + +Usage: + adaptive_threshold -i -o [-s ] [-b ] [-n] + adaptive_threshold -h | --help + +Options: + -i --input Path to input image + -o --output Path to output image + -b --brightness Change brightness of the output image + -s --size Size of local area + -n --invert Flip black/white + -h --help Show this screen. +""" +from docopt import docopt +import numpy as np +import cv2 as cv + +def apply(img, size=21, brightness=2): + size = size or 21 + brightness = brightness or 2 + return cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, int(size), int(brightness)) + +# face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') +# faces = face_cascade.detectMultiScale(img, 1.3, 5) +# for (x,y,w,h) in faces: +# # To draw a rectangle in a face +# #cv.rectangle(img,(x,y),(x+w,y+h),(255,255,0),2) +# roi_gray = img[y:y+h, x:x+w] +# thresh = roi_gray.mean() +# # img[x:x+w,y:y+h] +# +# ret,th1 = cv.threshold(img, thresh*1.2, 255,cv.THRESH_BINARY) + +def main(): + arguments = docopt(__doc__) + img = cv.imread(arguments["--input"],0) + out = apply(img,arguments["--size"],arguments["--brightness"]) + if arguments["--invert"]: + out = np.abs(out==0)*255 + cv.imwrite(arguments["--output"], out) + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..88463ac --- /dev/null +++ b/setup.py @@ -0,0 +1,15 @@ +from setuptools import setup, find_packages + +setup( + name='adaptive_threshold', + version='0.0.1', + packages=find_packages(include=['adaptive_threshold', 'adaptive_threshold.*']), + install_requires=[ + 'opencv-python-headless', + 'numpy>=1.14.5', + 'docopt', + ], + entry_points={ + 'console_scripts': ['adaptive_threshold=adaptive_threshold:main'] + } +)