Python openCV 类型错误 : labels data type = 18 is not supported

标签 python opencv numpy

我的部分代码:

# -*- 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”是一个常规字符串。知道为什么我会收到此错误吗?

最佳答案

好的,我找到了导致问题的部分。 label必须是整数,不接受字符串。

关于Python openCV 类型错误 : labels data type = 18 is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34790753/

相关文章:

python - 管理 python 字符串中的关键字参数 : how to format only some arguments and keep the others unformatted

python - numpy 中的 "as of"

c++ - 如何让cmake使用ubuntu系统以外的另一个opencv目录?

opencv - OpenCV 中的正常贝叶斯实现

python - 为 pandas 中的数据帧中的每一行循环 IF 语句

python - 在 python 启动时自动加载模块

python - 保存不在正则表达式 python 中的行

python - 如何找到直线和轮廓之间的交点

python - 在Python中设置颂歌

python - 将项目拆分为行 Pandas