Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 缩放OpenCV人脸识别中检测到的矩形_Python_Opencv - Fatal编程技术网

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

Python 缩放OpenCV人脸识别中检测到的矩形,python,opencv,Python,Opencv,使用OpenCV(在Python中),我在检测到的人脸周围绘制了一个矩形。这只需通过以下方式实现: cv2.rectangle(img, (x, y), (x+width, y+height), (255,255,255), 4, lineType=-1) 我想把这个矩形缩放3倍,这样它仍然围绕着同一点。它应该看起来像黄色边框中的矩形: 该如何操作?计算第一个矩形的中心点,然后创建一个宽度和高度为3倍的矩形: center_x = (x + x + width) // 2 center_y

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

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

我想把这个矩形缩放3倍,这样它仍然围绕着同一点。它应该看起来像黄色边框中的矩形:


该如何操作?

计算第一个矩形的中心点,然后创建一个宽度和高度为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)