赞
踩
《OpenCV系列教程》
项目位置:OpenCV-Sample
代码位置:23-LearnEigenFace.py
同时所需要的资源也都在项目里面
import cv2 import os import numpy as np imgs = [] cl = [] imgPath = './Actor/zxc/' model = cv2.face.EigenFaceRecognizer_create() dirs = os.listdir(imgPath) for f in dirs: file = imgPath + f img = cv2.imread(file, 0) imgs.append(img) cl.append(101) array = np.array(cl) model.train(imgs, array) model.save('./XML/actor_zxc.xml') cv2.destroyAllWindows()
需要注意的一点是必须转成灰度图。
训练资源也都在项目里面。
训练的是周润发的图片。
生成好的数据都类似这样的:
<?xml version="
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。