gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:56:19 28 4
gpt4 key购买 nike

我的部分代码:

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com