从原图中同时裁剪多个人脸图像,保持位置不变,组合成新的灰度图
#!/usr/bin/env python # -*- coding:utf-8 -*- #@Time : 19-12-23 下午5:37 #@Author: Bryan #@File : my_test.py ''' 从原图中裁剪部分人脸图像,保持位置不变, ''' import cv2 import numpy as np ratio=2#扩大比例 #画矩形框 def draw_box(image, box, color, thickness=2): b = np.array(box).astype(int) cv2.rectangle(image, (b[0], b[1]), (b[2], b[3]), color, thickness, cv2.LINE_AA) def main(): img_raw = cv2.imread('000021.jpg') img_raw = cv2.resize(img_raw, (300, 300), interpolation=cv2.INTER_AREA) rows, cols, ch = img_raw.shape #人为构造的矩形框,这里是图中的人脸位置 boxes = [[85.77092912833217, 55.85900957788992, 117.31985106905064, 85.6277261857844],