如何在 python 中增加 openCV 检测到的矩形的大小?

How to increase the size of a detected rectangle for openCV in python?

我在 Python3.6 中使用 openCV 来检测图像中的人脸。 它工作得很好并且可以检测到面部,但我希望矩形包含更多面部(下巴、头发等),因为这些部分对于识别人很重要。我正在使用 this code.

我怎样才能让程序select更多的脸?

这是我得到的示例(当然是为了保护隐私)

创建矩形时,只需设置一个offset/padding

padding = 10
cv2.rectangle(img,(x-padding,y-padding),(x+w+padding,y+h+padding),(255,0,0),2)