Fixed Classify offsets (#9155)
This commit is contained in:
1 parent
d07ddc6996
commit
729dc169ba
2 files changed
+7
-5
No files matched your search
+1
-1
@@ -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()
|
||||||
|
|||||||
+6
-4
@@ -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
|
|||||||
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
|
||||||
|
|||||||
Reference in new issue
Block a user