Discussions>TypeError cv::UMat for argument 'labels'>

TypeError cv::UMat for argument 'labels'

Good day everyone. Please could someone help me out? I keep getting this error message each time I run a code

TypeError: Expected Ptr<cv::UMat> for argument 'labels'

Below is my code

#This program trains the computer to recognize pictures

import cv2
import numpy as np
from PIL import Image
import os

#Path for face image database

path = 'Dataset'
face_recognizer = cv2.face.LBPHFaceRecognizer_create()
face_detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

#Function to get the images and label data

def getImagesAndLabel(path):
imagePaths = [os.path.join(path, f) for f in os.listdir(path)]
faceSamples = []
names = []
for imagePath in imagePaths:
PIL_image = Image.open(imagePath).convert('L')
img_numpy = np.array(PIL_image, 'uint8')
id = os.path.split(imagePath)[-1].split(".")[1]
faces = face_detector.detectMultiScale(img_numpy)

for (x,y,w,h) in faces:
faceSamples.append(img_numpy[y:y+h, x:x+w])
return faceSamples, names

faceSamples, names = getImagesAndLabel(path)
face_recognizer.train(faceSamples, np.array(names))
1 votesMG1.00
1 Answers

I think your issue is related to the type of labels. It needs to be int and you have to cast them before passing to a function.

This is a duplicate question and you can take a look at this discussion

Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?