需要導(dǎo)入相關(guān)的庫(kù)
def show_rect(img_path, regions, test_index):
ind_to_class = dict(zip(range(1, len(cfg.Classes) + 1), cfg.Classes))
img = cv2.imread(img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
for x, y, w, h, cls_ind, score in regions:
xmin, ymin, xmax, ymax = int(x), int(y), int(x + w), int(y + h)
if xmin <= 0: xmin = 1
if xmax >= cfg.Image_w: xmax = cfg.Image_w - 1
if ymin <= 0: ymin = 1
if ymax >= cfg.Image_h: ymax = cfg.Image_h - 1
message = ind_to_class[cls_ind]
rect = cv2.rectangle(
img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img, message + ': ' + str(round(score, 2)), (xmin + 5, ymin - 20), font, 1, (255, 255, 255), 2)
if not os.path.exists(cfg.Test_output):
os.makedirs(cfg.Test_output)
out_path = os.path.join(cfg.Test_output, test_index + 'test.jpg')
cv2.imwrite(out_path, img, [int(cv2.IMWRITE_PNG_COMPRESSION), 1])
plt.imshow(img)
plt.show()
本文整理轉(zhuǎn)載自其它博文,如有侵權(quán),請(qǐng)聯(lián)系364017364@qq.com刪除。