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()
In questa pagina del sito puoi guardare il video online Pycharm - Open webcam using Opencv library - Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Helpful Sources 04 gennaio 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 2,339 volte e gli è piaciuto 25 spettatori. Buona visione!