删除图像中除特定部分外的所有内容



我正在使用Python人脸识别库来检测图像中的人脸,它返回图像中人脸的坐标。我想删除除人脸识别函数返回的坐标以外的所有坐标

import face_recognition
image1 = face_recognition.load_image_file("image extract/image.jpg")
face_locations = face_recognition.face_locations(image1)
print(face_locations)

感谢@Mark Setchell和@Bohdan的帮助

count2=0
for file in image_folder:
loc=f"image extract/frame{count2}.jpg"
image1 = face_recognition.load_image_file("image extract/"+file)
face_locations = face_recognition.face_locations(image1)
width, height =0,0
for face_location in face_locations:
top, right, bottom, left = face_location
face_image = image1[top+20:bottom+20, left+20:right+20]
pil_image = Image2.fromarray(face_image)
if (pil_image.size[0]*pil_image.size[1]>width*height):
width, height = pil_image.size
pil_image.save(loc)

最新更新