#!/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()