Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

module 'cv2' has no attribute 'read'

import cv2 as cv

frameWidth = 640
frameHeight = 800

capture = cv.VideoCapture(0)
capture.set(3, frameWidth)
capture.set(4, frameHeight)
capture.set(10, 140)

while True:
    passed, frame = cv.read()
    cv.imshow('Camera Capture', frame)
    if cv.waitKey(1) & 0xFF == ord('q'):
        break

capture.release()
capture.destroyAllWindows()

I’ve been trying to capture my camera using OpenCV. However it gives the error "module ‘cv2’ has no attribute ‘read’" I looked at various codes and sources including OpenCV’s own documentation. They all use the same code without errors. I tried uninstalling and installing opencv and opencv-contrib.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In your section of code:

while True:
    passed, frame = cv.read()
    cv.imshow('Camera Capture', frame)
    if cv.waitKey(1) & 0xFF == ord('q'):
        break

The issue is that you are trying to call read() on the module, rather you want to call read on the cv.VideoCapture object you created called capture so it should be as such.

while True:
    passed, frame = capture.read()
    cv.imshow('Camera Capture', frame)
    if cv.waitKey(1) & 0xFF == ord('q'):
        break
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading