我如何使用cv2.face和cv2并通过使用QT创建窗口,而不会出现错误?

问题描述 投票:-2回答:1

我想使用openCV,但是使用不同的openCV版本时,会出现不同的错误。

例如,当我使用pip install opencv-python-headless代码时:

import cv2

img = cv2.imread('lena.jpg', -1)

cv2.imshow('image', img)
cv2.waitKey(5000)
cv2.destroyAllWindows()

工作正常。但是当我想使用face属性时,它崩溃并显示错误

Traceback (most recent call last):
  File "main.py", line 9, in <module>
    print(cv2.face.LBPHFaceRecognizer_create())
AttributeError: module 'cv2.cv2' has no attribute 'face'

要解决此问题,我需要使用sudo python3 -m pip install opencv-contrib-python安装openCV。但是,如果我现在执行上面的脚本,则错误

qt.qpa.plugin: Could not find the Qt platform plugin "cocoa" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

出现。

那么如何避免两个错误?

编辑:在常规安装pip install opencv-python中,两个错误都会出现。因此,它找不到face属性,并且无法通过使用QT

创建窗口
python python-3.x opencv pip cv2
1个回答
0
投票

事实证明最新的opencv-python版本已损坏,所以我只需要pip install opencv-contrib-python==4.1.0.25

© www.soinside.com 2019 - 2024. All rights reserved.