rogerxavier commited on
Commit
7fd6b1d
1 Parent(s): 1015d5c

Update 1removeMask.py

Browse files
Files changed (1) hide show
  1. 1removeMask.py +1 -114
1removeMask.py CHANGED
@@ -1,119 +1,6 @@
1
- # import base64
2
-
3
- # import requests
4
- # import os
5
- # from PIL import Image
6
- # import io
7
-
8
- # def inpaint(img_path:str,mask_path:str)->"img content (resp.content)":
9
- # image_bytes = open(img_path, 'rb')
10
- # mask_bytes = open(mask_path, 'rb')
11
- # # 将字节数据转换为Base64编码的字符串
12
-
13
- # files = {
14
- # "image": image_bytes,
15
- # "mask":mask_bytes
16
- # }
17
- # payload = {
18
- # "ldmSteps": 25,
19
- # "ldmSampler": "plms",
20
- # "zitsWireframe": True,
21
- # "hdStrategy": "Crop",
22
- # "hdStrategyCropMargin": 196,
23
- # "hdStrategyCropTrigerSize": 800,
24
- # "hdStrategyResizeLimit": 2048,
25
- # "prompt": "",
26
- # "negativePrompt": "",
27
- # "croperX": 307,
28
- # "croperY": 544,
29
- # "croperHeight": 512,
30
- # "croperWidth": 512,
31
- # "useCroper": False,
32
- # "sdMaskBlur": 5,
33
- # "sdStrength": 0.75,
34
- # "sdSteps": 50,
35
- # "sdGuidanceScale": 7.5,
36
- # "sdSampler": "uni_pc",
37
- # "sdSeed": -1,
38
- # "sdMatchHistograms": False,
39
- # "sdScale": 1,
40
- # "cv2Radius": 5,
41
- # "cv2Flag": "INPAINT_NS",
42
- # "paintByExampleSteps": 50,
43
- # "paintByExampleGuidanceScale": 7.5,
44
- # "paintByExampleSeed": -1,
45
- # "paintByExampleMaskBlur": 5,
46
- # "paintByExampleMatchHistograms": False,
47
- # "p2pSteps": 50,
48
- # "p2pImageGuidanceScale": 1.5,
49
- # "p2pGuidanceScale": 7.5,
50
- # "controlnet_conditioning_scale": 0.4,
51
- # "controlnet_method": "control_v11p_sd15_canny"
52
- # }#payload用data
53
-
54
- # #不使用header
55
- # #resp = requests.post("https://sanster-lama-cleaner-lama.hf.space/inpaint", data=payload, files=files)
56
- # #使用自己的space
57
- # resp = requests.post("https://rogerxavier-lama-cleaner-lama.hf.space/inpaint", data=payload, files=files)
58
-
59
- # print("请求lama clenaer状态是",resp.status_code)
60
- # return bytes(resp.content)
61
-
62
- # def save_img(img_content:"要处理的图片数据",new_save_path:"新文件的保存路径(包含后缀)",old_img_path:"旧文件路径")->"void生成新的文件保存 ,传入旧文件路径是为了删除有问题的旧文件":
63
- # print(new_save_path)
64
- # try:
65
- # img = Image.open(io.BytesIO(img_content))
66
- # # 如果需要指定图像格式,可以在保存时指定
67
- # img.save(new_save_path, format="JPEG")
68
- # except Exception as e:
69
- # #对于可能异常的图片->比如因为不合规导致resp.content没有正常返回
70
- # print(e,new_save_path,"图片返回有问题,跳过并删除图片.这里的路径是新保存路径")
71
- # os.remove(old_img_path)
72
-
73
-
74
-
75
-
76
-
77
- # if __name__ == '__main__':
78
- # # 获取当前目录的子目录的路径
79
- # img_path = 'manga'
80
- # subdir_path = os.path.join(os.getcwd(), img_path)
81
-
82
- # # 图片素材获取(包含子目录下所有图片)
83
- # image_files = []
84
- # for root, dirs, files in os.walk(subdir_path):
85
- # for file in files:
86
- # if file.endswith(".jpg") or file.endswith(".png"):
87
- # image_files.append(os.path.relpath(os.path.join(root, file)))
88
-
89
- # # 创建处理后的子目录在与image_files同级目录下
90
- # processed_subdir_path = os.path.join(os.path.dirname(subdir_path), f"{img_path}1")
91
- # os.makedirs(processed_subdir_path, exist_ok=True)
92
-
93
- # # 对image_files进行某种处理,生成新图片,并保存在处理后的子目录中
94
- # for img_file in image_files:
95
- # # 处理图片的代码(这里仅作示例)
96
- # # 假设处理后的图片为new_img
97
- # img_dir = os.path.dirname(img_file)
98
- # new_img_dir = os.path.join(processed_subdir_path, img_dir)
99
- # os.makedirs(new_img_dir, exist_ok=True)
100
-
101
- # new_img_path = os.path.join(new_img_dir, os.path.basename(img_file))
102
-
103
- # if not os.path.exists(new_img_path):
104
- # #如果已经处理过那么跳过
105
- # # 处理图片并保存
106
- # img_inpainted = inpaint(img_path=img_file, mask_path='mask/0.jpg')#上传的遮罩保存都是0开始
107
- # save_img(img_content=img_inpainted, new_save_path=new_img_path,old_img_path=img_file)
108
- # else:
109
- # print(f"Skipping {new_img_path} as it already exists.")
110
-
111
-
112
-
113
-
114
-
115
 
116
 
 
117
 
118
 
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
 
3
+ #装lama-cleaner==1.2.4来得到其他环境依赖,但是使用的时候用lama_cleaner这个文件的
4
 
5
 
6