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))))
目录
相关文章
|
2月前
|
机器学习/深度学习 计算机视觉 Python
cv2.dnn.
【9月更文挑战第13天】
50 12
|
3月前
|
机器学习/深度学习 编解码 自然语言处理
【文献学习】An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
本文介绍了如何使用纯Transformer模型进行图像识别,并讨论了模型的结构、训练策略及其在多个图像识别基准上的性能。
83 3
|
5月前
|
机器学习/深度学习 算法 图形学
shape_predictor_68_face_landmarks
【6月更文挑战第22天】
219 7
|
5月前
get_frontal_face_detector
【6月更文挑战第20天】
95 5
|
5月前
|
人工智能 自然语言处理 PyTorch
CLIP(Contrastive Language-Image Pre-training)
CLIP(Contrastive Language-Image Pre-training)
296 0
|
6月前
|
计算机视觉
cv2.putText
cv2.putText
441 1
|
6月前
|
计算机视觉 Python
cv2.polylines
cv2.polylines
287 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模块作为主干单元,它可以用很少的参数和低计算量提取有意义的特征,有效地学习表征。大大减少了特征提取的消耗
157 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》的翻译与解读