Python openCV TypeError:不支持labels data type=18

2024-05-18 15:47:44 发布

您现在位置:Python中文网/ 问答频道 /正文

部分代码:

# -*- 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

“label”是一个常规字符串。知道我为什么会犯这个错误吗?


Tags: inpyimageimportselflinetrainlabel

热门问题