python识别人脸多种属性_Python用局部二值模式直方图创建一个人脸识别器

3、定义一个方法,用于输入文件夹中提取图像和标签:

def get_images_and_labels(input_path):                                                                            label_words = []                                                                                                           # 对输入文件夹做递归迭代并追加文件                                                                           for root, dirs, files in os.walk(input_path):                                                                         for filename in (x for x in files if x.endswith('.jpg')):                                                         filepath = os.path.join(root, filename)                                                                       label_words.append(filepath.split('\\')[-2])                                                     # 初始化变量                                                                                                                 images = []                                                                                                                 le = LabelEncoder()                                                                                                     le.encode_labels(label_words)                                                                                     labels = []                                                                                                                                                                                                                                                         # 解析输入目录                                                                                                             for root, dirs, files in os.walk(input_path):                                                                         for filename in (x for x in files if x.endswith('.jpg')):                                                         filepath = os.path.join(root, filename)                                                                                                                                                                                               # 将当前图像读取成灰度格式                                                                                         image = cv2.imread(filepath, 0)                                                                                 # 从文件夹路径中提取标签                                                                                           name = filepath.split('\\')[-2]                                                                                       # 做人脸检测                                                                                                                 faces = faceCascade.detectMultiScale(image, 1.1, 2, minSize=(100, 100))                 # 循环处理每一张脸

# 提取ROI属性值,并将这些值和标签编码器返回:                                                       for (x, y, w, h) in faces:                                                                                                       images.append(image[y:y + h, x:x + w])                                                                     labels.append(le.word_to_num(name))                                                           return images, labels, le

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值