You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
#!/usr/bin/env python
|
|
"""This programm converts an image into an adaptiveThreshold one.
|
|
|
|
Usage:
|
|
adaptive_threshold -i <source> -o <output> [-s <int>] [-b <int>] [-n]
|
|
adaptive_threshold -h | --help
|
|
|
|
Options:
|
|
-i <source> --input <source> Path to input image
|
|
-o <target> --output <target> Path to output image
|
|
-b <int> --brightness <int> Change brightness of the output image
|
|
-s <int> --size <int> 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()
|
|
|