Skip to content
Snippets Groups Projects
Commit 7106a2be authored by Hyunseok_Sang's avatar Hyunseok_Sang
Browse files

포토샵 자동화를 통한 배경 제거 구현

parent 5d9deae2
No related branches found
No related tags found
No related merge requests found
Showing
with 343 additions and 7 deletions
sources/
.env .env
*.onnx *.onnx
google_cloud_vision_key.json google_cloud_vision_key.json
__pycache__/
\ No newline at end of file
File deleted
...@@ -5,7 +5,7 @@ from modules import image_processor ...@@ -5,7 +5,7 @@ from modules import image_processor
from modules import fileManager from modules import fileManager
from modules import object_detector from modules import object_detector
from modules import database from modules import database
from modules import photoshop
with open(sys.argv[1], 'r', encoding='UTF8') as file: with open(sys.argv[1], 'r', encoding='UTF8') as file:
shoppingmall_data = json.load(file) shoppingmall_data = json.load(file)
...@@ -22,11 +22,13 @@ clothesDetector = object_detector.ClothesDetector() ...@@ -22,11 +22,13 @@ clothesDetector = object_detector.ClothesDetector()
databaseManager = database.DatabaseManager() databaseManager = database.DatabaseManager()
photoshop_ = photoshop.Photoshop()
for product in shoppingmall_data["product_list"]: for product in shoppingmall_data["product_list"]:
save_path = "image_data/"+seller_brand_path+"/"+product["name"] save_path = "image_data/"+seller_brand_path+"/"+product["name"]
image_url = product["url"] image_url = product["url"]
image_path = imageDownloder.download_image(image_url, save_path, "original.jpg") image_path = imageDownloder.download_image(image_url, save_path, "original.jpg")
image = imageFactory.create_image(image_path, None) image = imageFactory.create_image(image_path, None, image_url)
result_image = imageProcessor.process(image) result_image = imageProcessor.process(image)
...@@ -37,6 +39,6 @@ for product in shoppingmall_data["product_list"]: ...@@ -37,6 +39,6 @@ for product in shoppingmall_data["product_list"]:
clothes = clothesDataList.getClothes(product["type_of_clothes"]) clothes = clothesDataList.getClothes(product["type_of_clothes"])
clothes.denormalizeByImageSize(image) clothes.denormalizeByImageSize(image)
no_background_image_path = photoshop_.backgroundRemover(image_path)
databaseManager.insertToClothesDataCollection(image, image_url, result_image, face, clothes) databaseManager.insertToClothesDataCollection(image, image_url, result_image, face, clothes)
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
...@@ -32,7 +32,7 @@ class ImageSaver: ...@@ -32,7 +32,7 @@ class ImageSaver:
class Image: class Image:
def __init__(self, filepath, cv_image): def __init__(self, filepath, cv_image, url = None):
if filepath is not None: if filepath is not None:
self.filepath = os.path.abspath(filepath) self.filepath = os.path.abspath(filepath)
if cv_image is not None: if cv_image is not None:
...@@ -42,7 +42,7 @@ class Image: ...@@ -42,7 +42,7 @@ class Image:
self.cv_image = cv2.imdecode(img_array, cv2.IMREAD_COLOR) self.cv_image = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
self.height = self.cv_image.shape[0] self.height = self.cv_image.shape[0]
self.width = self.cv_image.shape[1] self.width = self.cv_image.shape[1]
self.url = None self.url = url
def setURL(self, url): def setURL(self, url):
self.url = url self.url = url
class ImageFactory: class ImageFactory:
......
import subprocess
import os
class Photoshop:
def __init__(self, photoshop_path) -> None:
self.photoshop_path = photoshop_path
self.backgroundRemover = BackgroundRemover()
'''
def run_script(self, script_path):
subprocess.run([self.photoshop_path, script_path])
'''
def remove_background(self, file_path):
return self.backgroundRemover.remove_background(file_path, self.photoshop_path)
class BackgroundRemover:
def __init__(self):
pass
def remove_background(self, file_path, photoshop_path):
open_path = file_path.replace("\\", "\\\\")
save_path = os.path.dirname(file_path)
save_path = os.path.join(save_path, "no_background.png")
save_path = save_path.replace("\\", "\\\\")
jsx_code = f"""
var idOpn = charIDToTypeID( "Opn " );
var desc349 = new ActionDescriptor();
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc349.putBoolean( iddontRecord, false );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc349.putBoolean( idforceNotify, true );
var idnull = charIDToTypeID( "null" );
desc349.putPath( idnull, new File( "{open_path}" ) );
var idDocI = charIDToTypeID( "DocI" );
desc349.putInteger( idDocI, 72 );
var idtemplate = stringIDToTypeID( "template" );
desc349.putBoolean( idtemplate, false );
executeAction( idOpn, desc349, DialogModes.NO );
// ======================
var idsetd = charIDToTypeID( "setd" );
var desc326 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref15 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idBckg = charIDToTypeID( "Bckg" );
ref15.putProperty( idLyr, idBckg );
desc326.putReference( idnull, ref15 );
var idT = charIDToTypeID( "T " );
var desc327 = new ActionDescriptor();
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc327.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc327.putEnumerated( idMd, idBlnM, idNrml );
var idLyr = charIDToTypeID( "Lyr " );
desc326.putObject( idT, idLyr, desc327 );
var idLyrI = charIDToTypeID( "LyrI" );
desc326.putInteger( idLyrI, 5 );
executeAction( idsetd, desc326, DialogModes.NO );
// ===================================================
var idremoveBackground = stringIDToTypeID( "removeBackground" );
executeAction( idremoveBackground, undefined, DialogModes.NO );
// =======================================================
var idsave = charIDToTypeID( "save" );
var desc255 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc256 = new ActionDescriptor();
var idMthd = charIDToTypeID( "Mthd" );
var idPNGMethod = stringIDToTypeID( "PNGMethod" );
var idquick = stringIDToTypeID( "quick" );
desc256.putEnumerated( idMthd, idPNGMethod, idquick );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIN = charIDToTypeID( "PGIN" );
desc256.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "PNGf" );
var idPNGf = charIDToTypeID( "PNGf" );
var idPGAd = charIDToTypeID( "PGAd" );
desc256.putEnumerated( idPNGf, idPNGf, idPGAd );
var idCmpr = charIDToTypeID( "Cmpr" );
desc256.putInteger( idCmpr, 6 );
var idembedIccProfileLastState = stringIDToTypeID( "embedIccProfileLastState" );
var idembedOff = stringIDToTypeID( "embedOff" );
var idembedOff = stringIDToTypeID( "embedOff" );
desc256.putEnumerated( idembedIccProfileLastState, idembedOff, idembedOff );
var idPNGF = charIDToTypeID( "PNGF" );
desc255.putObject( idAs, idPNGF, desc256 );
var idIn = charIDToTypeID( "In " );
desc255.putPath( idIn, new File( "{save_path}" ) );
var idDocI = charIDToTypeID( "DocI" );
desc255.putInteger( idDocI, 59 );
var idLwCs = charIDToTypeID( "LwCs" );
desc255.putBoolean( idLwCs, true );
var idEmbP = charIDToTypeID( "EmbP" );
desc255.putBoolean( idEmbP, false );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc255.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc255, DialogModes.NO );
// =======================================================
var idCls = charIDToTypeID( "Cls " );
var desc322 = new ActionDescriptor();
var idSvng = charIDToTypeID( "Svng" );
var idYsN = charIDToTypeID( "YsN " );
var idN = charIDToTypeID( "N " );
desc322.putEnumerated( idSvng, idYsN, idN );
var idDocI = charIDToTypeID( "DocI" );
desc322.putInteger( idDocI, 88 );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc322.putBoolean( idforceNotify, true );
executeAction( idCls, desc322, DialogModes.NO );
"""
jsx_file_path = "remove_background.jsx"
with open(jsx_file_path, "w") as file:
file.write(jsx_code)
subprocess.Popen([photoshop_path, jsx_file_path])
return save_path
\ No newline at end of file
var idOpn = charIDToTypeID( "Opn " );
var desc349 = new ActionDescriptor();
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc349.putBoolean( iddontRecord, false );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc349.putBoolean( idforceNotify, true );
var idnull = charIDToTypeID( "null" );
desc349.putPath( idnull, new File( "\\\\wsl.localhost\\Ubuntu-22.04\\home\\sang\\automated_image_processing\\front-end\\images\\first_images\\original.jpg" ) );
var idDocI = charIDToTypeID( "DocI" );
desc349.putInteger( idDocI, 72 );
var idtemplate = stringIDToTypeID( "template" );
desc349.putBoolean( idtemplate, false );
executeAction( idOpn, desc349, DialogModes.NO );
// ======================
var idsetd = charIDToTypeID( "setd" );
var desc326 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref15 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idBckg = charIDToTypeID( "Bckg" );
ref15.putProperty( idLyr, idBckg );
desc326.putReference( idnull, ref15 );
var idT = charIDToTypeID( "T " );
var desc327 = new ActionDescriptor();
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc327.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc327.putEnumerated( idMd, idBlnM, idNrml );
var idLyr = charIDToTypeID( "Lyr " );
desc326.putObject( idT, idLyr, desc327 );
var idLyrI = charIDToTypeID( "LyrI" );
desc326.putInteger( idLyrI, 5 );
executeAction( idsetd, desc326, DialogModes.NO );
// ===================================================
var idremoveBackground = stringIDToTypeID( "removeBackground" );
executeAction( idremoveBackground, undefined, DialogModes.NO );
// =======================================================
var idsave = charIDToTypeID( "save" );
var desc255 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc256 = new ActionDescriptor();
var idMthd = charIDToTypeID( "Mthd" );
var idPNGMethod = stringIDToTypeID( "PNGMethod" );
var idquick = stringIDToTypeID( "quick" );
desc256.putEnumerated( idMthd, idPNGMethod, idquick );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIN = charIDToTypeID( "PGIN" );
desc256.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "PNGf" );
var idPNGf = charIDToTypeID( "PNGf" );
var idPGAd = charIDToTypeID( "PGAd" );
desc256.putEnumerated( idPNGf, idPNGf, idPGAd );
var idCmpr = charIDToTypeID( "Cmpr" );
desc256.putInteger( idCmpr, 6 );
var idembedIccProfileLastState = stringIDToTypeID( "embedIccProfileLastState" );
var idembedOff = stringIDToTypeID( "embedOff" );
var idembedOff = stringIDToTypeID( "embedOff" );
desc256.putEnumerated( idembedIccProfileLastState, idembedOff, idembedOff );
var idPNGF = charIDToTypeID( "PNGF" );
desc255.putObject( idAs, idPNGF, desc256 );
var idIn = charIDToTypeID( "In " );
desc255.putPath( idIn, new File( "\\\\wsl.localhost\\Ubuntu-22.04\\home\\sang\\automated_image_processing\\front-end\\images\\first_images\\noBackground6.png" ) );
var idDocI = charIDToTypeID( "DocI" );
desc255.putInteger( idDocI, 59 );
var idLwCs = charIDToTypeID( "LwCs" );
desc255.putBoolean( idLwCs, true );
var idEmbP = charIDToTypeID( "EmbP" );
desc255.putBoolean( idEmbP, false );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc255.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc255, DialogModes.NO );
// =======================================================
var idCls = charIDToTypeID( "Cls " );
var desc322 = new ActionDescriptor();
var idSvng = charIDToTypeID( "Svng" );
var idYsN = charIDToTypeID( "YsN " );
var idN = charIDToTypeID( "N " );
desc322.putEnumerated( idSvng, idYsN, idN );
var idDocI = charIDToTypeID( "DocI" );
desc322.putInteger( idDocI, 88 );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc322.putBoolean( idforceNotify, true );
executeAction( idCls, desc322, DialogModes.NO );
\ No newline at end of file
var idOpn = charIDToTypeID( "Opn " );
var desc349 = new ActionDescriptor();
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc349.putBoolean( iddontRecord, false );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc349.putBoolean( idforceNotify, true );
var idnull = charIDToTypeID( "null" );
desc349.putPath( idnull, new File( "C:\\SDP\\automated_image_processing\\back-end\\source_code\\image_data\\ssfshop\\beanpole\\남녀공용 베이직 피케 티셔츠 - 블랙\\original.jpg" ) );
var idDocI = charIDToTypeID( "DocI" );
desc349.putInteger( idDocI, 72 );
var idtemplate = stringIDToTypeID( "template" );
desc349.putBoolean( idtemplate, false );
executeAction( idOpn, desc349, DialogModes.NO );
// ======================
var idsetd = charIDToTypeID( "setd" );
var desc326 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref15 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idBckg = charIDToTypeID( "Bckg" );
ref15.putProperty( idLyr, idBckg );
desc326.putReference( idnull, ref15 );
var idT = charIDToTypeID( "T " );
var desc327 = new ActionDescriptor();
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc327.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc327.putEnumerated( idMd, idBlnM, idNrml );
var idLyr = charIDToTypeID( "Lyr " );
desc326.putObject( idT, idLyr, desc327 );
var idLyrI = charIDToTypeID( "LyrI" );
desc326.putInteger( idLyrI, 5 );
executeAction( idsetd, desc326, DialogModes.NO );
// ===================================================
var idremoveBackground = stringIDToTypeID( "removeBackground" );
executeAction( idremoveBackground, undefined, DialogModes.NO );
// =======================================================
var idsave = charIDToTypeID( "save" );
var desc255 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc256 = new ActionDescriptor();
var idMthd = charIDToTypeID( "Mthd" );
var idPNGMethod = stringIDToTypeID( "PNGMethod" );
var idquick = stringIDToTypeID( "quick" );
desc256.putEnumerated( idMthd, idPNGMethod, idquick );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIN = charIDToTypeID( "PGIN" );
desc256.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "PNGf" );
var idPNGf = charIDToTypeID( "PNGf" );
var idPGAd = charIDToTypeID( "PGAd" );
desc256.putEnumerated( idPNGf, idPNGf, idPGAd );
var idCmpr = charIDToTypeID( "Cmpr" );
desc256.putInteger( idCmpr, 6 );
var idembedIccProfileLastState = stringIDToTypeID( "embedIccProfileLastState" );
var idembedOff = stringIDToTypeID( "embedOff" );
var idembedOff = stringIDToTypeID( "embedOff" );
desc256.putEnumerated( idembedIccProfileLastState, idembedOff, idembedOff );
var idPNGF = charIDToTypeID( "PNGF" );
desc255.putObject( idAs, idPNGF, desc256 );
var idIn = charIDToTypeID( "In " );
desc255.putPath( idIn, new File( "C:\\SDP\\automated_image_processing\\back-end\\source_code\\image_data\\ssfshop\\beanpole\\남녀공용 베이직 피케 티셔츠 - 블랙\\no_background.jpg" ) );
var idDocI = charIDToTypeID( "DocI" );
desc255.putInteger( idDocI, 59 );
var idLwCs = charIDToTypeID( "LwCs" );
desc255.putBoolean( idLwCs, true );
var idEmbP = charIDToTypeID( "EmbP" );
desc255.putBoolean( idEmbP, false );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc255.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc255, DialogModes.NO );
// =======================================================
var idCls = charIDToTypeID( "Cls " );
var desc322 = new ActionDescriptor();
var idSvng = charIDToTypeID( "Svng" );
var idYsN = charIDToTypeID( "YsN " );
var idN = charIDToTypeID( "N " );
desc322.putEnumerated( idSvng, idYsN, idN );
var idDocI = charIDToTypeID( "DocI" );
desc322.putInteger( idDocI, 88 );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc322.putBoolean( idforceNotify, true );
executeAction( idCls, desc322, DialogModes.NO );
\ No newline at end of file
import subprocess
from modules import photoshop
photoshop_path = "C:/Program Files/Adobe/Adobe Photoshop 2023/Photoshop.exe"
script_path = "C:\\SDP\\automated_image_processing\\back-end\\source_code\\modules\\remove_background.jsx"
file_path = "C:\\SDP\\automated_image_processing\\back-end\\source_code\\image_data\\ssfshop\\beanpole\\남녀공용 베이직 피케 티셔츠 - 블랙\\original.jpg"
photoshop = photoshop.Photoshop(photoshop_path)
photoshop.remove_background(file_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment