Spaces:
Build error
Build error
sabrinabenas
commited on
Commit
β’
e4c380d
1
Parent(s):
3bf787d
test
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import gradio as gr
|
|
8 |
import torch
|
9 |
import torchvision
|
10 |
from dlclive import DLCLive, Processor
|
11 |
-
|
12 |
from PIL import Image, ImageColor, ImageFont, ImageDraw
|
13 |
# check git lfs pull!!
|
14 |
import numpy as np
|
@@ -62,7 +62,7 @@ def draw_keypoints_on_image(image,
|
|
62 |
use_normalized_coordinates: if True (default), treat keypoint values as
|
63 |
relative to the image. Otherwise treat them as absolute.
|
64 |
|
65 |
-
|
66 |
"""
|
67 |
# get a drawing context
|
68 |
draw = ImageDraw.Draw(image)
|
@@ -76,14 +76,16 @@ def draw_keypoints_on_image(image,
|
|
76 |
if use_normalized_coordinates:
|
77 |
keypoints_x = tuple([im_width * x for x in keypoints_x])
|
78 |
keypoints_y = tuple([im_height * y for y in keypoints_y])
|
79 |
-
|
|
|
|
|
80 |
# draw ellipses around keypoints
|
81 |
for i, (keypoint_x, keypoint_y) in enumerate(zip(keypoints_x, keypoints_y)):
|
82 |
-
|
|
|
83 |
draw.ellipse([(keypoint_x - marker_size, keypoint_y - marker_size),
|
84 |
(keypoint_x + marker_size, keypoint_y + marker_size)],
|
85 |
-
|
86 |
-
fill=keypt_color)
|
87 |
|
88 |
# add string labels around keypoints
|
89 |
if flag_show_str_labels:
|
|
|
8 |
import torch
|
9 |
import torchvision
|
10 |
from dlclive import DLCLive, Processor
|
11 |
+
import matplotlib
|
12 |
from PIL import Image, ImageColor, ImageFont, ImageDraw
|
13 |
# check git lfs pull!!
|
14 |
import numpy as np
|
|
|
62 |
use_normalized_coordinates: if True (default), treat keypoint values as
|
63 |
relative to the image. Otherwise treat them as absolute.
|
64 |
|
65 |
+
|
66 |
"""
|
67 |
# get a drawing context
|
68 |
draw = ImageDraw.Draw(image)
|
|
|
76 |
if use_normalized_coordinates:
|
77 |
keypoints_x = tuple([im_width * x for x in keypoints_x])
|
78 |
keypoints_y = tuple([im_height * y for y in keypoints_y])
|
79 |
+
|
80 |
+
cmap = matplotlib.cm.get_cmap('viridis')
|
81 |
+
cmap2 = matplotlib.cm.get_cmap('Greys')
|
82 |
# draw ellipses around keypoints
|
83 |
for i, (keypoint_x, keypoint_y) in enumerate(zip(keypoints_x, keypoints_y)):
|
84 |
+
round_fill = [round(num*255) for num in list(cmap(i*len(keypoints_x)))[:3]]
|
85 |
+
round_outline = [round(num*255) for num in list(cmap2(alpha[i]))[:3]]
|
86 |
draw.ellipse([(keypoint_x - marker_size, keypoint_y - marker_size),
|
87 |
(keypoint_x + marker_size, keypoint_y + marker_size)],
|
88 |
+
fill=tuple(round_fill), outline= tuple(round_outline))
|
|
|
89 |
|
90 |
# add string labels around keypoints
|
91 |
if flag_show_str_labels:
|