def vis_detections(im, class_name, dets, thresh=0.5):
global video_writer
"""Draw detected bounding boxes."""
inds = np.where(dets[:, -1] >= thresh)[0]
if len(inds) == 0:
return
show_im = im.copy()
for i in inds:
bbox = dets[i, :4]
score = dets[i, -1]
# Rectangle color is brighter if its probability is higher
if score>0.2:
cv2.rectangle(show_im,(int(bbox[0]), int(bbox[1])),
(int(bbox[2]), int(bbox[3])), (0,0,255*score), 3)
# Draw classic certainty percentage
# cv2.putText(show_im, '{:.0f}%'.format(score*100),
# (int(bbox[0]), int(bbox[1])-10), cv2.FONT_HERSHEY_DUPLEX,
# 0.6, (0,0,255))
cv2.imshow("result", show_im)
key = cv2.waitKey(3)
if args.record>0:
if video_writer is None:
video_writer = cv2.VideoWriter("output.avi", fourcc, 30, (im.shape[1], im.shape[0]))
print 'VideoWriter is ready'
video_writer.write(show_im)
if key==27: # Esc key to stop
sys.exit(0)
评论列表
文章目录