Spaces:
Runtime error
Runtime error
watermark on rectangles
Browse files
utils.py
CHANGED
|
@@ -17,7 +17,7 @@ apply_canny = CannyDetector()
|
|
| 17 |
apply_openpose = OpenposeDetector()
|
| 18 |
|
| 19 |
|
| 20 |
-
def add_watermark(image,
|
| 21 |
wmsize=16, bbuf=5, opacity=0.9):
|
| 22 |
'''
|
| 23 |
Creates a watermark on the saved inference image.
|
|
@@ -25,8 +25,9 @@ def add_watermark(image, im_size, watermark_path="__assets__/picsart_watermark.j
|
|
| 25 |
Shi-Lab's work.
|
| 26 |
'''
|
| 27 |
watermark = Image.open(watermark_path).resize((wmsize, wmsize))
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
return image
|
| 31 |
|
| 32 |
|
|
@@ -72,7 +73,9 @@ def create_video(frames, fps, rescale=False, path=None):
|
|
| 72 |
if rescale:
|
| 73 |
x = (x + 1.0) / 2.0 # -1,1 -> 0,1
|
| 74 |
x = (x * 255).numpy().astype(np.uint8)
|
| 75 |
-
|
|
|
|
|
|
|
| 76 |
outputs.append(x)
|
| 77 |
# imageio.imsave(os.path.join(dir, os.path.splitext(name)[0] + f'_{i}.jpg'), x)
|
| 78 |
|
|
@@ -90,7 +93,8 @@ def create_gif(frames, fps, rescale=False):
|
|
| 90 |
if rescale:
|
| 91 |
x = (x + 1.0) / 2.0 # -1,1 -> 0,1
|
| 92 |
x = (x * 255).numpy().astype(np.uint8)
|
| 93 |
-
|
|
|
|
| 94 |
outputs.append(x)
|
| 95 |
# imageio.imsave(os.path.join(dir, os.path.splitext(name)[0] + f'_{i}.jpg'), x)
|
| 96 |
|
|
|
|
| 17 |
apply_openpose = OpenposeDetector()
|
| 18 |
|
| 19 |
|
| 20 |
+
def add_watermark(image, im_size_h, im_size_w, watermark_path="__assets__/picsart_watermark.jpg",
|
| 21 |
wmsize=16, bbuf=5, opacity=0.9):
|
| 22 |
'''
|
| 23 |
Creates a watermark on the saved inference image.
|
|
|
|
| 25 |
Shi-Lab's work.
|
| 26 |
'''
|
| 27 |
watermark = Image.open(watermark_path).resize((wmsize, wmsize))
|
| 28 |
+
loc_h = im_size_h - wmsize - bbuf
|
| 29 |
+
loc_w = im_size_w - wmsize - bbuf
|
| 30 |
+
image[loc_h:-bbuf, loc_w:-bbuf, :] = watermark
|
| 31 |
return image
|
| 32 |
|
| 33 |
|
|
|
|
| 73 |
if rescale:
|
| 74 |
x = (x + 1.0) / 2.0 # -1,1 -> 0,1
|
| 75 |
x = (x * 255).numpy().astype(np.uint8)
|
| 76 |
+
|
| 77 |
+
h_, w_, _ = x.shape
|
| 78 |
+
x = add_watermark(x, im_size_h=h_, im_size_w=w_)
|
| 79 |
outputs.append(x)
|
| 80 |
# imageio.imsave(os.path.join(dir, os.path.splitext(name)[0] + f'_{i}.jpg'), x)
|
| 81 |
|
|
|
|
| 93 |
if rescale:
|
| 94 |
x = (x + 1.0) / 2.0 # -1,1 -> 0,1
|
| 95 |
x = (x * 255).numpy().astype(np.uint8)
|
| 96 |
+
h_, w_, _ = x.shape
|
| 97 |
+
x = add_watermark(x, im_size_h=h_, im_size_w=w_)
|
| 98 |
outputs.append(x)
|
| 99 |
# imageio.imsave(os.path.join(dir, os.path.splitext(name)[0] + f'_{i}.jpg'), x)
|
| 100 |
|