OpenCV EigenFaceRecognizer 错误图像不是来自相同大小,但已调整大小

发布于 2025-01-11 19:44:23 字数 1562 浏览 0 评论 0原文

我实际上正在尝试测试不同的人脸识别算法。使用 OpenCV EigenFaceRecognizer 时出现错误:

cv2.error: OpenCV(4.5.5) /io/opencv_contrib/modules/face/src/eigen_faces.cpp:121: error: (-5:Bad argument) Wrong input图像尺寸。原因:训练和测试图像必须大小相同!预期图像包含 7000 个元素,但得到了 11000 个元素。在函数“预测”

,但是,在我的代码中,我已经将图像大小调整为 70*100。

这是我的代码:

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))

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))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文