Unverified 提交 729dc169 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Fixed Classify offsets (#9155)

上级 d07ddc69
...@@ -136,7 +136,7 @@ def run( ...@@ -136,7 +136,7 @@ def run(
# Write results # Write results
if save_img or view_img: # Add bbox to image if save_img or view_img: # Add bbox to image
text = '\n'.join(f'{prob[j]:.2f} {names[j]}' for j in top5i) text = '\n'.join(f'{prob[j]:.2f} {names[j]}' for j in top5i)
annotator.text((64, 64), text, txt_color=(255, 255, 255)) annotator.text((32, 32), text, txt_color=(255, 255, 255))
# Stream results # Stream results
im0 = annotator.result() im0 = annotator.result()
......
...@@ -117,10 +117,12 @@ class Annotator: ...@@ -117,10 +117,12 @@ class Annotator:
# Add rectangle to image (PIL-only) # Add rectangle to image (PIL-only)
self.draw.rectangle(xy, fill, outline, width) self.draw.rectangle(xy, fill, outline, width)
def text(self, xy, text, txt_color=(255, 255, 255)): def text(self, xy, text, txt_color=(255, 255, 255), anchor='top'):
# Add text to image (PIL-only) # Add text to image (PIL-only)
w, h = self.font.getsize(text) # text width, height if anchor == 'bottom': # start y from font bottom
self.draw.text((xy[0], xy[1] - h + 1), text, fill=txt_color, font=self.font) w, h = self.font.getsize(text) # text width, height
xy[1] += 1 - h
self.draw.text(xy, text, fill=txt_color, font=self.font)
def result(self): def result(self):
# Return annotated image as array # Return annotated image as array
...@@ -222,7 +224,7 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max ...@@ -222,7 +224,7 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max
x, y = int(w * (i // ns)), int(h * (i % ns)) # block origin x, y = int(w * (i // ns)), int(h * (i % ns)) # block origin
annotator.rectangle([x, y, x + w, y + h], None, (255, 255, 255), width=2) # borders annotator.rectangle([x, y, x + w, y + h], None, (255, 255, 255), width=2) # borders
if paths: if paths:
annotator.text((x + 5, y + 5 + h), text=Path(paths[i]).name[:40], txt_color=(220, 220, 220)) # filenames annotator.text((x + 5, y + 5), text=Path(paths[i]).name[:40], txt_color=(220, 220, 220)) # filenames
if len(targets) > 0: if len(targets) > 0:
ti = targets[targets[:, 0] == i] # image targets ti = targets[targets[:, 0] == i] # image targets
boxes = xywh2xyxy(ti[:, 2:6]).T boxes = xywh2xyxy(ti[:, 2:6]).T
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论