Update app.py
Browse files
app.py
CHANGED
|
@@ -174,8 +174,17 @@ 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 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
cv2.imwrite(fl, fr)
|
| 180 |
return fl
|
| 181 |
else: # even: with the flash
|
|
@@ -290,7 +299,9 @@ with gr.Blocks() as demo:
|
|
| 290 |
|
| 291 |
gr.Examples(
|
| 292 |
examples=[[
|
| 293 |
-
["./examples/0.png", "./examples/1.png", "./examples/2.png", "./examples/3.png", "./examples/4.png"],
|
|
|
|
|
|
|
| 294 |
]],
|
| 295 |
fn=loadf,
|
| 296 |
inputs=[files_orig, r_bg],
|
|
|
|
| 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.imread(fl_).astype(np.uint8)
|
| 178 |
+
fr_mask = fr_diff - cv2.cvtColor(fr_mask, cv2.COLOR_BGR2GRAY)
|
| 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>0] = (fr[fr_mask>0] / 17).astype(np.uint8)
|
| 186 |
+
fr[fr_diff==0] = (255,255,255)
|
| 187 |
+
|
| 188 |
cv2.imwrite(fl, fr)
|
| 189 |
return fl
|
| 190 |
else: # even: with the flash
|
|
|
|
| 299 |
|
| 300 |
gr.Examples(
|
| 301 |
examples=[[
|
| 302 |
+
["./examples/0.png", "./examples/1.png", "./examples/2.png", "./examples/3.png", "./examples/4.png"], False
|
| 303 |
+
], [
|
| 304 |
+
["./examples/0_flash.jpg", "./examples/1_noflash.jpg", "./examples/2_flash.jpg", "./examples/3_noflash.jpg"], True
|
| 305 |
]],
|
| 306 |
fn=loadf,
|
| 307 |
inputs=[files_orig, r_bg],
|