简体   繁体   中英

How can I use cv2.face and cv2 with creating a window by using QT, without getting errors?

I want to use openCV, but with different openCV versions I get different errors.

For eg when I use pip install opencv-python-headless code something like:

import cv2

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

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

works fine. But when I want to use the face attribute, it crashes with the error

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'

To fix the issue, I need to install openCV by using sudo python3 -m pip install opencv-contrib-python . But if I now execute the script above, the error

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.

appears.

So how can I avoid both errors?

EDIT: With the normal installation pip install opencv-python both errors appear. So it can not find the face attribute and is not able to create a window by using QT

原来最新的opencv-python版本坏了,所以我只需要pip install opencv-contrib-python==4.1.0.25

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM