Search code examples
pythonpython-3.xopencvimage-processingface-recognition

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


I'm using openCV in Python3.6 to detect faces in an image. It works well enough and detects the face, but I'd like the rectangle to include more of the face (chin, hair, etc.) since those parts are important in recognizing the person. I'm using this code.

How can I get the program to select more of the face?

Here's an example of what I'm getting (censored for privacy of course)

One of the images


Solution

  • When it creates the rectangle, just set a offset/padding

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