python+opencv实现矩形框填充

需求:给跟踪的目标画框,并且在目标框上方用lab的形式展示出来

import numpy as np
import cv2

def plot_boxx(image_dir):

  im = cv2.imread(image_dir)
  h = im.shape[0] 
  w = im.shape[1]


  '''目标框 '''
  cv2.rectangle(im, (0, 0), (w, h), color=10, thickness=1)

  #c1, c2 = (x, y), (x + w, y + h)
  c1, c2 = (0, 0), (0+w, 0+h)

  '''目标Id文字的背景框'''
  #cv2.getTextSize(text, font-face, text_scale, thickness)
  t_size = cv2.getTextSize(id_text, 0, 1, 2)[0]
  c3 = (c1[0] + t_size[0], c1[1] - t_size[1] - 3)
  cv2.rectangle(im, c1, (np.float32(c3[0]), np.float32(c3[1])), color=color, thickness=-1)  # filled

  '''目标id'''
  cv2.putText(im, id_text, (intbox[0], intbox[1]-10), cv2.FONT_HERSHEY_PLAIN, text_scale, (0, 0, 255),  thickness=text_thickness)

return im

image.png

你可能感兴趣的:(python+opencv实现矩形框填充)