parent
adaac35b1b
commit
5d7828046a
@ -0,0 +1,45 @@ |
|||||||
|
#!/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() |
@ -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'] |
||||||
|
} |
||||||
|
) |
Loading…
Reference in new issue