当前位置:   article > 正文

OpenCV训练人脸模型并生成XML文件_opencv中特征脸算法生成的xml

opencv中特征脸算法生成的xml

《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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

需要注意的一点是必须转成灰度图。
训练资源也都在项目里面。
训练的是周润发的图片。
在这里插入图片描述

生成好的数据都类似这样的:

<?xml version="
    声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/278464
    推荐阅读
    相关标签
      

    闽ICP备14008679号