【问题标题】:Python openCV TypeError: labels data type = 18 is not supportedPython openCV TypeError:不支持标签数据类型= 18
【发布时间】:2018-03-01 06:41:58
【问题描述】:

我的部分代码:

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-09-05
    • 2017-06-03
    • 2015-01-18
    • 1970-01-01
    • 2018-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多