3
votes
import numpy
import cv2

cap = cv2.VideoCapture(0)

while(True):
    ret, frame = cap.read()

    cv2.imshow('frame',frame)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break


    cap.release()
    cv2.destroyAllWindows()

This my code andi get this error 1.Module 'cv2' has no 'VideoCapture' member 2.Module 'cv2' has no 'imshow' member 3.Module 'cv2' has no 'waitKey' member 4.Module 'cv2' has no 'destroyAllWindows' member

enter image description here

3

3 Answers

18
votes

If you use VSCode, you can try using this code:

from cv2 import cv2
3
votes

I had the same error in my code, I followed the steps below and it worked.

  1. Install OpenCV using pip install opencv-python
  2. While importing, do it like this: from cv2 import cv2
0
votes

Import statements shouldn’t be in the same line.

import numpy
import cv2

Also make sure that you have installed opencv using

pip install opencv-python