-2

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

For e.g 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

Jozott
  • 2,367
  • 2
  • 14
  • 28
  • the question is duplicated, the link: https://stackoverflow.com/questions/51853018/how-do-i-install-opencv-using-pip can give you an answer. – MIAWANG Feb 15 '20 at 21:33
  • No cause when I use the normal way to install it, I get in both cases the error. – Jozott Feb 15 '20 at 21:40
  • Why is it a bad question? Both problems are rarely answered on stackoverflow and github with a bad solution. And this particular problem was not asked on any platform. – Jozott Feb 15 '20 at 21:53

1 Answers1

0

It turns out that the latest opencv-python version is broken, so I just need to pip install opencv-contrib-python==4.1.0.25

Jozott
  • 2,367
  • 2
  • 14
  • 28