open CV人脸剪裁

识别了人脸并且用框标记出了人脸,要怎么把人脸部分剪裁出来并保存为指定像素的图片?

import cv2

# 读取文件
image = 'C:\\Users\86199\Desktop\OCP.jpg'
model = 'C:\\Users\86199\Downloads\opencv\sources\data\haarcascades_cuda\haarcascade_frontalface_default.xml'
image = cv2.imread(image)  # 读取图片
model = cv2.CascadeClassifier(model)  # 加载模型
# 人脸检测
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = model.detectMultiScale(gray)
graytorgb = cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
for (x, y, w, h) in faces:
    faceRectangle = cv2.rectangle(gray, (x, y), (x + w, y + h), (255,0,0), 2)
    face_img = faceRectangle[y:y+h, x:w+x]
    res = cv2.resize(face_img, (32, 32), interpolation=cv2.INTER_CUBIC)
    cv2.imshow("face_img", res)
for (x, y, w, h) in faces:
    # 左上顶角,右下顶角,颜色,框厚度
    cv2.rectangle(graytorgb, (x, y), (x + w, y + h), (0, 0, 255), thickness=1)  # 画出人脸矩形框
image = cv2.imread('img1.jpg')
# 显示和保存图片
cv2.imshow('result', graytorgb)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('result.jpg',graytorgb)
print('已保存')

最后将剪裁出的人脸另存为文件

直接使用获取框的在图像矩阵中的位置进行裁剪即可。如果有代码可以结合代码解答