freealise commited on
Commit
4d58024
·
verified ·
1 Parent(s): 56dbce8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -174,16 +174,18 @@ def remove_bg(fl, count):
174
  fr_diff = cv2.dilate(cv2.erode(fr_diff, element), element)
175
 
176
  if count % 2: # odd: is photo without the flash
177
- fr_mask = np.bitwise_not(cv2.cvtColor(cv2.imread(fl_).astype(np.uint8), cv2.COLOR_BGR2GRAY))
178
- fr_mask = np.bitwise_and(fr_diff, fr_mask).astype(np.uint8)
 
 
179
  cv2.imwrite(fl_, fr_mask)
180
 
181
- m = cv2.inRange(fr, np.array([240,240,240]), np.array([255,255,255]))
182
- fr[m>0] = (239,239,239)
183
- m = cv2.inRange(fr, np.array([0,0,0]), np.array([15,15,15]))
184
- fr[m>0] = (16,16,16)
185
- fr[fr_mask==255] = (fr[fr_mask==255] / 17).astype(np.uint8)
186
- fr[fr_diff==0] = (255,255,255)
187
 
188
  cv2.imwrite(fl, fr)
189
  return fl
 
174
  fr_diff = cv2.dilate(cv2.erode(fr_diff, element), element)
175
 
176
  if count % 2: # odd: is photo without the flash
177
+ fr_mask = cv2.cvtColor(cv2.imread(fl_).astype(np.uint8), cv2.COLOR_BGR2GRAY)
178
+ fr_not = np.bitwise_not(fr_mask)
179
+ fr_shadow = np.bitwise_and(fr_diff, fr_not).astype(np.uint8)
180
+ fr_fg = np.bitwise_or(fr_diff, fr_mask).astype(np.uint8)
181
  cv2.imwrite(fl_, fr_mask)
182
 
183
+ #m = cv2.inRange(fr, np.array([240,240,240]), np.array([255,255,255]))
184
+ #fr[m>0] = (239,239,239)
185
+ #m = cv2.inRange(fr, np.array([0,0,0]), np.array([15,15,15]))
186
+ #fr[m>0] = (16,16,16)
187
+ fr[fr_shadow>0] = (fr[fr_shadow>0] / 17).astype(np.uint8)
188
+ fr[fr_fg==0] = (255,255,255)
189
 
190
  cv2.imwrite(fl, fr)
191
  return fl