在我的命令提示符中安装以下这些命令后,我也面临同样的问题。
> pip install opencv-contrib-python
> pip install opencv-contrib-python --user
在jupyter notebook中遇到以下错误。
培训完成--------------
-------------------------------------------------- ------------------------- AttributeError Traceback(最近一次调用最后一次)~\AppData\Local\Temp/ipykernel_4424/3540845204.py in 40 个标签 = np.array(labels) 41 ---> 42 face_recognizer = cv.face.LBPHFaceRecognizer_create() 43 44 # 在特征列表和标签列表上训练识别器
AttributeError:模块'cv2'没有属性'face'
在我尝试使用Visual Studio 代码后,但请确保您在命令提示符或终端中使用以下确认命令运行。
我会建议你在命令提示符下尝试。
Microsoft Windows [Version 10.0.19043.1348]
(c) Microsoft Corporation. All rights reserved.
C:\Users\Admin>python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
4.5.5
>>> **recognizer = cv2.face.LBPHFaceRecognizer_create()**
>>> **print(recognizer)**
**<face_LBPHFaceRecognizer 000001F890F3D8D0>**
>>>
成功解决此问题后,我得到了以下输出。
on.exe' 'c:\Users\Admin\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy\launcher'
'55275' '--' 'c:\Users\Admin\Downloads\Opencv\Faces\face.py'
> Training done ---------------
PS C:\Users\Admin\Downloads\Opencv\Faces> c:; cd 'c:\Users\Admin\Downloads\Opencv\Faces'; & 'C:\Program
Files\Python310\pyth0' '--'
'c:\Users\Admin\Downloads\Opencv\Faces\face_recognization1.py'
> Label = Elton John with a confidence of 0.0
> Label = Elton John with a confidence of 0.0
on.exe'
'c:\Users\Admin\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy\launcher'
'55339' '--'
'c:\Users\Admin\Downloads\Opencv\Faces\face_recognization1.py'
> Label = nidhi agarwal with a confidence of 0.0