From ff1cc11b4e6056ea403df6db2e2d15d792c64884 Mon Sep 17 00:00:00 2001 From: Adrian Rosebrock Date: Fri, 12 Feb 2016 13:26:55 -0500 Subject: [PATCH] Next release of imutils --- demos/temp_file.py | 29 +++++++++++++++++++++++++++++ imutils/io/__init__.py | 2 ++ imutils/io/tempfile.py | 13 +++++++++++++ setup.py | 2 +- 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 demos/temp_file.py create mode 100644 imutils/io/__init__.py create mode 100644 imutils/io/tempfile.py diff --git a/demos/temp_file.py b/demos/temp_file.py new file mode 100644 index 0000000..c4025e1 --- /dev/null +++ b/demos/temp_file.py @@ -0,0 +1,29 @@ +# author: Adrian Rosebrock +# website: http://www.pyimagesearch.com + +# USAGE +# BE SURE TO INSTALL 'imutils' PRIOR TO EXECUTING THIS COMMAND +# python temp_file.py --image ../demo_images/bridge.jpg + +# import the necessary packages +from __future__ import print_function +from imutils.io import TempFile +import argparse +import cv2 + +# construct the argument parser and parse the arguments +ap = argparse.ArgumentParser() +ap.add_argument("-i", "--image", required=True, help="path to input image") +args = ap.parse_args() + +# load the input image +image = cv2.imread(args.image) + +# create a temporary path for the image, then write the image +# to file +t = TempFile() +cv2.imwrite(t.path, image) +print("[INFO] path: {}".format(t.path)) + +# delete the file +t.cleanup() \ No newline at end of file diff --git a/imutils/io/__init__.py b/imutils/io/__init__.py new file mode 100644 index 0000000..ab81a79 --- /dev/null +++ b/imutils/io/__init__.py @@ -0,0 +1,2 @@ +# import the necessary packages +from .tempfile import TempFile \ No newline at end of file diff --git a/imutils/io/tempfile.py b/imutils/io/tempfile.py new file mode 100644 index 0000000..f13424a --- /dev/null +++ b/imutils/io/tempfile.py @@ -0,0 +1,13 @@ +# import the necessary packages +import uuid +import os + +class TempFile: + def __init__(self, basePath="./", ext=".jpg"): + # construct the file path + self.path = "{base_path}/{rand}{ext}".format(base_path=basePath, rand=str(uuid.uuid4()), + ext=ext) + + def cleanup(self): + # remove the file + os.remove(self.path) \ No newline at end of file diff --git a/setup.py b/setup.py index ccbdf1a..b73b700 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='imutils', - packages=['imutils', 'imutils.video'], + packages=['imutils', 'imutils.video', 'imutils.io'], version='0.3.4', description='A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, displaying Matplotlib images, sorting contours, detecting edges, and much more easier with OpenCV and both Python 2.7 and Python 3.', author='Adrian Rosebrock',