Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

102 lignes
2.8 KiB

"""Processing."""
import os
import time
from config import Config as Conf
from utils import camel_case_to_str, cv2_supported_extension
class Processing:
""" Abstract Processing Class """
def run(self, *args, config=None):
"""
Run the Image Transform.
:param args: <dict> settings for the transformation
:return: <RGB> image
"""
self.running = True
self._start = time.time()
self._args = Conf.args.copy() if config is None else config.copy()
self._info_start_run()
self._setup(*args)
r = self._execute(*args)
self._clean(*args)
self._info_end_run()
self.running = False
return r
def _info_start_run(self):
"""
Log info at the start of the run.
:return: None
"""
self.__start = time.time()
Conf.log.info("Executing {}".format(camel_case_to_str(self.__class__.__name__)))
def _info_end_run(self):
"""
Log info at the end of the run.
:return: None
"""
Conf.log.debug("{} Done in {} seconds".format(
camel_case_to_str(self.__class__.__name__), round(time.time() - self.__start, 2)))
def _setup(self, *args):
"""
Configure the transformation.
:param args: <dict> settings for the transformation
:return: None
"""
pass
def _execute(self, *args):
"""
Execute the transformation.
:param args: <dict> settings for the transformation
:return: None
"""
pass
def _clean(self, *args):
"""
Clean the transformation.
:param args: <dict> settings for the transformation
:return: None
"""
pass
class SimpleProcessing(Processing):
"""Simple Transform Class."""
def __init__(self, args=None):
"""
Construct a Simple Processing .
:param args: <dict> args parameter to run the image transformation (default use Conf.args)
"""
super().__init__(args)
def __new__(cls, args=None):
"""
Create the correct SimpleTransform object corresponding to the input_path format.
:param args: <dict> args parameter to run the image transformation (default use Conf.args)
:return: <ImageProcessing|GiftProcessing|None> SimpleTransform object corresponding to the input_path format
"""
args = Conf.args.copy() if args is None else args.copy()
if os.path.splitext(args['input'])[1] == ".gif":
from processing.gif import GifProcessing
return GifProcessing()
elif os.path.splitext(args['input'])[1] in cv2_supported_extension():
from processing.image import ImageProcessing
return ImageProcessing()
else:
return None