Opencv view camera module

I am unable to run opencv’s imshow to run a camera loop on it to analyze information from the camera.

Repl link

import cv2

# Create a VideoCapture object to access the default camera
cap = cv2.VideoCapture(0)
while True:
    # Read the frames from the camera
    ret, frame = cap.read()
    # Display the frames
    cv2.imshow("Camera", frame)
    # Break the loop when 'q' is pressed
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break
# Release the VideoCapture object and close the OpenCV windows
cap.release()
cv2.destroyAllWindows()

Did you get an error on the import cv2 line related to a missing file? I couldn’t get any of the last 5 versions of opencv-python to work so I moved to pillow for converting images to numpy arrays.

Hi @trentsmith1 , welcome to the forums!
Installing OpenCV has some problems, and is difficult to install.
Kindly take a look at this topic:

Hope this helps!

Hi, your repl runs on a virtual machine in Google cloud, not your machine. Therefore it cannot access your camera.

4 Likes