【问题标题】:Scale the rectangle detected in OpenCV Face Recognition缩放 OpenCV 人脸识别中检测到的矩形
【发布时间】:2023-03-16 11:27:01
【问题描述】:

使用 OpenCV(在 Python 中),我在检测到的人脸周围绘制了一个矩形。只需通过以下方式完成:

cv2.rectangle(img, (x, y), (x+width, y+height), (255,255,255), 4, lineType=-1)

我想将该矩形缩放 3 倍左右,使其仍以同一点为中心。它应该看起来像黄色边框的矩形:

这应该怎么做?

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    计算第一个矩形的中心点,然后创建一个宽度和高度为 3 倍的矩形:

    center_x = (x + x + width) // 2
    center_y = (y + y + height) // 2
    cv2.rectangle(img, (center_x-3*width, center_y-3*height), (center_x+3*width, center_y+3*height), (255,255,255), 4, lineType=-1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 2022-06-24
      • 1970-01-01
      • 2017-08-29
      • 2015-07-05
      • 2023-03-19
      相关资源
      最近更新 更多