'OpenCV EigenFaceRecognizer error image not from the same size, but already resized

I'm actually trying to test different face recognition algorithm. While using OpenCV EigenFaceRecognizer i obtain an error:

cv2.error: OpenCV(4.5.5) /io/opencv_contrib/modules/face/src/eigen_faces.cpp:121: error: (-5:Bad argument) Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with 7000 elements, but got 11000. in function 'predict'

But, in my code i already resized my image to be 70*100.

Here is my code:

for filename in filename_list:

    if filename.startswith('i'):

        im_num=int(filename[6:10])

        if count[int(csv_reader[im_num-1][0])-1] > 19 :

            image = cv2.imread('caltech/'+filename)

            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            start_row=int(img_data['SubDir_Data'][3][im_num-1])
            end_row=int(img_data['SubDir_Data'][7][im_num-1])
            start_col=int(img_data['SubDir_Data'][2][im_num-1])
            end_col=int(img_data['SubDir_Data'][6][im_num-1])

            scrop_img = gray[start_row:end_row, start_col:end_col]

            resized_image = cv2.resize(scrop_img, (70, 100),)

            if random.random() > 0.25:
                train_images.append(resized_image)
                train_labels.append(int(csv_reader[im_num-1][0]))
            else:
                test_images.append(resized_image)
                test_labels.append(int(csv_reader[im_num-1][0]))


#Train the eigen face recognition model
EIFR_model = cv2.face.EigenFaceRecognizer_create()
EIFR_model.train(np.array(train_images), np.array(train_labels))

#Test the models
EIFR_predicted_label = []

EIFR_predicted_label = EIFR_model.predict(np.array(test_images))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source