App/Model.py
def export_imgs(self, sfpn, tfpn, tsufix):
        """
        Export images from source files into target files with CV2

        Args:
            sfpn (list): local filepaths of source images
            tfpn (list): local filepaths of target images
            tsufix (dict): target image file sufix, ie.: "-rgb"

        Raises:
            exp: raise a generic exception if something goes wrong

        Returns:
            ans (dict): relative filepaths for the target images
        """
        try:
            # default answer
            ans = dict()
            wans = dict()
            for key in tsufix.keys():
                wans[key] = str()

            # checking if both list have images
            eq1 = (len(sfpn) > 0) and (len(tfpn) > 0)
            # checking if the target files and the keys equal
            eq2 = (len(tfpn) == len(tsufix.keys()))

            # evaluating both conditions
            if eq1 and eq2:

                # iterating in the source files
                for sf in sfpn:

                    # iterating in the target files paths and keys
                    for tf, key in zip(tfpn, tsufix.keys()):
                        # default temporal variables
                        complete = False
                        tdf = None

                        # checking if is RGB
                        # if any("rgb" in s for s in (tf, key)):
                        if "rgb" in tf:
                            # opening the source file
                            tdf = cv2.imread(sf, cv2.IMREAD_UNCHANGED)
                            # exporting/saving to RBG file
                            complete = cv2.imwrite(tf, tdf)

                        # checking if is B&W
                        # elif any("bw" in s for s in (tf, key)):
                        elif "bw" in tf:
                            # opening the source file
                            tdf = cv2.imread(sf, cv2.IMREAD_GRAYSCALE)
                            # convert = cv2.COLOR_BGR2GRAY
                            # tdf = cv2.cvtColor(tdf, convert)
                            # exporting/saving to B&W file
                            complete = cv2.imwrite(tf, tdf)

                        # updating answer dict
                        if complete is True:
                            # recovering the important relative path
                            tf = os.path.normpath(tf)
                            tf = tf.split(os.sep)
                            tf = tf[len(tf)-4:len(tf)]
                            tf = os.path.join(*tf)
                            td = {key: tf}
                            wans.update(td)

            # returning answer
            ans = copy.deepcopy(wans)
            return ans

        # exception handling
        except Exception as exp:
            Err.reraise(exp, "Gallery: export_imgs")

        Export images from source files into target files with CV2

        Args:
            sfpn (list): local filepaths of source images
            tfpn (list): local filepaths of target images
            tsufix (dict): target image file sufix, ie.: "-rgb"

        Raises:
            exp: raise a generic exception if something goes wrong

        Returns:
            ans (dict): relative filepaths for the target images
        
Export images from source files into target files with CV2
Export images from source files into target files with CV2
def export_imgs(self, sfpn, tfpn, tsufix):
        try:
            ans = dict()
            wans = dict()
            for key in tsufix.keys():
                wans[key] = str()
            eq1 = (len(sfpn) > 0) and (len(tfpn) > 0)
            eq2 = (len(tfpn) == len(tsufix.keys()))
            if eq1 and eq2:
                for sf in sfpn:
                    for tf, key in zip(tfpn, tsufix.keys()):
                        complete = False
                        tdf = None
                        if "rgb" in tf:
                            tdf = cv2.imread(sf, cv2.IMREAD_UNCHANGED)
                            complete = cv2.imwrite(tf, tdf)
                        elif "bw" in tf:
                            tdf = cv2.imread(sf, cv2.IMREAD_GRAYSCALE)
                            complete = cv2.imwrite(tf, tdf)
                        if complete is True:
                            tf = os.path.normpath(tf)
                            tf = tf.split(os.sep)
                            tf = tf[len(tf)-4:len(tf)]
                            tf = os.path.join(*tf)
                            td = {key: tf}
                            wans.update(td)
            ans = copy.deepcopy(wans)
            return ans
        except Exception as exp:
            Err.reraise(exp, "Gallery: export_imgs")
def export_imgs ( self , sfpn , tfpn , tsufix ) : try : ans = dict ( ) wans = dict ( ) for key in tsufix . keys ( ) : wans [ key ] = str ( ) eq1 = ( len ( sfpn ) > 0 ) and ( len ( tfpn ) > 0 ) eq2 = ( len ( tfpn ) == len ( tsufix . keys ( ) ) ) if eq1 and eq2 : for sf in sfpn : for tf , key in zip ( tfpn , tsufix . keys ( ) ) : complete = False tdf = None if "rgb" in tf : tdf = cv2 . imread ( sf , cv2 . IMREAD_UNCHANGED ) complete = cv2 . imwrite ( tf , tdf ) elif "bw" in tf : tdf = cv2 . imread ( sf , cv2 . IMREAD_GRAYSCALE ) complete = cv2 . imwrite ( tf , tdf ) if complete is True : tf = os . path . normpath ( tf ) tf = tf . split ( os . sep ) tf = tf [ len ( tf ) - 4 : len ( tf ) ] tf = os . path . join ( * tf ) td = { key : tf } wans . update ( td ) ans = copy . deepcopy ( wans ) return ans except Exception as exp : Err . reraise ( exp , "Gallery: export_imgs" )
Export images from source files into target files with CV2
Export images from source files into target files with CV2
"""
        Export images from source files into target files with CV2

        Args:
            sfpn (list): local filepaths of source images
            tfpn (list): local filepaths of target images
            tsufix (dict): target image file sufix, ie.: "-rgb"

        Raises:
            exp: raise a generic exception if something goes wrong

        Returns:
            ans (dict): relative filepaths for the target images
        """ # default answer # checking if both list have images # checking if the target files and the keys equal # evaluating both conditions # iterating in the source files # iterating in the target files paths and keys # default temporal variables # checking if is RGB # if any("rgb" in s for s in (tf, key)): # opening the source file # exporting/saving to RBG file # checking if is B&W # elif any("bw" in s for s in (tf, key)): # opening the source file # convert = cv2.COLOR_BGR2GRAY # tdf = cv2.cvtColor(tdf, convert) # exporting/saving to B&W file # updating answer dict # recovering the important relative path # returning answer # exception handling
ans (dict): relative filepaths for the target images
ans ( dict ) : relative filepaths for the target images
raise a generic exception if something goes wrong
raise a generic exception if something goes wrong
exp
self
sfpn
local filepaths of source images
local filepaths of source images
tfpn
local filepaths of target images
local filepaths of target images
tsufix
target image file sufix, ie.: "-rgb"
target image file sufix ie . : " - rgb "