JS Lavertu
JS Lavertu

Reputation: 220

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

Upvotes: 1

Views: 6047

Answers (1)

user1767754
user1767754

Reputation: 25094

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)

Upvotes: 5

Related Questions