-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# import the necessary packages | ||
from .tempfile import TempFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters