1

I'm using FaceDetect (Python) which finds a face in an image and creates a box around it (as below).

Unlike the image below, the images I want to use all have a single face. Is there a simple way to save the produced image and crop it to what is inside the box?

enter image description here

  • Have you read e.g. https://realpython.com/blog/python/face-recognition-with-python/? This explains how the example works. You could also try reading the code itself. – jonrsharpe Aug 11 '15 at 16:28

1 Answers1

0

Line 26 on face_detect.py - Looks like it has the dimensions you need...

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)

You need to replace the rectangle() function with logic to crop instead. You should be able to pass in the dimensions into a numpy array function to do the crop. Here's an example of cropping in OpenCV using hard coded dimensions...

How to crop an image in OpenCV using Python

Community
  • 1
  • 1
abaldwin99
  • 903
  • 1
  • 8
  • 26