Skip to content

Commit 9a30d98

Browse files
committed
Fix image size indexing when drawing keypoints
Corrects swapped im_size indexing when clamping ellipse coordinates in Display.draw. The previous code used im_size[1] for x1 and im_size[0] for y1, which reversed width/height fallbacks and could produce incorrect bounds; x1 now uses im_size[0] (width) and y1 uses im_size[1] (height). This prevents drawing outside the image or using wrong coordinates.
1 parent cfba326 commit 9a30d98

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

dlclive/display.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class Display:
3535

3636
def __init__(self, cmap="bmy", radius=3, pcutoff=0.5):
3737
if not _TKINTER_AVAILABLE:
38-
raise ImportError("tkinter is not available. Display functionality requires tkinter. ")
38+
raise ImportError(
39+
"tkinter is not available. Display functionality requires tkinter. "
40+
)
3941
self.cmap = cmap
4042
self.colors = None
4143
self.radius = radius
@@ -93,12 +95,30 @@ def display_frame(self, frame, pose=None):
9395
for j in range(pose.shape[1]):
9496
if pose[i, j, 2] > self.pcutoff:
9597
try:
96-
x0 = pose[i, j, 0] - self.radius if pose[i, j, 0] - self.radius > 0 else 0
97-
x1 = pose[i, j, 0] + self.radius if pose[i, j, 0] + self.radius < im_size[0] else im_size[1]
98-
y0 = pose[i, j, 1] - self.radius if pose[i, j, 1] - self.radius > 0 else 0
99-
y1 = pose[i, j, 1] + self.radius if pose[i, j, 1] + self.radius < im_size[1] else im_size[0]
98+
x0 = (
99+
pose[i, j, 0] - self.radius
100+
if pose[i, j, 0] - self.radius > 0
101+
else 0
102+
)
103+
x1 = (
104+
pose[i, j, 0] + self.radius
105+
if pose[i, j, 0] + self.radius < im_size[0]
106+
else im_size[0]
107+
)
108+
y0 = (
109+
pose[i, j, 1] - self.radius
110+
if pose[i, j, 1] - self.radius > 0
111+
else 0
112+
)
113+
y1 = (
114+
pose[i, j, 1] + self.radius
115+
if pose[i, j, 1] + self.radius < im_size[1]
116+
else im_size[1]
117+
)
100118
coords = [x0, y0, x1, y1]
101-
draw.ellipse(coords, fill=self.colors[j], outline=self.colors[j])
119+
draw.ellipse(
120+
coords, fill=self.colors[j], outline=self.colors[j]
121+
)
102122
except Exception as e:
103123
print(e)
104124
img_tk = ImageTk.PhotoImage(image=img, master=self.window)

0 commit comments

Comments
 (0)