Martin Delisle
Martin Delisle

Reputation: 21

Extract the selected zone on a picture with opencv python

I'm using OPENCV to detect a face in a picture and I want ot extract it, so i have the photo with a man and the expected result is a jpg image with only the seleted face

enter image description here

I have detect the face but if someone can help me to extract this face and save it!

Thank you all

Upvotes: 0

Views: 1380

Answers (1)

Jeru Luke
Jeru Luke

Reputation: 21203

You just have to add a single line to your program.

Consider a variable detected_face, and do the following:

detected_face = img[y:y+h, x:x+w]
cv2.imwrite('face.jpg', detected_face)

You will have a .jpgfile of ONLY the face stored in your directory

Upvotes: 1

Related Questions