Python OpenCV错误MagicMirror AttributeError:&x27;cv2.人脸识别器&x27;对象没有属性';写';
配置:Python OpenCV错误MagicMirror AttributeError:&x27;cv2.人脸识别器&x27;对象没有属性';写';,python,python-2.7,opencv,magic-mirror,Python,Python 2.7,Opencv,Magic Mirror,配置: #!/usr/bin/env python # coding: utf8 """MMMM-Facial-Recognition-OCV3 - MagicMirror Module The MIT License (MIT) Copyright (c) 2018 Mathieu Goulène (MIT License) Based on work by Paul-Vincent Roll (Copyright 2016) (MIT License) """ # to install
#!/usr/bin/env python
# coding: utf8
"""MMMM-Facial-Recognition-OCV3 - MagicMirror Module The MIT License (MIT)
Copyright (c) 2018 Mathieu Goulène (MIT License) Based on work by Paul-Vincent Roll (Copyright 2016) (MIT License) """
# to install builtins run `pip install future` from builtins import input
import cv2 import numpy as np import os
from lib.tools.config import ToolsConfig from lib.common.face import FaceDetection
class ToolsTrain:
def __init__(self):
self.face = ToolsConfig.getFaceDetection()
def prepareImage(self, filename):
"""Read an image as grayscale and resize it to the appropriate size for
training the face recognition model.
"""
return self.face.resize(cv2.imread(filename, cv2.IMREAD_GRAYSCALE),ToolsConfig.FACE_WIDTH, ToolsConfig.FACE_HEIGHT)
def train(self):
print("Reading training images...")
print('-' * 20)
faces = []
labels = []
imageDirsWithLabel = [[0, "negative"]]
imageDirs = os.listdir(ToolsConfig.TRAINING_DIR)
imageDirs = [x for x in imageDirs if not x.startswith('.') and not x.startswith('negative')]
pos_count = 0
for i in range(len(imageDirs)):
print("Assign label " + str(i + 1) + " to " + imageDirs[i])
imageDirsWithLabel.append([i + 1, imageDirs[i]])
print('-' * 20)
print('')
# Für jedes Label/Namen Paar:
# for every label/name pair:
for j in range(0, len(imageDirsWithLabel)):
# Label zu den Labels hinzufügen / Bilder zu den Gesichtern
for filename in ToolsConfig.walkFiles(ToolsConfig.TRAINING_DIR + str(imageDirsWithLabel[j][1]), '*.pgm'):
faces.append(self.prepareImage(filename))
labels.append(imageDirsWithLabel[j][0])
if imageDirsWithLabel[j][0] != 0:
pos_count += 1
# Print statistic on how many pictures per person we have collected
print('Read ' + str(pos_count) + ' positive images and ' + str(labels.count(0)) + ' negative images.')
print('')
for j in range(1, max(labels) + 1):
print(str(labels.count(j)) + " images from subject " + imageDirs[j - 1])
# Train model
print('-' * 20)
print('')
CMD:
sudo python tools.train.py
错误/输出
记住设置名称列表环境变量FACE\u user Reading
训练图像。。。
--------------------将标签1指定给Jorick
--------------------
阅读7张正面图像和0张负面图像。
受试者Jorick的7幅图像
--------------------
具有阈值80回溯的培训模型(最近一次呼叫最后一次):
文件“tools.train.py”,第14行,在
ToolsTrain().train()文件“/home/pi/MagicMirror/modules/MMM-face-Recognition-OCV3/lib/tools/train.py”,
74号线,火车上
model.write(ToolsConfig.TRAINING\u文件)AttributeError:'cv2.face\u LBPHFaceRecognizer'对象没有属性'write'
Git包:
Python版本:
Python 2.7.16您似乎正在使用旧版本的OpenCV,为了运行MMM-face-Recognition-OCV3,您将需要OpenCV 3.3,任何旧版本都将失败,因为cv::face::FaceRecognitizer的接口在3.2和3.3之间更改。阅读MMM-face-Recognition-OCV3存储库自述文件-它解释了如何安装该软件包dependencies@Black0ut我找不到它。