Update app.py
Browse files
app.py
CHANGED
|
@@ -205,15 +205,21 @@ def remove_bg(fl, count, mh, ms, md, lm):
|
|
| 205 |
|
| 206 |
cv2.imwrite(fl, fr)
|
| 207 |
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
return fl #f"{str(count)}_cutout.png"
|
| 218 |
else: # even: with the flash
|
| 219 |
fl_ = fl.split(".")[0] + "_.png"
|
|
@@ -222,7 +228,7 @@ def remove_bg(fl, count, mh, ms, md, lm):
|
|
| 222 |
|
| 223 |
def denoise(fl):
|
| 224 |
fr = cv2.imread(fl).astype(np.uint8)
|
| 225 |
-
fr = cv2.fastNlMeansDenoisingColored(fr, None,
|
| 226 |
cv2.imwrite(fl, fr)
|
| 227 |
return fl
|
| 228 |
|
|
@@ -252,7 +258,7 @@ def sharpest(fl, i):
|
|
| 252 |
imgToDenoiseIndex = indx,
|
| 253 |
temporalWindowSize = n,
|
| 254 |
hColor = 5,
|
| 255 |
-
templateWindowSize =
|
| 256 |
searchWindowSize = 21)
|
| 257 |
|
| 258 |
cv2.imwrite(fl, frame)
|
|
|
|
| 205 |
|
| 206 |
cv2.imwrite(fl, fr)
|
| 207 |
|
| 208 |
+
b = 15
|
| 209 |
+
d = 1
|
| 210 |
+
element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * b + 1, 2 * b + 1), (b, b))
|
| 211 |
+
mask_e = cv2.erode(mask, element) * 255
|
| 212 |
+
element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * d + 1, 2 * d + 1), (d, d))
|
| 213 |
+
mask_d = cv2.dilate(mask, element) * 127
|
| 214 |
+
mask_d[mask_e>0] = 255
|
| 215 |
+
cv2.imwrite(f"{str(count)}_trimask.png", mask_d.astype(np.uint8))
|
| 216 |
+
cutout(fl, f"{str(count)}_trimask.png", f"{str(count)}_cutout.png")
|
| 217 |
+
|
| 218 |
+
a_map = cv2.imread(f"{str(count)}_cutout.png", cv2.IMREAD_UNCHANGED).astype(np.uint8)
|
| 219 |
+
a_map[:,:,3] = ((255 - a_map[:,:,3]) / 255).astype(np.float16)
|
| 220 |
+
fr[a_map[:,:,3]>0] = (fr * a_map[:,:,3] * 15 + 240).astype(np.uint8)
|
| 221 |
+
|
| 222 |
+
cv2.imwrite(fl, fr)
|
| 223 |
return fl #f"{str(count)}_cutout.png"
|
| 224 |
else: # even: with the flash
|
| 225 |
fl_ = fl.split(".")[0] + "_.png"
|
|
|
|
| 228 |
|
| 229 |
def denoise(fl):
|
| 230 |
fr = cv2.imread(fl).astype(np.uint8)
|
| 231 |
+
fr = cv2.fastNlMeansDenoisingColored(fr, None, 5,5,7,21)
|
| 232 |
cv2.imwrite(fl, fr)
|
| 233 |
return fl
|
| 234 |
|
|
|
|
| 258 |
imgToDenoiseIndex = indx,
|
| 259 |
temporalWindowSize = n,
|
| 260 |
hColor = 5,
|
| 261 |
+
templateWindowSize = 7,
|
| 262 |
searchWindowSize = 21)
|
| 263 |
|
| 264 |
cv2.imwrite(fl, frame)
|