0
votes

I am using python and open-CV to do a face matching but there i am getting the following errors?

Module 'cv2' has no 'CascadeClassifier' member Module 'cv2' has no 'VideoCapture' member Module 'cv2' has no 'cvtColor' member Module 'cv2' has no 'COLOR_BGR2GRAY' member Module 'cv2' has no 'imshow' member Module 'cv2' has no 'waitKey' member Module 'cv2' has no 'destroyAllWindows' member

Here is my sample.py

import numpy as np
import cv2

face_cascade = cv2.CascadeClassifier('cascades/data/haarcascade_frontalface_alt2.xml')

cap = cv2.VideoCapture(0)

while(True):
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
    for(x,y,w,h) in faces:
        print(x,y,w,h)
    cv2.imshow('frame',frame)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break


cap.release()
cv2.destroyAllWindows()

How to fixed those errors?

3
How did you install opencv? - FMarazzi
using pip install opencv-contrib-python --upgrade command - user10368830

3 Answers

2
votes

If you using VSCode, you can change the your code from:

import cv2

to:

from cv2 import cv2
0
votes

It should be pip install opencv-python, which is the main opencv. opencv-contrib-python contains contributions of users.

0
votes

If you are using Visual Studio Code then you can follow these steps:

  1. On VS Code: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file: "python.linting.pylintArgs": ["--generate-members"]

Steps taken from this link

Hope this helps.