I keep running into this error and can't fix it. I spoke with many people and they are not sure what to do. My code is below. This is very simple code that should open my webcam and display the live video. I am using python 3.8.0 on a M1 Mac 64 bit Ventura 13.2 using VsCode with the latest version of openCv, Mediapipe, and numpy. I have tried different IDE's and no luck.
import cv2
import mediapipe as mp
import numpy as np
mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose
#VIDEO FEED
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
cv2.imshow('Mediapipe Feed', frame)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
I got this code to work the first time I ran it. I ran it a few times, then connected my laptop via HDMI to a TV that has a camera built into it and then disconnected my laptop from the TV and now my code doesn't work. I think it has something to do with not being able to find the camera on my laptop but I can't figure it out. Any help would be great! I have tried changing the argument inside the .VideoCapture() from -10 to 10 and still no luck.