cv2.rectangle(img, pt1, pt2, color, thickness, lineType, shift)

  • img: 使用 imread 打开的图像
  • pt1: 左上角坐标, (xmin, ymin)
  • pt2: 右上角坐标, (xmax, ymax)
  • color: 颜色, (0, 255, 0)
  • thickness: 边框的粗细, 默认值 1
  • lineType: 边框的线形, 默认 8 连通线
  • shift: 矩形坐标的小数点位数, 默认为 0

大部分参数和 circle 一样

import cv2
 
img = cv2.imread("image.jpg")
cv2.rectangle(img, (4.2, 4.2), (42, 42), (0, 255, 0), 1)
 
cv2.imshow("image", img)
cv2.waitKey(0)