cv2. 02_face_training

简介:

import cv2
import os
from PIL import Image
import numpy as np

# Path for face image database
path = './face_dataset/0'
recognizer = cv2.face.LBPHFaceRecognizer_create()
cascPath = './data/'
detector = cv2.CascadeClassifier(cascPath + 'haarcascade_frontalface_alt.xml')
#function to get the images and label data

def getImagesAndLabels(path):
imagePaths = [os.path.join(path,f) for f in os.listdir(path)[1:]]
faceSamples = []
ids = []
for imagePath in imagePaths:
PIL_img = Image.open(imagePath).convert('L') #convert it to grayscale
img_numpy = np.array(PIL_img,dtype='uint8')
id = int(os.path.split(imagePath)[-1].split('.')[1])
faces = detector.detectMultiScale(img_numpy)
for (x,y,w,h) in faces:
faceSamples.append(img_numpy[y:y+h, x:x+w])
ids.append(id)
return faceSamples,ids

print('\n [INFO] Training faces. It will take a few seconds. Wait ...')
faces,ids = getImagesAndLabels(path)
recognizer.train(faces,np.array(ids))
# Save the model into trainer/trainer.yml
recognizer.write('./trainer/trainer.yml') # recognizer.save( ) worked on Mac, but not on Pi
# Print the numer of faces trained and end program
print('\n [INFO] {0} faces trained. Exiting Program'.format(len(np.unique(ids))))
目录
相关文章
|
1月前
|
机器学习/深度学习 计算机视觉 Python
cv2.dnn.
【9月更文挑战第13天】
34 12
|
2月前
|
机器学习/深度学习 编解码 自然语言处理
【文献学习】An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
本文介绍了如何使用纯Transformer模型进行图像识别,并讨论了模型的结构、训练策略及其在多个图像识别基准上的性能。
64 3
|
4月前
|
机器学习/深度学习 算法 图形学
shape_predictor_68_face_landmarks
【6月更文挑战第22天】
180 7
|
4月前
get_frontal_face_detector
【6月更文挑战第20天】
79 5
|
4月前
|
人工智能 自然语言处理 PyTorch
CLIP(Contrastive Language-Image Pre-training)
CLIP(Contrastive Language-Image Pre-training)
226 0
|
5月前
|
算法 BI 计算机视觉
[Initial Image Segmentation Generator]论文实现:Efficient Graph-Based Image Segmentation
[Initial Image Segmentation Generator]论文实现:Efficient Graph-Based Image Segmentation
54 1
|
编解码 资源调度 自然语言处理
【计算机视觉】Open-Vocabulary Semantic Segmentation with Mask-adapted CLIP(OVSeg)
基于掩码的开放词汇语义分割。 从效果上来看,OVSeg 可以与 Segment Anything 结合,完成细粒度的开放语言分割。
|
机器学习/深度学习 存储 机器人
LF-YOLO: A Lighter and Faster YOLO for Weld Defect Detection of X-ray Image
高效的特征提取EFE模块作为主干单元,它可以用很少的参数和低计算量提取有意义的特征,有效地学习表征。大大减少了特征提取的消耗
147 0
|
机器学习/深度学习 传感器 编解码
Spatial-Spectral Transformer for Hyperspectral Image Classification_外文翻译
 由于成像光谱学的进步,高光谱传感器倾向于以越来越高的空间和光谱分辨率捕获给定场景的反射强度[1]。获得的高光谱图像(HSI)同时包含空间特征和不同物体的连续诊断光谱[2]。因此,获得的丰富信息使HSI在许多领域有用,包括有效测量农业绩效[3]、植物病害检测[4]、矿物鉴定[5]、疾病诊断和图像引导手术[6]、生态系统测量[7],和地球监测[8]。为了充分利用获得的HSI,已经探索了许多数据处理技术,例如解混合、检测和分类[8]。
222 0
|
计算机视觉
Paper之CV:《One Millisecond Face Alignment with an Ensemble of Regression Trees》的翻译与解读
Paper之CV:《One Millisecond Face Alignment with an Ensemble of Regression Trees》的翻译与解读
Paper之CV:《One Millisecond Face Alignment with an Ensemble of Regression Trees》的翻译与解读