Way 1:
import cv2
cam = cv2.VideoCapture(0)
while True:
b, img = cam.read()
if b:
cv2.imshow("Window", img)
cv2.waitKey(1)
else:
print("The camera is not working!") #if I use cam = cv2.VideoCapture(1) will show this message # because I doesn't have second camera, doesn t exist
break
cam.release()
cv2.destroyAllWindows()
Way 2: Close window pressing q taste
import cv2
cam = cv2.VideoCapture(0) # if you have 1 camera, use 0 but if you have more then use 1 for second # camera, 2 for third etc.
while True:
b, img = cam.read()
cv2.imshow("Window", img) # name for window
if cv2.waitKey(1) == ord('q'): # if press q, will close window camera
break
cam.release()
cv2.destroyAllWindows()
En esta página del sitio puede ver el video en línea Pycharm - Open webcam using Opencv library - Python de Duración hora minuto segunda en buena calidad , que subió el usuario Helpful Sources 04 enero 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 2,295 veces y le gustó 25 a los espectadores. Disfruta viendo!