guardiancc commited on
Commit
896f3dd
·
verified ·
1 Parent(s): de22012

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -149,19 +149,34 @@ def execute(image, prompt, debug=False):
149
  current_img = imgs[image]
150
  cv2.imwrite('base_image.jpg', current_img)
151
  cv2.imwrite("mask_person.jpg", maskPerson('base_image.jpg'))
152
- #cv2.imwrite("mask.jpg", maskHead('base_image.jpg'))
 
153
 
154
  im = Image.open('base_image.jpg')
155
  np_arr = np.array(im)
156
  rgb_image = cv2.cvtColor(np_arr, cv2.COLOR_BGR2RGB)
157
 
158
  im = Image.fromarray(rgb_image)
159
- person = Image.open('mask_person.jpg')
 
 
160
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  result0 = pipe(
162
  prompt=f"{prompt} {TRIGGER}",
163
  image=im,
164
- mask_image=person,
165
  width=1024,
166
  height=1024,
167
  strength=0.85,
@@ -193,8 +208,10 @@ def execute(image, prompt, debug=False):
193
  if debug:
194
  response.append(im)
195
  response.append(person)
196
- response.append(mask)
 
197
  response.append(result0)
 
198
 
199
  response.append(result)
200
  return response
 
149
  current_img = imgs[image]
150
  cv2.imwrite('base_image.jpg', current_img)
151
  cv2.imwrite("mask_person.jpg", maskPerson('base_image.jpg'))
152
+ cv2.imwrite("mask_face.jpg", maskHead('base_image.jpg'))
153
+
154
 
155
  im = Image.open('base_image.jpg')
156
  np_arr = np.array(im)
157
  rgb_image = cv2.cvtColor(np_arr, cv2.COLOR_BGR2RGB)
158
 
159
  im = Image.fromarray(rgb_image)
160
+
161
+ person = np.array(Image.open('mask_person.jpg'))
162
+ face = np.array(Image.open('mask_face.jpg'))
163
 
164
+ person_gray = cv2.cvtColor(person, cv2.COLOR_BGR2GRAY)
165
+ face_gray = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
166
+
167
+ _, mask = cv2.threshold(face_gray, 1, 255, cv2.THRESH_BINARY_INV)
168
+ mask_inv = cv2.bitwise_not(mask)
169
+ person_masked = cv2.bitwise_and(person_gray, person_gray, mask=mask_inv)
170
+ face_masked = cv2.bitwise_and(face_gray, face_gray, mask=mask)
171
+ result = cv2.add(person_masked, face_masked)
172
+ cv2.imwrite('join.jpg', result)
173
+
174
+ fund_mask = (Image.open('join.jpg')
175
+
176
  result0 = pipe(
177
  prompt=f"{prompt} {TRIGGER}",
178
  image=im,
179
+ mask_image=fund_mask,
180
  width=1024,
181
  height=1024,
182
  strength=0.85,
 
208
  if debug:
209
  response.append(im)
210
  response.append(person)
211
+ response.append(face)
212
+ response.append(fund_mask)
213
  response.append(result0)
214
+ response.append(mask)
215
 
216
  response.append(result)
217
  return response