TypeError: Expected cv::UMat for argument 'labels'

I'm tring to create a simple face detecton script by OpenCV 4

import cv2
import numpy as np

if __name__ == '__main__':
  recognizer = cv2.face.LBPHFaceRecognizer_create()
  faces, labels = load_data()
  recognizer.train(faces, np.ndarray(labels))

I new that labels should be numpy array, that's why I converted it, but I'm still getting this error

TypeError: Expected cv::UMat for argument 'labels'

I can't find any documentation for face recognition of OpenCV and don't know what wrong with this.

numpyopencvface-recognition
3 votesJW234.00
1 Answers
JO220.00
2

Make sure your labels is a list of integers.

The problem is, OpenCV C++ lib uses std::vector<int> and you gonna have to pass there a list of integer numbers. Like a simple example

labels = np.random.randint(0, size=len(faces))
recognizer.train(faces, np.array(labels))
Reply
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?