Pycharm - Open webcam using Opencv library - Python

Published: 04 January 2021
on channel: Helpful Sources
2,339
25

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()


On this page of the site you can watch the video online Pycharm - Open webcam using Opencv library - Python with a duration of hours minute second in good quality, which was uploaded by the user Helpful Sources 04 January 2021, share the link with friends and acquaintances, this video has already been watched 2,339 times on youtube and it was liked by 25 viewers. Enjoy your viewing!