gpt4 book ai didi

python - 训练人脸识别模型

转载 作者:太空宇宙 更新时间:2023-11-03 22:37:56 27 4
gpt4 key购买 nike

我正在用 Python 编写人脸识别器,但我在训练部分遇到了麻烦。

这是我的代码:

import cv2
import numpy as np
from os import listdir
from os.path import isfile, join
data_path = 'E:/Documents/7thSemester/Project/OpenCV-master/faces'
onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path,f))]
Training_Data, Labels = [], []

for i, files in enumerate(onlyfiles):
image_path = data_path + onlyfiles[i]
images = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
Training_Data.append(np.asarray(images, dtype=np.uint8))
Labels.append(i)

Labels = np.asarray(Labels, dtype=np.int32)
model = cv2.face.LBPHFaceRecognizer_create()
model.train(np.asarray(Training_Data), np.asarray(Labels))
print("Model Training Complete!!!!!")

我收到以下错误:

Traceback (most recent call last):
File "facial_recognition_part2.py", line 19, in <module>
model = cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'face'

最佳答案

请将 opencv-contrib 安装为:

pip 安装 opencv-contrib

pip 安装 opencv_contrib_python

关于python - 训练人脸识别模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56628385/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com