AttributeError: module ‘cv2‘ has no attribute ‘face‘

简介: AttributeError: module ‘cv2‘ has no attribute ‘face‘

Traceback (most recent call last):

 File "D:\AI_37\pythonProject7\day23\课堂代码\day23\07-人脸识别.py", line 4, in <module>

   recognizer = cv2.face.LBPHFaceRecognizer_create()

                ^^^^^^^^

AttributeError: module 'cv2' has no attribute 'face'


可能是之前你的opnecv-python不是扩展版


试试


pip uninstall opencv-python


pip install opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn/simple


不行的话接着往后面看~~~~~~~~~~~~~~~~


在 OpenCV 4.10.0 中,人脸识别器的创建方式与之前版本(如4.1.0)并没有显著变化。你仍然可以使用以下方式创建 LBPH 人脸识别器:

import cv2


# 创建 LBPH 人脸识别器

recognizer = cv2.face.LBPHFaceRecognizer_create()


# 现在可以使用 'recognizer' 进行进一步的操作


这段代码使用了 cv2.face.LBPHFaceRecognizer_create() 方法来创建 LBPH 人脸识别器实例。这个方法在 OpenCV 的较新版本中仍然有效,包括 4.10.0 版本。

注意事项:


1.OpenCV 版本兼容性:确保你安装的是 OpenCV 4.10.0 或更新版本。LBPH 人脸识别器功能在较早的版本(如3.x系列)和较新的版本中(如4.x系列)都有支持。

2.更新 OpenCV:如果你的 OpenCV 版本较旧,可以通过 pip 命令来升级:


 pip install opencv-python --upgrade



3.文档参考:建议查阅官方的 OpenCV 文档,以获取针对你所使用的确切版本的最新信息和方法使用说明。


通过以上步骤,你应该能够正确地在 OpenCV 4.10.0 中创建 LBPH 人脸识别器。


相关文章
|
TensorFlow 算法框架/工具 Python
成功解决AttributeError: module 'numpy' has no attribute 'equal'
成功解决AttributeError: module 'numpy' has no attribute 'equal'
成功解决AttributeError: module 'numpy' has no attribute 'equal'
成功解决AttributeError: module 'numpy' has no attribute 'integer'
成功解决AttributeError: module 'numpy' has no attribute 'integer'
成功解决AttributeError: module 'numpy' has no attribute 'integer'
|
3月前
|
Python
AttributeError: module ‘scipy.misc‘ has no attribute ‘imread‘,imresize,imsave等问题
AttributeError: module ‘scipy.misc‘ has no attribute ‘imread‘,imresize,imsave等问题
48 1
|
3月前
|
Python
AttributeError: module ‘numpy‘ has no attribute ‘int‘.
AttributeError: module ‘numpy‘ has no attribute ‘int‘.
43 0
|
计算机视觉
图像拼接遇到module ‘cv2.cv2‘ has no attribute ‘xfeatures2d‘
图像拼接遇到module ‘cv2.cv2‘ has no attribute ‘xfeatures2d‘
108 0
|
算法 计算机视觉 Python
【完美解决方案】module ‘cv2.cv2‘ has no attribute ‘xfeatures2d‘
【完美解决方案】module ‘cv2.cv2‘ has no attribute ‘xfeatures2d‘
718 0
AttributeError: module ‘torch.utils‘ has no attribute ‘data‘
属性错误:模块的'torch.utils'没有属性'data'
81 0
|
Python
numpy 报错:”AttributeError: module ‘numpy‘ has no attribute ‘bool‘“
numpy 报错:”AttributeError: module ‘numpy‘ has no attribute ‘bool‘“
2221 0
|
TensorFlow API 算法框架/工具
解决AttributeError: module ‘tensorflow‘ has no attribute ‘div‘
解决AttributeError: module ‘tensorflow‘ has no attribute ‘div‘
154 0
解决AttributeError: module ‘tensorflow‘ has no attribute ‘div‘
|
计算机视觉
AttributeError: module 'cv2' has no attribute 'xfeatures2d'问题解决
AttributeError: module 'cv2' has no attribute 'xfeatures2d'问题解决
3223 0