我的部分代码:
# -*- coding: utf-8 -*-
import cv2, os, time
from PIL import Image
import numpy as np
class Trainer:
def __init__(self, label, initial_image):
self.label = label
self.image_list = [initial_image]
self.recognizer = cv2.createLBPHFaceRecognizer()
print(label)
print(type(label))
self.recognizer.train([initial_image], np.array([label]))
我称之为的地方:
...
...
...
gray_image_list = self.create_image_list(image_path_list)
t.tick("Images Created and Converted To Gray Scale :")
face_list = self.detect_and_crop_faces(gray_image_list)
t.tick(print_text="Faces Detected :")
i = 0
for face in face_list:
self.train_image(face)
t.tick(print_text="For " + str(i) + " image Total Calculate Time :")
i += 1
回溯:
Detecting Faces -> Faces Detected : 1.80294 sn.
Traceback (most recent call last):
subject01.gif_0
<type 'str'>
File "face_recognizer/self_learner.py", line 143, in <module>
st.run()
File "face_recognizer/self_learner.py", line 136, in run
self.train_image(face)
File "face_recognizer/self_learner.py", line 117, in train_image
self.trainer_dict[face.label] = Trainer(face.label, face.image)
File "face_recognizer/self_learner.py", line 58, in __init__
self.recognizer.train([initial_image], np.array([label]))
TypeError: labels data type = 18 is not supported
&#34;标签&#34;是一个常规字符串。知道为什么我会收到此错误吗?
答案 0 :(得分:8)
好的,我发现导致问题的部分。 标签必须是整数,它不接受字符串。