我想裁剪使用cv2.rectangle装箱的面孔。
我尝试过:
faces = face_cascade.detectMultiScale(gray_image, 1.25, 6)
但是此代码仅为此image检测到一张脸,但是当我使用其他代码时:
boxes = face_recognition.face_locations(rgb,model="hog")
它返回了我3个带有上,右,下,左值的脸,但我不知道如何使用这些值(上,右,下,左)裁剪图像。任何帮助将不胜感激。
我正在使用:
Python- 2.7
OpenCv- 3.1.0
答案 0 :(得分:0)
在问题中,框具有检测到的脸部的上,右,下,左值,因此要使用给定的上,右,下,左值来裁剪该区域,我使用了PIL.Image.crop():
然后代码将如下所示:
from PIL import Image
img = Image.open("path/to/file")
crop_pic = img.crop( ( left, top, right, bottom ) )
crop_pic.show()