缩放在OpenCV人脸识别中检测到的矩形

时间:2019-05-03 18:42:41

标签: python opencv

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

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

enter image description here

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

enter image description here

这应该怎么做?

1 个答案:

答案 0 :(得分: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)
相关问题