aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/bin/utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-08-30 01:27:27 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-08-30 01:27:27 +0300
commit0d88d9328d8fea0f5880580dfc9fab57f6a801c5 (patch)
tree1dd84280ffe73da9a880957a64dada13328bc595 /bin/utils
parentfix Pylint warnings (diff)
downloadfilters-0d88d9328d8fea0f5880580dfc9fab57f6a801c5.tar.gz
filters-0d88d9328d8fea0f5880580dfc9fab57f6a801c5.zip
factor common code out
More helpers & more files.
Diffstat (limited to '')
-rw-r--r--bin/utils/__init__.py0
-rw-r--r--bin/utils/cmd_line.py15
-rw-r--r--bin/utils/image.py16
3 files changed, 31 insertions, 0 deletions
diff --git a/bin/utils/__init__.py b/bin/utils/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/utils/__init__.py
diff --git a/bin/utils/cmd_line.py b/bin/utils/cmd_line.py
new file mode 100644
index 0000000..6bfeafe
--- /dev/null
+++ b/bin/utils/cmd_line.py
@@ -0,0 +1,15 @@
+# Copyright 2016 (c) Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "Simple image filters" project.
+# For details, see https://github.com/egor-tensin/filters.
+# Distributed under the MIT License.
+
+import argparse
+
+def parse_non_negative_integer(s):
+ try:
+ x = int(s)
+ except ValueError:
+ raise argparse.ArgumentTypeError('must be a non-negative integer: ' + s)
+ if x < 0:
+ raise argparse.ArgumentTypeError('must be a non-negative integer: ' + s)
+ return x
diff --git a/bin/utils/image.py b/bin/utils/image.py
new file mode 100644
index 0000000..1dd64cd
--- /dev/null
+++ b/bin/utils/image.py
@@ -0,0 +1,16 @@
+# Copyright 2016 (c) Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "Simple image filters" project.
+# For details, see https://github.com/egor-tensin/filters.
+# Distributed under the MIT License.
+
+import cv2
+
+def load_grayscale(path):
+ return cv2.imread(path, cv2.IMREAD_GRAYSCALE)
+
+def save(path, img):
+ cv2.imwrite(path, img)
+
+def show(img, window_title=None):
+ cv2.imshow(window_title, img)
+ cv2.waitKey()