1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
import matplotlib.pyplot as plt import cv2 import numpy as np
def (img, boxes, label=None, classes=None): ''' Args: img: narrary image boxes: Nx4 [[xmin, ymin, xmax, ymax],[.. ..]] label: [c1, c2 ,c3,....] 1xN classes: ['bird', 'cat', 'dog', ....] ''' plt.imshow(img) wh = boxes[:,2:4] - boxes[:,0:2] for i in range(len(boxes)): currentAxis=plt.gca() rect=patches.Rectangle((boxes[i,0], boxes[i,1]),wh[i, 0],wh[i, 1],linewidth=1,edgecolor='r',facecolor='none') currentAxis.add_patch(rect) plt.text(boxes[i,0], boxes[i,1], classes[label[i]-1], color='white',fontsize=16) plt.show() img = cv2.imread('12.jpg') boxes = np.array([[304,70,514,386],[547,55,762,360]], dtype=float) label = [1, 2] classes = ['sasiki', 'naruto'] img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) draw_bbox(img, boxes, label, classes)
|
近期评论