Skip to content

Commit e8cdb15

Browse files
committed
minor update
1 parent c86ba83 commit e8cdb15

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

util/tools.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import numpy as np
22
import torch
33
import matplotlib.pyplot as plt
4-
from PIL import Image, ImageDraw
5-
import sys
4+
from PIL import Image, ImageDraw, ImageFont
65
import math
76
import random
87
import tqdm
@@ -333,7 +332,8 @@ def drawBox(_img, boxes = None, cls = None, mode = 0, color = (0,255,0)):
333332
_img_data = np.array(_img, dtype=np.uint8)
334333
img_data = Image.fromarray(_img_data, 'L')
335334
draw = ImageDraw.Draw(img_data)
336-
335+
fontsize = 15
336+
font = ImageFont.truetype("./arial.ttf", fontsize)
337337
if boxes is not None:
338338
for i, box in enumerate(boxes):
339339
# if (box[4] + box[5]) / 2 < 0.5:
@@ -346,11 +346,11 @@ def drawBox(_img, boxes = None, cls = None, mode = 0, color = (0,255,0)):
346346
draw.rectangle((box[0] - box[2]/2, box[1] - box[3]/2, box[0] + box[2]/2, box[1] + box[3]/2), outline=(0,255,0), width=1)
347347
else:
348348
draw.rectangle((box[0],box[1],box[2],box[3]), outline=(0,255,0), width=1)
349-
#draw.text((box[0],box[1]), str(int(cls[i])), fill ="red")
349+
draw.text((box[0],box[1]), str(int(cls[i])), fill ="red", font=font)
350350
plt.imshow(img_data)
351351
plt.show()
352352

353-
def drawBoxlist(_img, boxes : list = [], mode : int = 0):
353+
def drawBoxlist(_img, boxes : list = [], mode : int = 0, name : str = ""):
354354
_img = _img * 255
355355
#img dim is [C,H,W]
356356
if _img.shape[0] == 3:
@@ -360,13 +360,17 @@ def drawBoxlist(_img, boxes : list = [], mode : int = 0):
360360
_img_data = np.array(_img, dtype=np.uint8)
361361
img_data = Image.fromarray(_img_data, 'L')
362362
draw = ImageDraw.Draw(img_data)
363+
fontsize = 15
364+
font = ImageFont.truetype("./arial.ttf", fontsize)
363365
for box in boxes:
364366
if mode == 0:
365367
draw.rectangle((box[0] - box[2]/2, box[1] - box[3]/2, box[0] + box[2]/2, box[1] + box[3]/2), outline=(0,255,0), width=1)
368+
draw.text((box[0],box[1]), str(int(box[5]))+","+str(int(box[4]*100)) , fill ="red", font=font)
366369
else:
367370
draw.rectangle((box[0],box[1],box[2],box[3]), outline=(0,255,0), width=1)
368-
plt.imshow(img_data)
369-
plt.show()
371+
draw.text((box[0],box[1]), str(int(box[5]))+","+str(int(box[4]*100)), fill ="red", font=font)
372+
#img_data.show("draw")
373+
img_data.save(name+".png")
370374

371375
def check_outrange(box, img_size):
372376
box = box.detach().cpu().numpy()
@@ -602,7 +606,6 @@ def non_max_suppression(prediction, conf_thres=0.25, iou_thres=0.45, classes=Non
602606

603607
return output
604608

605-
606609
def get_lr(optimizer):
607610
for param_group in optimizer.param_groups:
608611
return param_group['lr']

0 commit comments

Comments
 (0)